文档管理中心

对话交互

单轮问答

用户提问,Agent一次返回完整答复,适用于简单播报场景。

用户请求:

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-002",
  4. "method":"MessageStream",
  5. "params":{
  6. "message":{
  7. "messageId":"msg-abc-002",
  8. "role":"ROLE_USER",
  9. "contextId":"ctx-session-xyz",
  10. "parts":[
  11. {
  12. "text":"请介绍一下量子计算的基本原理",
  13. "mediaType":"text/plain"
  14. }
  15. ]
  16. },
  17. "metadata":{
  18. "traceId":"trace-7f8a2b3c-0001",
  19. "agentId":"agent-example-001",
  20. "appVersion":"12.0.1"
  21. }
  22. }
  23. }

Agent一次性返回结果:

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "task":{
  6. "id":"task-7f8a2b3c-0001",
  7. "contextId":"ctx-session-xyz",
  8. "status":{
  9. "state":"TASK_STATE_COMPLETED",
  10. "timestamp":"2026-03-04T10:24:02.500Z"
  11. },
  12. "artifacts":[
  13. {
  14. "artifactId":"artifact-001",
  15. "parts":[
  16. {
  17. "text":"量子计算基本原理...",
  18. "mediaType":"text/plain"
  19. },
  20. {
  21. "data":{
  22. "ttsText":"国航一二三四于下午两点半从三号航站楼起飞,预计准点。"
  23. }
  24. }
  25. ]
  26. }
  27. ]
  28. },
  29. "metadata":{
  30. "traceId":"trace-7f8a2b3c-0001",
  31. "agentId":"agent-example-001",
  32. "agentVersion":"1.2.0"
  33. }
  34. }
  35. }
说明

data.ttsText为TTS播报内容。同一artifact内只要有任意part包含data.ttsText,则发声内容以ttsText为准。如果播报内容和text一致,可以不传。

流式分批回复(含思考过程、推荐)

Agent逐步输出回答,用户可实时看到思考过程和内容生成。

首帧(TASK_STATE_SUBMITTED):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-002",
  4. "result":{
  5. "task":{
  6. "id":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "status":{
  9. "state":"TASK_STATE_SUBMITTED",
  10. "timestamp":"2026-03-04T10:24:00.000Z"
  11. }
  12. },
  13. "metadata":{
  14. "traceId":"trace-7f8a2b3c-0001",
  15. "agentId":"agent-example-001",
  16. "agentVersion":"1.2.0"
  17. }
  18. }
  19. }

中间帧——过程信息(TASK_STATE_WORKING),message.parts[].text将对用户展示:

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "statusUpdate":{
  6. "taskId":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "status":{
  9. "state":"TASK_STATE_WORKING",
  10. "message":{
  11. "role":"ROLE_AGENT",
  12. "messageId":"msg-001",
  13. "parts":[
  14. {
  15. "text":"正在思考",
  16. "mediaType":"text/plain",
  17. }
  18. ]
  19. },
  20. "timestamp":"2026-03-24T10:00:01.000Z"
  21. }
  22. },
  23. "metadata":{
  24. "traceId":"trace-7f8a2b3c-0001",
  25. "agentId":"agent-example-001",
  26. "agentVersion":"1.2.0"
  27. }
  28. }
  29. }

中间帧——思考内容,thinking对用户展示思考过程:

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "artifactUpdate":{
  6. "taskId":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "artifact":{
  9. "artifactId":"art-thinking-001",
  10. "parts":[
  11. {
  12. "data":{
  13. "thinking":"用户问的是量子计算,需要先解释基本原理..."
  14. }
  15. }
  16. ]
  17. },
  18. "append":false,
  19. "lastChunk":false
  20. },
  21. "metadata":{
  22. "traceId":"trace-7f8a2b3c-0001",
  23. "agentId":"agent-example-001",
  24. "agentVersion":"1.2.0"
  25. }
  26. }
  27. }

thinking支持增量发送:append值为true表示本帧内容追加到同一artifactId的上一帧thinking中,未返回或者返回lastChunk=true视为append结束,例如开始返回正文。

中间帧——流式正文,支持增量叠加:

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "artifactUpdate":{
  6. "taskId":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "artifact":{
  9. "artifactId":"art-text-001",
  10. "parts":[
  11. {
  12. "text":"量子计算是一种利用量子力学原理",
  13. "mediaType":"text/plain"
  14. }
  15. ]
  16. },
  17. "append":true,
  18. "lastChunk":false
  19. },
  20. "metadata":{
  21. "traceId":"trace-7f8a2b3c-0001",
  22. "agentId":"agent-example-001",
  23. "agentVersion":"1.2.0"
  24. }
  25. }
  26. }

中间帧——流式正文最后一片(lastChunk=true标识正文结束):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "artifactUpdate":{
  6. "taskId":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "artifact":{
  9. "artifactId":"art-text-001",
  10. "parts":[
  11. {
  12. "text":"进行信息处理的新型计算模式。",
  13. "mediaType":"text/plain"
  14. }
  15. ]
  16. },
  17. "append":true,
  18. "lastChunk":true
  19. },
  20. "metadata":{
  21. "traceId":"trace-7f8a2b3c-0001",
  22. "agentId":"agent-example-001",
  23. "agentVersion":"1.2.0"
  24. }
  25. }
  26. }

末帧(TASK_STATE_COMPLETED):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "statusUpdate":{
  6. "taskId":"task-9e1b4d5f-0001",
  7. "contextId":"ctx-session-xyz",
  8. "status":{
  9. "state":"TASK_STATE_COMPLETED",
  10. "timestamp":"2026-03-24T10:00:05.000Z"
  11. }
  12. },
  13. "metadata":{
  14. "traceId":"trace-7f8a2b3c-0001",
  15. "agentId":"agent-example-001",
  16. "agentVersion":"1.2.0"
  17. }
  18. }
  19. }

Agent 对话澄清

信息不足时,Agent主动追问用户,补充后继续完成任务。

Agent发起澄清(Agent发送至小艺):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "statusUpdate":{
  6. "taskId":"task-001",
  7. "contextId":"ctx-001",
  8. "status":{
  9. "state":"TASK_STATE_INPUT_REQUIRED",
  10. "message":{
  11. "role":"ROLE_AGENT",
  12. "messageId":"msg-001",
  13. "parts":[
  14. {
  15. "text":"请问您要去哪个城市?",
  16. "mediaType":"text/plain"
  17. }
  18. ]
  19. },
  20. "timestamp":"2026-03-24T10:00:01.000Z"
  21. }
  22. },
  23. "metadata":{
  24. "traceId":"trace-7f8a2b3c-0001",
  25. "agentId":"agent-example-001",
  26. "agentVersion":"1.2.0"
  27. }
  28. }
  29. }

注意:state为TASK_STATE_INPUT_REQUIRED,表示需要用户输入。

小艺回复用户答案(小艺发送至Agent):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-002",
  4. "method":"MessageStream",
  5. "params":{
  6. "message":{
  7. "messageId":"msg-002",
  8. "taskId":"task-001",
  9. "contextId":"ctx-001",
  10. "role":"ROLE_USER",
  11. "parts":[
  12. {
  13. "text":"北京",
  14. "mediaType":"text/plain"
  15. }
  16. ]
  17. },
  18. "metadata":{
  19. "traceId":"trace-7f8a2b3c-0002",
  20. "agentId":"agent-example-001",
  21. "appVersion":"12.0.1"
  22. }
  23. }
  24. }
说明

这里小艺会携带相同的taskId。

文件传递

小艺与Agent之间互相传递在线图片或文件。

Agent返回文件(以PNG图片为例):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "artifactUpdate":{
  6. "taskId":"task-001",
  7. "contextId":"ctx-001",
  8. "artifact":{
  9. "artifactId":"art-file-001",
  10. "parts":[
  11. {
  12. "url":"https://example.com/image.png",
  13. "filename":"image.png",
  14. "mediaType":"image/png"
  15. }
  16. ]
  17. },
  18. "append":false,
  19. "lastChunk":true
  20. },
  21. "metadata":{
  22. "traceId":"trace-7f8a2b3c-0001",
  23. "agentId":"agent-example-001",
  24. "agentVersion":"1.2.0"
  25. }
  26. }
  27. }

其中mediaType支持范围见【Part结构定义】章节。

对话返回卡片

Agent触发端侧渲染卡片,向用户展示富媒体内容。

Agent返回卡片(Agent发送至小艺):

收起
自动换行
深色代码主题
复制
  1. {
  2. "jsonrpc":"2.0",
  3. "id":"req-001",
  4. "result":{
  5. "artifactUpdate":{
  6. "taskId":"task-001",
  7. "contextId":"ctx-001",
  8. "artifact":{
  9. "artifactId":"art-card-001",
  10. "parts":[
  11. {
  12. "data":{
  13. "uiExtensionCard":{
  14. "cardId":"卡片id",
  15. "bundleName":"com.example.agentapp",
  16. "moduleName":"entry",
  17. "abilityName":"AgentUIExtensionAbility",
  18. "payload":"卡片参数",
  19. "dimension":"2x4",
  20. "encrypted":false,
  21. "summary":"卡片摘要,用于上下文存储和风控"
  22. }
  23. }
  24. }
  25. ]
  26. },
  27. "append":false,
  28. "lastChunk":true
  29. },
  30. "metadata":{
  31. "traceId":"trace-7f8a2b3c-0001",
  32. "agentId":"agent-example-001",
  33. "agentVersion":"1.2.0"
  34. }
  35. }
  36. }
在 服务分发 中进行搜索
请输入您想要搜索的关键词