Skip to content

fix(orchestrator): 修复多轮对话 3 个问题#254

Merged
hrygo merged 7 commits into
mainfrom
fix/251-orchestrator-context-reuse
Feb 17, 2026
Merged

fix(orchestrator): 修复多轮对话 3 个问题#254
hrygo merged 7 commits into
mainfrom
fix/251-orchestrator-context-reuse

Conversation

@hrygo

@hrygo hrygo commented Feb 17, 2026

Copy link
Copy Markdown
Owner

Summary

修复 Orchestrator 模式多轮对话的 3 个问题:

  1. Tool 面板显示 "unknown 等待中"

    • 修复 executor.gosendTaskStartEvent/EndEvent 始终传 index: -1 的问题
    • 修复 decomposer.go 中 LLM 未返回 task id 时为空的问题
  2. blockSummary 面板信息缺失

    • 修复 TotalDurationMs 使用 token 数量而非实际耗时
    • 添加 ToolCallCountToolsUsedStatus 等字段
  3. Orchestrator 未持久化消息

    • 添加 assistantContent 收集 AI 回复内容
    • 调用 CompleteBlock 持久化到数据库

Changes

  • ai/agents/orchestrator/executor.go
  • ai/agents/orchestrator/decomposer.go
  • ai/agents/orchestrator/expert_registry.go
  • ai/agents/orchestrator/prompts.go
  • config/orchestrator/prompts.yaml
  • server/router/api/v1/ai/handler.go

Test plan

  • 测试 "搜索关于工作的笔记",Tool 面板应正确显示 agent 名称和状态
  • 测试 "总结这些笔记",blockSummary 应显示工具调用信息
  • 测试多轮对话,消息应持久化到数据库

Resolves #251

🤖 Generated with Claude Code

hotplex-ai and others added 6 commits February 17, 2026 14:17
1. executor: 修复 task index 始终为 -1 导致前端无法更新状态
2. decomposer: 修复 LLM 未返回 task id 时为空的问题
3. handler: 修复 BlockSummary 信息缺失 + 添加消息持久化

- executor.go: sendTaskStartEvent/EndEvent 传入正确的 index
- decomposer.go: parseTaskPlan 自动生成 task ID,fallbackPlan 添加默认 ID
- handler.go: 添加 assistantContent 收集 + CompleteBlock 持久化 + 修复事件类型

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 添加 "answer" 和 "aggregation" 事件类型收集
- 修复 success_count=0 和 FinalResponse 为空的问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 将 EventWithMeta 的 Meta 信息序列化为 JSON 一起转发
- 修复前端显示 "unknown" 的问题(因为缺少 tool_name)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- expert_registry: 发送 JSON 格式 {"data": "...", "meta": {...}}
- handler: 解析 JSON 并设置 EventMeta 字段
- 修复 ToolCallsSection 显示 "unknown" 的问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 后端: 改进 JSON 格式事件处理,正确传递 tool_name/tool_id
- 前端: 解析 JSON 格式事件内容,提取 metadata
- 统计: 添加 ToolsUsed 跟踪和成本计算
- UI: 简化工具调用显示,修复表格样式

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
问题:tool_result 事件无法匹配到对应的 tool_use 事件,导致前端
extractToolCalls 无法找到结果,工具卡片一直显示"等待中"状态。

原因:Claude Code CLI 的 tool_result 块使用 tool_use_id 字段
(而非 id)来引用对应的 tool_use。

修复:
- ContentBlock 结构添加 ToolUseID 字段
- case "user" 分支使用 tool_use_id 进行匹配

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hrygo

hrygo commented Feb 17, 2026

Copy link
Copy Markdown
Owner Author

Code review

Found 2 issues:

  1. runner.go: case "tool_result" should use ToolUseID for tool matching (Code comment at line 919-921 says "tool_result blocks use tool_use_id to reference the corresponding tool_use")

The case "tool_result" branch (lines 851-857) uses block.ID for toolID, but the case "user" branch (lines 919-924) correctly uses block.ToolUseID with fallback to block.ID. This inconsistency will cause tool_use/tool_result matching to fail in the frontend when the ID fields differ.

Status: "success",
DurationMs: durationMs,
TotalDurationMs: totalDuration,
OutputSummary: TruncateString(msg.Output, 500),
}
r.logger.Debug("CCRunner: sending tool_result event", "output_length", len(msg.Output), "duration_ms", durationMs)
if err := callback("tool_result", &EventWithMeta{EventType: "tool_result", EventData: msg.Output, Meta: meta}); err != nil {
return err
}
}

  1. handler.go: Tool event persistence silently fails without warning (Line 694-695 says this is "CRITICAL FIX" for frontend display)

When currentBlock is nil (e.g., temporary conversations) or h.blockManager is nil, tool_use/tool_result events are not persisted to database, but no warning is logged. This causes frontend to show "pending" status indefinitely without any diagnostic information.

var blockMode BlockMode
if req.EvolutionMode {
blockMode = BlockModeEvolution
} else if req.GeekMode {
blockMode = BlockModeGeek
} else {
blockMode = BlockModeNormal
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

1. runner.go: case "tool_result" 分支使用 ToolUseID 匹配工具调用
   - 与 case "user" 分支保持一致
   - 优先使用 ToolUseID,回退到 ID

2. handler.go: 添加工具事件持久化失败的警告日志
   - 当 currentBlock 或 blockManager 为 nil 时记录警告
   - 帮助诊断前端 "pending" 状态问题

Refs #254

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hrygo hrygo merged commit 040b994 into main Feb 17, 2026
13 checks passed
@hrygo hrygo deleted the fix/251-orchestrator-context-reuse branch February 17, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Orchestrator 调度 sub-agent 时上下文丢失

2 participants