Agent UI面临怎样的挑战 A2UI 协议:Agent UI的“描述语言” 实例解析:A2UI如何工作? A2UI 与 AG-UI、Copilot 的联系 总结:Agent协议组合栈及未来演进
01
动态性:UI元素需要随着上下文即时生成或调整,某种程度上应该由 AI 来“决定该出现什么”。 安全性:但你又不能直接执行 AI 输出的前端代码,否则极易引入 XSS、代码注入等风险。AI应该“描述UI”,而不是“构建UI”。 跨平台:同一个 Agent,可能服务于Web/App/桌面等多种前端,各UI 技术栈并不相同。能否做到“一次UI生成,多端呈现”? 流式交互:正如文本的流式输出,能否让用户也能实时看到 UI 的生成和变化,而不是长时间等待一次性“憋”出完整的UI? 状态同步:UI的表单数据、进度状态、临时输入,往往需要与后端 Agent 状态保持同步。能否根据状态变化局部更新UI?
02
安全的声明式设计
LLM 友好 + ”流式“UI生成
跨框架、跨平台的可移植性
状态与数据绑定
03
后端的 Agent 利用LLM动态生成结构化的 A2UI JSON 消息(包含界面结构和数据)。 消息通过 A2A 流式协议(SSE) 实时传输到 Web 前端。 前端接收并解析这些流数据,安全地渲染出用户界面(如预订表单)。 当用户在界面上进行操作(如点击“确认预订”)时,前端会将交互转化为标准化的 用户操作事件(UserAction Event),回传给 Agent。
标题文字「预订餐厅桌位」 日期与时间选择控件 一个「确认预订」按钮
{
"surfaceUpdate": {
"surfaceId": "main", # 指定界面区域(surface),支持一个对话有多个界面区域
"components": [
{
"id": "root",
"component": {
"Column": {
"children": {
"explicitList": [
"header",
"date_input",
"confirm_btn"
]
},
"distribution": "start",
"alignment": "stretch"
}
}
},
{ "id": "header", "component": { "Text": { "text": { "literalString": "预订餐厅桌位" }, "usageHint": "h1" } } },
{ "id": "date_input", "component": { "DateTimeInput": { "label": { "literalString": "选择日期和时间" }, "value": { "path": "/reservation/datetime" }, "enableDate": true, "enableTime": true } } },
{ "id": "confirm_btn", "component": { "Button": { "child": "confirm_text", "action": { "name": "confirm_reservation" }, "primary": true } } },
{ "id": "confirm_text", "component": { "Text": { "text": { "literalString": "确认预订" } } } }
]
}
}组件 ID:每个组件都有一个唯一的 id(如 header、date_input)。后续如果 Agent 需要更新某个组件,或引用其内容,会依赖这个 ID。 组件类型:在 component 字段中,通过对象键指定组件类型,例如 Text、DateTimeInput、Button。有前端经验的读者对此应该并不陌生。 数据绑定:在 DateTimeInput 中,value: {"path": "/reservation/datetime"} 表示该控件绑定到数据模型中的某个字段。
{
"dataModelUpdate": {
"surfaceId": "main",
"contents": [
{"key": "reservation", "valueMap": [
{"key": "datetime", "valueString": "2025-12-18T19:00"}
]}
]
}
}{
"beginRendering": {
"surfaceId": "main",
"root": "root",
"catalogId": "https://my-company.com/a2ui/v0.8/my_custom_catalog.json"
}
}{"surfaceUpdate": {"surfaceId": "main", "components": [...]}} // Header{"surfaceUpdate": {"surfaceId": "main", "components": [...]}} // Body{"beginRendering": {"surfaceId": "main", "root": "root-id"}} // Initial render{"surfaceUpdate": {"surfaceId": "main", "components": [...]}} // Footer (after initial render){"dataModelUpdate": {"surfaceId": "main", "contents": {...}}} // Populate data{
"userAction": {
"name": "confirm",
"surfaceId": "main",
"context": {
"details": {
"datetime": "2025-12-16T19:00:00Z",
}
}
}
}04
它规定前后端如何发送和接收事件 如何保持上下文感知与同步 如何支持流式更新与实时协同
A2UI 定义的是 UI 的结构、组件和数据绑定 AG-UI 定义的是这些描述如何以事件流的方式,在 Agent 与前端之间安全、实时地传输。
一是 Agent 的业务逻辑 二是前端组件和用户体验
05
