|
@@ -1,7 +1,7 @@
|
|
|
# Agent Execution API - 前端对接文档
|
|
# Agent Execution API - 前端对接文档
|
|
|
|
|
|
|
|
> 版本:v4.0
|
|
> 版本:v4.0
|
|
|
-> 更新日期:2026-02-04
|
|
|
|
|
|
|
+> 更新日期:2026-07-17
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -16,7 +16,7 @@
|
|
|
- **GoalTree** - 每个 Trace 的目标树
|
|
- **GoalTree** - 每个 Trace 的目标树
|
|
|
- **Goal** - 一个目标节点,包含 self_stats(自身统计)和 cumulative_stats(含后代统计)
|
|
- **Goal** - 一个目标节点,包含 self_stats(自身统计)和 cumulative_stats(含后代统计)
|
|
|
- **Message** - 执行消息,对应 LLM API 的 assistant/tool 消息
|
|
- **Message** - 执行消息,对应 LLM API 的 assistant/tool 消息
|
|
|
-- **Sub-Trace** - 子 Agent(通过 explore/delegate 工具启动)
|
|
|
|
|
|
|
+- **Sub-Trace** - 子 Agent(通过统一 `agent()` 工具启动;`explore/delegate` 是内部模式)
|
|
|
|
|
|
|
|
**统一的 Trace 模型**:
|
|
**统一的 Trace 模型**:
|
|
|
```
|
|
```
|
|
@@ -40,13 +40,15 @@
|
|
|
- Goal.stats 从关联的 Messages 聚合计算
|
|
- Goal.stats 从关联的 Messages 聚合计算
|
|
|
- Sub-Trace 通过 parent_trace_id 关联
|
|
- Sub-Trace 通过 parent_trace_id 关联
|
|
|
- Goal 通过 sub_trace_ids 关联启动的 Sub-Traces
|
|
- Goal 通过 sub_trace_ids 关联启动的 Sub-Traces
|
|
|
|
|
+- 前端从 `trace.context.agent_mode` 识别 `legacy` / `recursive`;缺失时按 Legacy 显示
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**DAG 可视化**(前端负责):
|
|
**DAG 可视化**(前端负责):
|
|
|
- 从 GoalTree 生成 DAG 视图
|
|
- 从 GoalTree 生成 DAG 视图
|
|
|
- 节点 = Goal 完成后的里程碑
|
|
- 节点 = Goal 完成后的里程碑
|
|
|
- 边 = 相邻节点之间的执行过程
|
|
- 边 = 相邻节点之间的执行过程
|
|
|
-- Sub-Trace 可以折叠(显示为单个节点)或展开(显示内部 Goals)
|
|
|
|
|
|
|
+- Recursive 的 Agent Goal 最多显示 6 个 `A1~A6` 入口,点击后切换到对应子 Trace,子 Trace 内可继续进入孙 Trace
|
|
|
|
|
+- Legacy 不显示 `A1~A6`;当前不在同一张图内展开完整五层树
|
|
|
- 边的统计数据从 target Goal 的 stats 获取
|
|
- 边的统计数据从 target Goal 的 stats 获取
|
|
|
|
|
|
|
|
---
|
|
---
|
|
@@ -60,6 +62,38 @@
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
|
|
|
+### 0. 新建 Trace 并执行
|
|
|
|
|
+
|
|
|
|
|
+```http
|
|
|
|
|
+POST /api/traces
|
|
|
|
|
+Content-Type: application/json
|
|
|
|
|
+
|
|
|
|
|
+{
|
|
|
|
|
+ "messages": [{"role": "user", "content": "完成任务"}],
|
|
|
|
|
+ "model": "qwen-plus",
|
|
|
|
|
+ "temperature": 0.3,
|
|
|
|
|
+ "max_iterations": 200,
|
|
|
|
|
+ "tools": null,
|
|
|
|
|
+ "name": "任务名称",
|
|
|
|
|
+ "uid": "user_id",
|
|
|
|
|
+ "project_name": null,
|
|
|
|
|
+ "root_completion_criteria": ["产出物通过验收"]
|
|
|
|
|
+}
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`root_completion_criteria` 在 Recursive 模式下必填且至少一项;Legacy 忽略该字段。该端点立即返回 `trace_id` 和 `status="started"`,执行过程通过 WebSocket 监听。
|
|
|
|
|
+
|
|
|
|
|
+### 0.1 续跑、回溯与停止
|
|
|
|
|
+
|
|
|
|
|
+```http
|
|
|
|
|
+POST /api/traces/{trace_id}/run
|
|
|
|
|
+POST /api/traces/{trace_id}/stop
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`run` 请求使用 `messages` 和可选 `after_message_id`。`stop` 是协作式停止:Legacy 只停请求的 Trace;Recursive 在当前 Python 进程内向活跃子孙传播,但不强制中断已发出的 LLM 请求。
|
|
|
|
|
+
|
|
|
|
|
+---
|
|
|
|
|
+
|
|
|
### 1. 列出 Traces
|
|
### 1. 列出 Traces
|
|
|
|
|
|
|
|
```http
|
|
```http
|
|
@@ -69,9 +103,9 @@ GET /api/traces?status=running&limit=20
|
|
|
**查询参数**:
|
|
**查询参数**:
|
|
|
| 参数 | 类型 | 必填 | 说明 |
|
|
| 参数 | 类型 | 必填 | 说明 |
|
|
|
|------|------|------|------|
|
|
|------|------|------|------|
|
|
|
-| `status` | string | 否 | 过滤状态:`running` / `completed` / `failed` |
|
|
|
|
|
|
|
+| `status` | string | 否 | 过滤状态:`running` / `completed` / `failed` / `stopped` |
|
|
|
| `mode` | string | 否 | 过滤模式:`call` / `agent` |
|
|
| `mode` | string | 否 | 过滤模式:`call` / `agent` |
|
|
|
-| `limit` | int | 否 | 返回数量(默认 50,最大 100)|
|
|
|
|
|
|
|
+| `limit` | int | 否 | 返回数量(默认 20,最大 100)|
|
|
|
|
|
|
|
|
**响应示例**:
|
|
**响应示例**:
|
|
|
```json
|
|
```json
|
|
@@ -88,8 +122,7 @@ GET /api/traces?status=running&limit=20
|
|
|
"current_goal_id": "2.1",
|
|
"current_goal_id": "2.1",
|
|
|
"created_at": "2026-02-04T15:30:00"
|
|
"created_at": "2026-02-04T15:30:00"
|
|
|
}
|
|
}
|
|
|
- ],
|
|
|
|
|
- "total": 1
|
|
|
|
|
|
|
+ ]
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -101,21 +134,36 @@ GET /api/traces?status=running&limit=20
|
|
|
GET /api/traces/{trace_id}
|
|
GET /api/traces/{trace_id}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+真实响应外层固定为:
|
|
|
|
|
+
|
|
|
|
|
+```json
|
|
|
|
|
+{
|
|
|
|
|
+ "trace": {"trace_id": "abc123", "context": {"agent_mode": "recursive"}},
|
|
|
|
|
+ "goal_tree": {"mission": "...", "current_id": "2", "goals": []},
|
|
|
|
|
+ "sub_traces": {}
|
|
|
|
|
+}
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`sub_traces` 是当前 Trace 的直接子 Trace,可同时包含业务子 Agent 和 `agent_type="validator"` 的验收 Trace。前端判断业务模式和树级血缘时使用 `trace.context.agent_mode`、`agent_mode_revision`、`root_trace_id` 和 `agent_depth`。
|
|
|
|
|
+
|
|
|
**响应示例 1**(主 Trace,explore 进行中):
|
|
**响应示例 1**(主 Trace,explore 进行中):
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
|
- "trace_id": "abc123",
|
|
|
|
|
- "mode": "agent",
|
|
|
|
|
- "task": "实现用户认证功能",
|
|
|
|
|
- "status": "running",
|
|
|
|
|
- "parent_trace_id": null,
|
|
|
|
|
- "parent_goal_id": null,
|
|
|
|
|
- "agent_type": "main",
|
|
|
|
|
- "total_messages": 15,
|
|
|
|
|
- "total_tokens": 5000,
|
|
|
|
|
- "total_cost": 0.05,
|
|
|
|
|
- "created_at": "2026-02-04T15:30:00",
|
|
|
|
|
- "completed_at": null,
|
|
|
|
|
|
|
+ "trace": {
|
|
|
|
|
+ "trace_id": "abc123",
|
|
|
|
|
+ "mode": "agent",
|
|
|
|
|
+ "task": "实现用户认证功能",
|
|
|
|
|
+ "status": "running",
|
|
|
|
|
+ "parent_trace_id": null,
|
|
|
|
|
+ "parent_goal_id": null,
|
|
|
|
|
+ "agent_type": "main",
|
|
|
|
|
+ "total_messages": 15,
|
|
|
|
|
+ "total_tokens": 5000,
|
|
|
|
|
+ "total_cost": 0.05,
|
|
|
|
|
+ "created_at": "2026-02-04T15:30:00",
|
|
|
|
|
+ "completed_at": null,
|
|
|
|
|
+ "context": {"agent_mode": "recursive", "agent_mode_revision": 2, "root_trace_id": "abc123", "agent_depth": 0}
|
|
|
|
|
+ },
|
|
|
"goal_tree": {
|
|
"goal_tree": {
|
|
|
"mission": "实现用户认证功能",
|
|
"mission": "实现用户认证功能",
|
|
|
"current_id": "2",
|
|
"current_id": "2",
|
|
@@ -137,7 +185,7 @@ GET /api/traces/{trace_id}
|
|
|
"type": "agent_call",
|
|
"type": "agent_call",
|
|
|
"description": "并行探索认证方案",
|
|
"description": "并行探索认证方案",
|
|
|
"reason": "评估不同技术选型",
|
|
"reason": "评估不同技术选型",
|
|
|
- "status": "in_progress",
|
|
|
|
|
|
|
+ "status": "waiting_children",
|
|
|
"agent_call_mode": "explore",
|
|
"agent_call_mode": "explore",
|
|
|
"sub_trace_ids": [
|
|
"sub_trace_ids": [
|
|
|
{"trace_id": "abc123.A", "mission": "JWT 方案"},
|
|
{"trace_id": "abc123.A", "mission": "JWT 方案"},
|
|
@@ -189,10 +237,13 @@ GET /api/traces/{trace_id}
|
|
|
**响应示例 2**(主 Trace,explore 已完成并合并):
|
|
**响应示例 2**(主 Trace,explore 已完成并合并):
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
|
- "trace_id": "abc123",
|
|
|
|
|
- "mode": "agent",
|
|
|
|
|
- "task": "实现用户认证功能",
|
|
|
|
|
- "status": "running",
|
|
|
|
|
|
|
+ "trace": {
|
|
|
|
|
+ "trace_id": "abc123",
|
|
|
|
|
+ "mode": "agent",
|
|
|
|
|
+ "task": "实现用户认证功能",
|
|
|
|
|
+ "status": "running",
|
|
|
|
|
+ "context": {"agent_mode": "legacy"}
|
|
|
|
|
+ },
|
|
|
"goal_tree": {
|
|
"goal_tree": {
|
|
|
"mission": "实现用户认证功能",
|
|
"mission": "实现用户认证功能",
|
|
|
"current_id": "3",
|
|
"current_id": "3",
|
|
@@ -289,17 +340,19 @@ GET /api/traces/abc123.A
|
|
|
**响应示例**:
|
|
**响应示例**:
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
|
- "trace_id": "abc123.A",
|
|
|
|
|
- "parent_trace_id": "abc123",
|
|
|
|
|
- "parent_goal_id": "2",
|
|
|
|
|
- "agent_type": "explore",
|
|
|
|
|
- "task": "JWT 方案",
|
|
|
|
|
- "status": "completed",
|
|
|
|
|
- "total_messages": 8,
|
|
|
|
|
- "total_tokens": 4000,
|
|
|
|
|
- "total_cost": 0.05,
|
|
|
|
|
- "created_at": "2026-02-04T15:31:00",
|
|
|
|
|
- "completed_at": "2026-02-04T15:35:00",
|
|
|
|
|
|
|
+ "trace": {
|
|
|
|
|
+ "trace_id": "abc123.A",
|
|
|
|
|
+ "parent_trace_id": "abc123",
|
|
|
|
|
+ "parent_goal_id": "2",
|
|
|
|
|
+ "agent_type": "explore",
|
|
|
|
|
+ "task": "JWT 方案",
|
|
|
|
|
+ "status": "completed",
|
|
|
|
|
+ "total_messages": 8,
|
|
|
|
|
+ "total_tokens": 4000,
|
|
|
|
|
+ "total_cost": 0.05,
|
|
|
|
|
+ "created_at": "2026-02-04T15:31:00",
|
|
|
|
|
+ "completed_at": "2026-02-04T15:35:00"
|
|
|
|
|
+ },
|
|
|
"goal_tree": {
|
|
"goal_tree": {
|
|
|
"mission": "JWT 方案",
|
|
"mission": "JWT 方案",
|
|
|
"current_id": null,
|
|
"current_id": null,
|
|
@@ -347,7 +400,6 @@ GET /api/traces/abc123.A/messages?goal_id=2
|
|
|
**响应示例**:
|
|
**响应示例**:
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
|
- "trace_id": "abc123",
|
|
|
|
|
"messages": [
|
|
"messages": [
|
|
|
{
|
|
{
|
|
|
"message_id": "msg-001",
|
|
"message_id": "msg-001",
|
|
@@ -383,8 +435,7 @@ GET /api/traces/abc123.A/messages?goal_id=2
|
|
|
"cost": null,
|
|
"cost": null,
|
|
|
"created_at": "2026-02-04T15:31:01"
|
|
"created_at": "2026-02-04T15:31:01"
|
|
|
}
|
|
}
|
|
|
- ],
|
|
|
|
|
- "total": 2
|
|
|
|
|
|
|
+ ]
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -418,16 +469,14 @@ const ws = new WebSocket(
|
|
|
"event": "connected",
|
|
"event": "connected",
|
|
|
"trace_id": "abc123",
|
|
"trace_id": "abc123",
|
|
|
"current_event_id": 15,
|
|
"current_event_id": 15,
|
|
|
- "trace": {
|
|
|
|
|
- "trace_id": "abc123",
|
|
|
|
|
- "status": "running",
|
|
|
|
|
- "goal_tree": {
|
|
|
|
|
- "mission": "实现用户认证功能",
|
|
|
|
|
- "current_id": "2",
|
|
|
|
|
- "goals": [...]
|
|
|
|
|
- },
|
|
|
|
|
- "sub_traces": {}
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ "trace_status": "running",
|
|
|
|
|
+ "is_running": true,
|
|
|
|
|
+ "goal_tree": {
|
|
|
|
|
+ "mission": "实现用户认证功能",
|
|
|
|
|
+ "current_id": "2",
|
|
|
|
|
+ "goals": [...]
|
|
|
|
|
+ },
|
|
|
|
|
+ "sub_traces": {}
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -457,15 +506,14 @@ if (data.event === 'connected') {
|
|
|
"summary": null,
|
|
"summary": null,
|
|
|
"self_stats": { "message_count": 0, "total_tokens": 0, "total_cost": 0.0, "preview": null },
|
|
"self_stats": { "message_count": 0, "total_tokens": 0, "total_cost": 0.0, "preview": null },
|
|
|
"cumulative_stats": { "message_count": 0, "total_tokens": 0, "total_cost": 0.0, "preview": null }
|
|
"cumulative_stats": { "message_count": 0, "total_tokens": 0, "total_cost": 0.0, "preview": null }
|
|
|
- },
|
|
|
|
|
- "parent_id": "2"
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**前端处理**:
|
|
**前端处理**:
|
|
|
```javascript
|
|
```javascript
|
|
|
if (data.event === 'goal_added') {
|
|
if (data.event === 'goal_added') {
|
|
|
- insertGoal(data.goal, data.parent_id)
|
|
|
|
|
|
|
+ insertGoal(data.goal, data.goal.parent_id)
|
|
|
regenerateDAG()
|
|
regenerateDAG()
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
@@ -474,7 +522,8 @@ if (data.event === 'goal_added') {
|
|
|
|
|
|
|
|
#### 3. goal_updated(Goal 状态变化)
|
|
#### 3. goal_updated(Goal 状态变化)
|
|
|
|
|
|
|
|
-包含级联完成场景:当所有子 Goal 完成时,父 Goal 自动 completed。
|
|
|
|
|
|
|
+Legacy 中可包含级联完成;Recursive 不自动完成父 Goal,子任务返回后会经过 `waiting_children` / `pending_review` 等待父 Agent 审核。
|
|
|
|
|
+实时广播的变更字段名为 `patch`,从 `events.jsonl` 补发的历史事件为 `updates`;前端同时兼容两者。
|
|
|
|
|
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
@@ -503,7 +552,7 @@ if (data.event === 'goal_added') {
|
|
|
**前端处理**:
|
|
**前端处理**:
|
|
|
```javascript
|
|
```javascript
|
|
|
if (data.event === 'goal_updated') {
|
|
if (data.event === 'goal_updated') {
|
|
|
- updateGoal(data.goal_id, data.updates)
|
|
|
|
|
|
|
+ updateGoal(data.goal_id, data.patch ?? data.updates)
|
|
|
for (const g of data.affected_goals) {
|
|
for (const g of data.affected_goals) {
|
|
|
updateGoalStats(g.goal_id, g)
|
|
updateGoalStats(g.goal_id, g)
|
|
|
}
|
|
}
|
|
@@ -567,9 +616,7 @@ if (data.event === 'message_added') {
|
|
|
"event": "trace_completed",
|
|
"event": "trace_completed",
|
|
|
"event_id": 50,
|
|
"event_id": 50,
|
|
|
"trace_id": "abc123",
|
|
"trace_id": "abc123",
|
|
|
- "total_messages": 50,
|
|
|
|
|
- "total_tokens": 25000,
|
|
|
|
|
- "total_cost": 0.25
|
|
|
|
|
|
|
+ "total_messages": 50
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -581,39 +628,34 @@ if (data.event === 'trace_completed') {
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+`trace_status_changed` 用于停止和续跑时的状态同步:
|
|
|
|
|
+
|
|
|
|
|
+```json
|
|
|
|
|
+{
|
|
|
|
|
+ "event": "trace_status_changed",
|
|
|
|
|
+ "trace_id": "abc123",
|
|
|
|
|
+ "status": "stopped"
|
|
|
|
|
+}
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
---
|
|
---
|
|
|
|
|
|
|
|
#### 6. sub_trace_started(Sub-Trace 开始)
|
|
#### 6. sub_trace_started(Sub-Trace 开始)
|
|
|
|
|
|
|
|
-explore 或 delegate 工具启动 Sub-Trace 时触发。
|
|
|
|
|
|
|
+`agent()` 工具启动 Sub-Trace 时触发;`explore` / `delegate` 只是内部运行模式。
|
|
|
|
|
|
|
|
```json
|
|
```json
|
|
|
{
|
|
{
|
|
|
"event": "sub_trace_started",
|
|
"event": "sub_trace_started",
|
|
|
"event_id": 20,
|
|
"event_id": 20,
|
|
|
- "parent_trace_id": "abc123",
|
|
|
|
|
|
|
+ "trace_id": "abc123@explore-20260204220012-001",
|
|
|
"parent_goal_id": "2",
|
|
"parent_goal_id": "2",
|
|
|
- "sub_trace": {
|
|
|
|
|
- "trace_id": "abc123.A",
|
|
|
|
|
- "parent_trace_id": "abc123",
|
|
|
|
|
- "parent_goal_id": "2",
|
|
|
|
|
- "agent_type": "explore",
|
|
|
|
|
- "task": "JWT 方案",
|
|
|
|
|
- "status": "running",
|
|
|
|
|
- "total_messages": 0,
|
|
|
|
|
- "total_tokens": 0,
|
|
|
|
|
- "total_cost": 0.0
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ "agent_type": "explore",
|
|
|
|
|
+ "task": "JWT 方案"
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**前端处理**:
|
|
|
|
|
-```javascript
|
|
|
|
|
-if (data.event === 'sub_trace_started') {
|
|
|
|
|
- insertSubTrace(data.parent_trace_id, data.sub_trace)
|
|
|
|
|
- regenerateDAG()
|
|
|
|
|
-}
|
|
|
|
|
-```
|
|
|
|
|
|
|
+Goal 上的 `sub_trace_ids` 以 `goal_updated` 事件为准;该事件可用于补充子 Trace 运行提示。
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -625,13 +667,14 @@ Sub-Trace 执行完成后触发。
|
|
|
{
|
|
{
|
|
|
"event": "sub_trace_completed",
|
|
"event": "sub_trace_completed",
|
|
|
"event_id": 35,
|
|
"event_id": 35,
|
|
|
- "trace_id": "abc123.A",
|
|
|
|
|
- "parent_trace_id": "abc123",
|
|
|
|
|
- "parent_goal_id": "2",
|
|
|
|
|
|
|
+ "trace_id": "abc123@explore-20260204220012-001",
|
|
|
|
|
+ "status": "completed",
|
|
|
"summary": "JWT 方案实现完成,无状态但 token 较大",
|
|
"summary": "JWT 方案实现完成,无状态但 token 较大",
|
|
|
- "total_messages": 8,
|
|
|
|
|
- "total_tokens": 4000,
|
|
|
|
|
- "total_cost": 0.05
|
|
|
|
|
|
|
+ "stats": {
|
|
|
|
|
+ "total_messages": 8,
|
|
|
|
|
+ "total_tokens": 4000,
|
|
|
|
|
+ "total_cost": 0.05
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -639,13 +682,10 @@ Sub-Trace 执行完成后触发。
|
|
|
```javascript
|
|
```javascript
|
|
|
if (data.event === 'sub_trace_completed') {
|
|
if (data.event === 'sub_trace_completed') {
|
|
|
updateSubTrace(data.trace_id, {
|
|
updateSubTrace(data.trace_id, {
|
|
|
- status: 'completed',
|
|
|
|
|
|
|
+ status: data.status,
|
|
|
summary: data.summary,
|
|
summary: data.summary,
|
|
|
- total_messages: data.total_messages,
|
|
|
|
|
- total_tokens: data.total_tokens,
|
|
|
|
|
- total_cost: data.total_cost
|
|
|
|
|
|
|
+ ...data.stats
|
|
|
})
|
|
})
|
|
|
- regenerateDAG()
|
|
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -657,19 +697,29 @@ if (data.event === 'sub_trace_completed') {
|
|
|
|
|
|
|
|
| 字段 | 类型 | 说明 |
|
|
| 字段 | 类型 | 说明 |
|
|
|
|------|------|------|
|
|
|------|------|------|
|
|
|
-| `trace_id` | string | 层级化 ID(如 "abc123", "abc123.A", "abc123.A.1")|
|
|
|
|
|
|
|
+| `trace_id` | string | 根 Trace 为 UUID;子 Trace 为 `{parent}@{mode}-{timestamp}-{seq}` |
|
|
|
| `mode` | string | `call` - 单次调用 / `agent` - Agent 模式 |
|
|
| `mode` | string | `call` - 单次调用 / `agent` - Agent 模式 |
|
|
|
| `task` | string | 任务描述 |
|
|
| `task` | string | 任务描述 |
|
|
|
| `parent_trace_id` | string \| null | 父 Trace ID(Sub-Trace 才有)|
|
|
| `parent_trace_id` | string \| null | 父 Trace ID(Sub-Trace 才有)|
|
|
|
| `parent_goal_id` | string \| null | 哪个 Goal 启动的(Sub-Trace 才有)|
|
|
| `parent_goal_id` | string \| null | 哪个 Goal 启动的(Sub-Trace 才有)|
|
|
|
-| `agent_type` | string \| null | "main" / "explore" / "delegate" / "compaction" |
|
|
|
|
|
-| `status` | string | `running` / `completed` / `failed` |
|
|
|
|
|
|
|
+| `agent_type` | string \| null | `main` / `explore` / `delegate` / `compaction` / `validator` |
|
|
|
|
|
+| `status` | string | `running` / `completed` / `failed` / `stopped` |
|
|
|
|
|
+| `context` | object | 模式、血缘及 Recursive 协议状态;前端至少使用 `agent_mode` |
|
|
|
| `total_messages` | int | Message 总数 |
|
|
| `total_messages` | int | Message 总数 |
|
|
|
| `total_tokens` | int | Token 总消耗 |
|
|
| `total_tokens` | int | Token 总消耗 |
|
|
|
| `total_cost` | float | 成本总和 |
|
|
| `total_cost` | float | 成本总和 |
|
|
|
| `created_at` | string | 创建时间(ISO 8601)|
|
|
| `created_at` | string | 创建时间(ISO 8601)|
|
|
|
| `completed_at` | string \| null | 完成时间 |
|
|
| `completed_at` | string \| null | 完成时间 |
|
|
|
|
|
|
|
|
|
|
+Recursive 前端相关的 `context` 字段:
|
|
|
|
|
+
|
|
|
|
|
+| 字段 | 说明 |
|
|
|
|
|
+|------|------|
|
|
|
|
|
+| `agent_mode` / `agent_mode_revision` | 当前 Trace 固化的模式和协议版本 |
|
|
|
|
|
+| `root_trace_id` / `agent_depth` | 任务树根 ID 和业务 Agent 深度 |
|
|
|
|
|
+| `created_by_tool` | `agent` 为业务子 Trace,`validator` 为验收 Trace |
|
|
|
|
|
+| `task_protocol` | TaskBrief、待审核报告、审核记录和下一步动作 |
|
|
|
|
|
+
|
|
|
**Trace ID 规则**:
|
|
**Trace ID 规则**:
|
|
|
- 主 Trace:标准 UUID(如 "2f8d3a1c-4b6e-4f9a-8c2d-1e5b7a9f3c4d")
|
|
- 主 Trace:标准 UUID(如 "2f8d3a1c-4b6e-4f9a-8c2d-1e5b7a9f3c4d")
|
|
|
- Sub-Trace:`{parent_uuid}@{mode}-{timestamp}-{seq}`
|
|
- Sub-Trace:`{parent_uuid}@{mode}-{timestamp}-{seq}`
|
|
@@ -699,9 +749,9 @@ if (data.event === 'sub_trace_completed') {
|
|
|
| `type` | string | `normal` / `agent_call` |
|
|
| `type` | string | `normal` / `agent_call` |
|
|
|
| `description` | string | 目标描述(做什么)|
|
|
| `description` | string | 目标描述(做什么)|
|
|
|
| `reason` | string | 创建理由(为什么做)|
|
|
| `reason` | string | 创建理由(为什么做)|
|
|
|
-| `status` | string | `pending` / `in_progress` / `completed` / `abandoned` |
|
|
|
|
|
|
|
+| `status` | string | 后端:`pending` / `in_progress` / `waiting_children` / `pending_review` / `completed` / `failed` / `abandoned`;前端类型额外保留 `running` 兼容旧数据 |
|
|
|
| `summary` | string \| null | 完成/放弃时的总结 |
|
|
| `summary` | string \| null | 完成/放弃时的总结 |
|
|
|
-| `sub_trace_ids` | Array<{trace_id: string, mission: string}> \| null | 启动的 Sub-Trace 信息(仅 agent_call)|
|
|
|
|
|
|
|
+| `sub_trace_ids` | Array<string \| {trace_id: string, mission?: string}> \| null | 启动的 Sub-Trace 信息(仅 agent_call)|
|
|
|
| `agent_call_mode` | string \| null | "explore" / "delegate" / "sequential"(仅 agent_call)|
|
|
| `agent_call_mode` | string \| null | "explore" / "delegate" / "sequential"(仅 agent_call)|
|
|
|
| `sub_trace_metadata` | object \| null | Sub-Trace 元数据(仅 agent_call,包含最后消息等)|
|
|
| `sub_trace_metadata` | object \| null | Sub-Trace 元数据(仅 agent_call,包含最后消息等)|
|
|
|
| `self_stats` | GoalStats | 自身统计 |
|
|
| `self_stats` | GoalStats | 自身统计 |
|
|
@@ -717,14 +767,15 @@ if (data.event === 'sub_trace_completed') {
|
|
|
- 表示启动了 Sub-Agent 的特殊 Goal
|
|
- 表示启动了 Sub-Agent 的特殊 Goal
|
|
|
- 不直接关联 Messages,而是启动一个或多个独立的 Sub-Trace
|
|
- 不直接关联 Messages,而是启动一个或多个独立的 Sub-Trace
|
|
|
- 通过 `sub_trace_ids` 关联启动的所有 Sub-Traces
|
|
- 通过 `sub_trace_ids` 关联启动的所有 Sub-Traces
|
|
|
|
|
+- Legacy 同一 Goal 的 `sub_trace_ids` 保持当前批次覆盖语义;Recursive 累计合并、去重,每个父 Trace 最多 6 个直接业务孩子
|
|
|
- 通过 `agent_call_mode` 标记执行模式:
|
|
- 通过 `agent_call_mode` 标记执行模式:
|
|
|
- - `"explore"` - 并行探索:启动多个 Sub-Trace 并行执行,汇总结果后合并
|
|
|
|
|
|
|
+ - `"explore"` - 多任务汇合:Legacy 整批并行;Recursive 默认串行,显式并行时最多 2 个
|
|
|
- `"delegate"` - 单线委托:将大任务委托给单个 Sub-Trace 执行
|
|
- `"delegate"` - 单线委托:将大任务委托给单个 Sub-Trace 执行
|
|
|
- `"sequential"` - 顺序执行:按顺序启动多个 Sub-Trace
|
|
- `"sequential"` - 顺序执行:按顺序启动多个 Sub-Trace
|
|
|
|
|
|
|
|
**分支探索与合并(`explore` 模式)**:
|
|
**分支探索与合并(`explore` 模式)**:
|
|
|
-1. **分支开始**:`agent_call` Goal 同时启动多个 Sub-Trace(如 2-5 个)
|
|
|
|
|
-2. **并行执行**:各 Sub-Trace 独立运行,有各自的 GoalTree 和 Messages
|
|
|
|
|
|
|
+1. **分支开始**:`agent_call` Goal 创建多个 Sub-Trace(Recursive 每父累计最多 6 个)
|
|
|
|
|
+2. **调度执行**:各 Sub-Trace 独立运行;Legacy 批量并行,Recursive 按 Runner 配置串行或最多两路并行
|
|
|
3. **收集元数据**:执行完成后,收集每个 Sub-Trace 的:
|
|
3. **收集元数据**:执行完成后,收集每个 Sub-Trace 的:
|
|
|
- 最后一条 assistant 消息(`last_message`)
|
|
- 最后一条 assistant 消息(`last_message`)
|
|
|
- 执行总结(`summary`)
|
|
- 执行总结(`summary`)
|
|
@@ -785,7 +836,7 @@ if (data.event === 'sub_trace_completed') {
|
|
|
|
|
|
|
|
**字段说明**:
|
|
**字段说明**:
|
|
|
- `task` - Sub-Trace 的任务描述
|
|
- `task` - Sub-Trace 的任务描述
|
|
|
-- `status` - Sub-Trace 的最终状态(completed/failed)
|
|
|
|
|
|
|
+- `status` - Sub-Trace 的最终状态(completed/failed/stopped)
|
|
|
- `summary` - Sub-Trace 的执行总结
|
|
- `summary` - Sub-Trace 的执行总结
|
|
|
- 优先使用 `run_agent()` 返回的 `summary` 字段(如果有)
|
|
- 优先使用 `run_agent()` 返回的 `summary` 字段(如果有)
|
|
|
- 否则使用最后一条 assistant 消息的内容(截断至 200 字符)
|
|
- 否则使用最后一条 assistant 消息的内容(截断至 200 字符)
|
|
@@ -1078,7 +1129,7 @@ function generateEdges(visibleGoals) {
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-### 示例:Sub-Trace 展开
|
|
|
|
|
|
|
+### 示例:Recursive Sub-Trace 逐层钻取
|
|
|
|
|
|
|
|
```javascript
|
|
```javascript
|
|
|
// 主 Trace 的 GoalTree
|
|
// 主 Trace 的 GoalTree
|
|
@@ -1100,36 +1151,21 @@ const mainTrace = {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 折叠视图:[1] → [2:并行探索] → [3]
|
|
|
|
|
-
|
|
|
|
|
-// 展开 Sub-Traces 后的视图:
|
|
|
|
|
-// ┌→ [abc123.A] ────┐
|
|
|
|
|
-// [1] ──────┼ ├──→ [3]
|
|
|
|
|
-// └→ [abc123.B] ────┘
|
|
|
|
|
|
|
+// 仅 Recursive 把 sub_trace_ids 规范化为最多 6 个 A1~A6 入口。
|
|
|
|
|
+// 点击入口后切换 selectedTraceId,而不是在当前图内聚合展开。
|
|
|
|
|
|
|
|
-// 继续展开 Sub-Trace abc123.A 内部
|
|
|
|
|
-async function loadSubTrace(traceId) {
|
|
|
|
|
- const resp = await fetch(`/api/traces/${traceId}`)
|
|
|
|
|
- return await resp.json() // 返回完整 Trace,含 goal_tree
|
|
|
|
|
|
|
+async function openSubTrace(entry) {
|
|
|
|
|
+ setSelectedTraceId(entry.trace_id)
|
|
|
|
|
+ const resp = await fetch(`/api/traces/${entry.trace_id}`)
|
|
|
|
|
+ return await resp.json()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const subTraceA = await loadSubTrace("abc123.A")
|
|
|
|
|
-// {
|
|
|
|
|
-// trace_id: "abc123.A",
|
|
|
|
|
-// goal_tree: {
|
|
|
|
|
-// goals: [
|
|
|
|
|
-// { id: "1", description: "JWT 设计" },
|
|
|
|
|
-// { id: "2", description: "JWT 实现" }
|
|
|
|
|
-// ]
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// 展开后显示 Sub-Trace 内部 Goals:
|
|
|
|
|
|
|
+// 以下“同图展开”仅是旧设计示意,当前未实现:
|
|
|
// ┌→ [A.1:JWT设计] → [A.2:JWT实现] ──┐
|
|
// ┌→ [A.1:JWT设计] → [A.2:JWT实现] ──┐
|
|
|
// [1] ──────┼ ├──→ [3]
|
|
// [1] ──────┼ ├──→ [3]
|
|
|
// └→ [abc123.B] ─────────────────────┘
|
|
// └→ [abc123.B] ─────────────────────┘
|
|
|
|
|
|
|
|
-// 注意:前端显示为 "A.1",实际查询是 GET /api/traces/abc123.A/messages?goal_id=1
|
|
|
|
|
|
|
+// 当前实际行为是切换到 abc123.A 的独立流程图。
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
### 视觉区分
|
|
### 视觉区分
|
|
@@ -1195,4 +1231,6 @@ function connect(traceId) {
|
|
|
## 相关文档
|
|
## 相关文档
|
|
|
|
|
|
|
|
- [Context 管理设计](../cyber_agent/docs/context-management.md) - Goal 机制完整设计
|
|
- [Context 管理设计](../cyber_agent/docs/context-management.md) - Goal 机制完整设计
|
|
|
-- [Trace 模块说明](../docs/trace-api.md) - 后端实现细节
|
|
|
|
|
|
|
+- [Trace 模块说明](../cyber_agent/docs/trace-api.md) - 后端实现细节
|
|
|
|
|
+- [Agent 运行模式](../cyber_agent/docs/agent-modes.md) - Legacy/Recursive 边界和调度
|
|
|
|
|
+- [Recursive 任务协议](../cyber_agent/docs/recursive-task-protocol.md) - 报告、Validator 和审核状态机
|