Skip to content

核心类型

本文档定义所有 JSON 对象的结构。字段标注 ? 表示可选(可能为 null 或不出现)。


Session(会话)

json
{
  "id": "sess_xxx",
  "intent": "用户任务描述",
  "status": "created | running | completed | failed | interrupted | waiting_for_input",
  "created_at": "2026-01-01T00:00:00Z",
  "updated_at": "2026-01-01T00:00:00Z",
  "user_id": "user_xxx",
  "solution_id": "string?",
  "biz_role_id": "string?",
  "model": "string?",
  "shared": false,
  "is_pinned": false,
  "memory_enabled": true,
  "is_persistent": false,
  "replay_state": null
}
字段类型说明
idstring会话唯一 ID
intentstring会话意图/标题
statusstring状态枚举,见下方
solution_idstring?关联的 Solution
biz_role_idstring?业务角色
modelstring?使用的 LLM 模型
sharedbool是否已分享
is_pinnedbool是否置顶
memory_enabledbool是否启用记忆
is_persistentbool是否持久会话
replay_stateobject?回放状态

Session Status 枚举:

说明
created已创建,未开始
running运行中
completed已完成
failed失败
interrupted被中断
waiting_for_input等待用户输入(AskUserQuestion)

TurnProjection(Turn 投影)

一轮对话的完整快照,是聊天历史的基本单位。

json
{
  "id": "entry_xxx",
  "sequence": 0,
  "turn_id": "turn_xxx",
  "loop_id": "root",
  "kind": "message",
  "role": "assistant",
  "status": "completed",
  "blocks": [],
  "tool_calls": [],
  "model": "claude-sonnet-4-20250514",
  "usage": { "input_tokens": 500, "output_tokens": 200 },
  "duration_ms": 3500,
  "started_at": "2026-01-01T00:00:00Z",
  "context_window": 200000,
  "memory_refs": null,
  "parent_fork_tool_call_id": null
}
字段类型说明
idstring条目 ID
sequenceint序号(从 0 递增)
turn_idstringTurn 唯一 ID
loop_idstring循环 ID(根循环为 "root"
kindstring"message""compaction"(压缩摘要)
rolestring"user" / "assistant" / "system"
statusstring"streaming" / "completed" / "paused" / "failed" / "interrupted"
blocksContentBlock[]内容块列表
tool_callsToolCallProjection[]工具调用列表
modelstring?使用的模型
usageobject?Token 用量 {input_tokens, output_tokens}
duration_msint耗时(毫秒)
started_atstring?开始时间
context_windowint上下文窗口大小
memory_refsMemoryRef[]?命中的记忆引用
parent_fork_tool_call_idstring?父级 Fork 工具调用 ID(子智能体场景)

Compaction 相关字段kind = "compaction" 时出现):

字段类型说明
compaction_idstring?压缩 ID
summary_previewstring?摘要预览
summary_fullstring?完整摘要
archived_countint?被归档的 Turn 数
tokens_beforeint?压缩前 token 数
tokens_afterint?压缩后 token 数
saved_ratiofloat?节省比例 0~1
triggerstring?触发方式:"auto" / "manual" / "forced_retry"

ContentBlock(内容块)

Turn 内的一个内容元素。

json
{
  "type": "text",
  "content": "这是回复文本",
  "tool_call_id": null,
  "tool_name": null,
  "display_name": null
}
字段类型说明
typestring内容类型(见枚举)
contentany内容值,类型随 type 变化
tool_call_idstring?关联的工具调用 ID
tool_namestring?工具名称
display_namestring?工具的友好显示名

type 枚举:

content 类型说明
textstring文本内容
thinkingstringAI 思考过程
tool_useobject工具调用声明
tool_resultany工具执行结果
tool_uiobject工具返回的 UI 卡片
tool_bridgeobject工具桥接动作(传递给宿主页面)
system_notificationstring系统通知
mode_changeobject模式切换
planning_enter-进入规划模式
planning_exit-退出规划模式
plan_statusobject计划状态更新
ask_user_answerobject用户回答

ToolCallProjection(工具调用)

json
{
  "id": "tc_xxx",
  "tool_name": "Bash",
  "display_name": "执行命令",
  "arguments": "{\"command\": \"ls -la\"}",
  "status": "done",
  "result": "total 48\ndrwxr-xr-x ...",
  "duration_ms": 150,
  "pending_question_ref": null
}
字段类型说明
idstring工具调用唯一 ID
tool_namestring工具名称
display_namestring显示名称(优先展示)
argumentsstringJSON 字符串,需自行解析
statusstring状态枚举
resultany?执行结果
duration_msint?耗时(毫秒)
pending_question_refobject?等待用户回答的引用信息

status 枚举:

说明
pending执行中
done已完成
error出错
cancelled已取消
awaiting_answer等待用户回答

pending_question_ref 结构:

json
{
  "child_loop_name": "string",
  "child_tool_call_id": "string",
  "description": "string?"
}

MemoryRef(记忆引用)

json
{
  "id": 1,
  "content_preview": "记忆内容预览...",
  "skill_name": "string?"
}

PatchEnvelope(增量更新信封)

WebSocket turn:patch 事件的载荷格式。

json
{
  "session_id": "sess_xxx",
  "sequence": 1,
  "turn_id": "turn_xxx",
  "loop_id": "root",
  "patch_type": "add_content",
  "data": {}
}
字段类型说明
session_idstring会话 ID
sequenceint序号
turn_idstringTurn ID
loop_idstring循环 ID
patch_typestring补丁类型(见下表)
dataobject补丁数据,结构随 patch_type 变化

patch_type 枚举与 data 结构:

add_content

新增内容块。

json
{
  "type": "text",
  "content": "新文本",
  "text_delta": "增量文本"
}

流式文本场景下 text_delta 为增量字符串,可拼接。content 为该块的当前完整内容。

add_tool_call

新增工具调用。

json
{
  "id": "tc_xxx",
  "tool_name": "Bash",
  "display_name": "执行命令",
  "arguments": "{\"command\": \"ls\"}",
  "status": "pending"
}

tool_result

工具执行完毕。

json
{
  "tool_call_id": "tc_xxx",
  "result": "执行结果...",
  "status": "done",
  "duration_ms": 150
}

set_status

Turn 状态变更。

json
{
  "status": "completed"
}

set_tool_status

工具调用状态变更。

json
{
  "tool_call_id": "tc_xxx",
  "status": "done"
}

Memory(记忆)

json
{
  "id": 1,
  "type": "feedback",
  "content": "记忆内容",
  "skill_name": null,
  "record_type": null,
  "scope": null,
  "owner": null,
  "topic": null,
  "mem0_id": null,
  "superseded_by": null,
  "write_reason": null,
  "created_at": "2026-01-01T00:00:00Z",
  "updated_at": null,
  "hit_count": 0,
  "last_hit_at": null,
  "disabled": false,
  "source_session": "sess_xxx"
}
字段类型说明
idint记忆 ID
typestring"feedback""experience"
contentstring记忆内容(1-500 字符)
skill_namestring?关联技能
record_typestring?"memory""skill_comment"
scopestring?范围
ownerstring?所有者
topicstring?主题
mem0_idstring?外部 ID
superseded_byint?被哪条记忆替代
write_reasonstring?写入原因
hit_countint命中次数
last_hit_atstring?最后命中时间
disabledbool是否禁用
source_sessionstring来源会话 ID

ApiKey

json
{
  "id": "key_xxx",
  "name": "My Key",
  "masked": "sk-blade-v2-...xxxx",
  "plaintext": null,
  "created_at": "2026-01-01T00:00:00Z",
  "last_used_at": "2026-01-02T00:00:00Z"
}

plaintext 仅在创建时返回一次,之后始终为 null


ScheduledTask(定时任务)

json
{
  "id": "task_xxx",
  "title": "每日报告",
  "prompt": "生成今日数据摘要",
  "cron": "0 9 * * *",
  "timezone": "Asia/Shanghai",
  "enabled": true,
  "expires_at": null,
  "skip_confirmations": false,
  "model": null
}

ScheduledTaskRun(运行记录)

json
{
  "id": "run_xxx",
  "task_id": "task_xxx",
  "session_id": "sess_xxx",
  "status": "completed | failed | running",
  "error": null,
  "triggered_at": "2026-01-01T09:00:00Z",
  "finished_at": "2026-01-01T09:05:00Z"
}

Tool _meta 扩展

工具执行结果中可携带 _meta 字段,用于向宿主页面传递动作或 UI 卡片。

Bridge(页面动作)

json
{
  "ok": true,
  "_meta": {
    "bridge": {
      "action": "map.highlight",
      "payload": { "cityIds": ["hangzhou", "ningbo"] }
    }
  }
}

宿主页面监听 bridge 事件后执行相应动作(如地图高亮)。

UI Card(内联/预览卡片)

json
{
  "_meta": {
    "ui": {
      "resourceHTML": "<!doctype html>...",
      "resourceUri": "https://...",
      "target": "inline | preview",
      "height": 320,
      "title": "卡片标题"
    }
  }
}
字段类型说明
resourceHTMLstring?完整 HTML,通过 iframe srcdoc 渲染
resourceUristring?外部 URL,通过 iframe src 渲染
targetstring"inline"(聊天区内联)或 "preview"(侧边预览)
heightint?iframe 高度(像素)
titlestring?卡片标题

resourceHTMLresourceUri 二选一。