我学习到的AG-UI的功能:全面的交互支持

15 阅读1分钟

AG-UI提供了智能体和应用交互所需的几乎所有功能:

1. 流式聊天

{
  type: "message",
  role: "assistant",
  content: "正在为您查找...",
  streaming: true
}

2. 状态同步

{
  type: "state_sync",
  state: {
    searchQuery: "中餐厅",
    results: [...]
  }
}

3. 生成式UI

{
  type: "generative_ui",
  component: "RestaurantCard",
  props: {...}
}

4. 工具调用

{
  type: "tool_call",
  tool: "search_restaurants",
  arguments: {...}
}

5. 前端工具

{
  type: "frontend_action",
  action: "open_map",
  params: {...}
}

6. 人机协作(HITL)

{
  type: "interrupt",
  reason: "需要用户确认",
  options: [...]
}

7. 思考步骤

{
  type: "thinking",
  content: "正在分析用户需求..."
}

8. 多模态支持

{
  type: "message",
  content: "这是餐厅照片",
  attachments: [{
    type: "image",
    url: "..."
  }]
}

9. 集成方式

# 使用LangGraph中间件
from copilotkit import CopilotKitSDK
 
sdk = CopilotKitSDK(
    agents=[my_langgraph_agent]
)

AG-UI可以传输A2UI消息

// AG-UI事件中包含A2UI消息
{
  type: "generative_ui",
  format: "a2ui",
  content: {
    surfaceUpdate: {
      components: [...]
    }
  }
}