跳转到内容

AG-UI 协议

AG-UI 适配层会把 Awaken 的 AgentEvent 流转换成 AG-UI / CopilotKit 事件格式,使 CopilotKit 前端可以直接驱动 Awaken agent。

POST /v1/ag-ui/run
{
"threadId": "optional-thread-id",
"agentId": "optional-agent-id",
"messages": [{ "role": "user", "content": "Hello" }],
"context": {}
}
字段类型必填说明
messagesAgUiMessage[]聊天消息,使用 rolecontent
threadIdstring继续已有 thread
agentIdstring指定目标 agent
contextobject前端上下文透传

SSE 流(text/event-stream),每个 frame 是一个 JSON 编码的 AG-UI Event

路由方法说明
/v1/ag-ui/runPOST启动 run 并流式返回 AG-UI events
/v1/ag-ui/threads/:thread_id/runsPOST在指定 thread 上启动 run
/v1/ag-ui/agents/:agent_id/runsPOST在指定 agent 上启动 run
/v1/ag-ui/threads/:thread_id/interruptPOST中断指定 thread
/v1/ag-ui/threads/:thread_id/replayGET回放指定 thread 的持久协议 frame
/v1/ag-ui/threads/:id/messagesGET读取 thread 消息历史

Replay 要求配置 ProtocolReplayLog。请求可带 ?cursor=Last-Event-ID,以及 ?limit=(默认 100,最大 500);响应是 SSE, 并使用 protocol replay cursor 作为 SSE id。未配置 replay 存储返回 503, 非法 cursor 返回 400,过期 cursor 返回 410 Gone

AgentEventAG-UI Event
RunStartRUN_STARTED
TextDeltaTEXT_MESSAGE_START + TEXT_MESSAGE_CONTENT
ReasoningDeltaREASONING_MESSAGE_START + REASONING_MESSAGE_CONTENT
ToolCallStart关闭当前 text/reasoning,然后发 STEP_STARTEDTOOL_CALL_START
ToolCallDeltaTOOL_CALL_ARGS
ToolCallDoneTOOL_CALL_ENDSTEP_FINISHED
StateSnapshotSTATE_SNAPSHOT
StateDeltaSTATE_DELTA
RunFinishRUN_FINISHEDRUN_ERROR
  • RUN_STARTED / RUN_FINISHED / RUN_ERROR
  • TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END
  • REASONING_MESSAGE_START / REASONING_MESSAGE_CONTENT / REASONING_MESSAGE_END
  • STEP_STARTED / STEP_FINISHED
  • TOOL_CALL_START / TOOL_CALL_ARGS / TOOL_CALL_END
  • STATE_SNAPSHOT / STATE_DELTA
  • MESSAGES_SNAPSHOT

AG-UI 消息角色使用小写字符串:systemuserassistanttool

  1. 第一个 TextDelta 会发 TEXT_MESSAGE_STARTTEXT_MESSAGE_CONTENT
  2. 后续 delta 只追加 TEXT_MESSAGE_CONTENT
  3. 遇到 ToolCallStartRunFinish 时,当前消息会以 TEXT_MESSAGE_END 关闭。

reasoning 消息采用同样模式。