01
A2UIMiddleware 的适配代码。其作用是:从 Agent 的工具输出中识别 A2UI 内容,并将其封装成 AG-UI 事件,和文字、状态消息一起传给前端。{
"type": "ACTIVITY_SNAPSHOT",
"messageId": "a2ui-refund",
"activityType": "a2ui-surface",
"content": {
"a2ui_operations": [
{
"version": "v0.9",
"createSurface": {
"surfaceId": "refund",
"catalogId": "https://refund-demo.local/catalog/v1"
}
},
{
"version": "v0.9",
"updateComponents": {
"surfaceId": "refund",
"components": [
{
"id": "root",
"component": "Column",
"children": ["product", "confirm"]
},
...
]
}
}
]
},
"replace": true
}activityType: "a2ui-surface" 标识出这是一个 A2UI 的描述。02
通过 MCP Resource 提供 A2UI 描述的 UI 模板 通过 MCP Tool 提供数据及更新
"_meta": {
"ui": {
"resourceUri": "a2ui://recipe-card",
"mimeType": "application/a2ui+json"
}
}application/a2ui+json 内嵌资源中返回完整 UI 描述,前端据此绘制退款卡片并展示:03
AG-UI 持续传递 Agent 的回复和处理进度; A2UI 描述外层订单卡片、金额和确认按钮; MCP Apps 承载卡片里的物流取件面板;
用户选好取件时段并点击保存,App 通过宿主调用 MCP 工具 MCP Server 校验并保存安排,结果经宿主返回,取件面板更新 宿主确认 MCP 面板保存成功后,再向 Agent 发送新的请求 Agent 读取最新安排,通过 AG-UI 返回回复、进度,以及封装在事件里的 A2UI 更新,前端根据新的 A2UI 消息刷新外层 A2UI 卡片 用户点击“确认退款”,再次发送 Agent 请求,继续后续的任务,更新 UI