Skip to content

fix(prompt_builder): tool-role history loss + typo breaking tool_calls#27

Open
youyou752 wants to merge 11 commits into
YuJunZhiXue:mainfrom
youyou752:fix/tool-loop-history-and-typo
Open

fix(prompt_builder): tool-role history loss + typo breaking tool_calls#27
youyou752 wants to merge 11 commits into
YuJunZhiXue:mainfrom
youyou752:fix/tool-loop-history-and-typo

Conversation

@youyou752

Copy link
Copy Markdown

问题

在 v0.5.0+ 用 OpenAI 兼容 tools 接口跑 agent loop 时发现两个 bug。

Bug 1:prompt_builder.py:419 typo → NameError → HTTP 500

_looks_like_opencode_system_prompt(system)  # ← 带下划线,但 import 的名字没下划线

每一个带 tools=[]/v1/chat/completions 请求都会 NameError 崩,回 500。

Bug 2:默认 profile tool-loop 死在第 5 轮

非 qwen-code / claude-code 的通用客户端(Cline、Continue、自写 agent等)命中 default profile:

  • max_history_msgs = 8:5 轮 tool call 以后早期上下文全部被截
  • tool_result_limit = 300 chars:几行 JSON 就被截断,模型看不到完整 tool output
  • role=="tool" 的消息跟 assistant/user 一起计入 msg_count,虽然 tool-role msg 它们是上一步 assistant tool_call 的回收数据,本不应几乎平级被简他

结果模型在第 6-7 轮就看不到自己前几轮调用的 tool 返回值,开始幻觉/重复调用/提前 finish。

修复

  1. line 419_looks_like_opencode_system_prompt → looks_like_opencode_system_prompt
  2. line 442-443:default profile 开 tools 时 max_history_msgs 8 → 32tool_result_limit 300 → 3000
  3. line 476role=="tool" 的消息不再计入 msg_count(仍受字符 budget 约束)

测试

用 天气 + compare_numbers 两个工具搭 7 步任务回放:

模型 修复前 修复后
qwen3.6-plus 第 6 轮起丢历史 → 重复调用 → 不收敛 7 轮正确收敛,finish=stop
qwen3.6-max-preview 同上 7 轮正确收敛

另用真实 sandbox shell agent (shell/write_file/read_file/finish 4 工具)跑了个分析 docker log 写报告的任务,7 轮 25s 0 错误完成。

影响面

  • 只改 default profile(QWEN_CODE_OPENAI_PROFILE / CLAUDE_CODE_OPENAI_PROFILE 不受影响)
  • 无新增依赖,无 schema 变更
  • diff 5 行

YuJunZhiXue and others added 11 commits April 10, 2026 02:29
修改docker和添加图片生成功能
修改了claude code 中长任务工具调用
删除4
…es-qwen-code

Add Responses API compatibility and improve Qwen Code tool-call handling
Two fixes:

1. line 419: typo _looks_like_opencode_system_prompt -> looks_like_opencode_system_prompt (NameError crashed every tools request with HTTP 500)

2. default client_profile (non qwen-code / non claude-code) with tools: max_history_msgs 8->32; tool-role messages no longer count against msg_count; tool_result_limit 300->3000 chars. Fixes agent loops losing tool history after ~5 turns.
@YuJunZhiXue

Copy link
Copy Markdown
Owner

有冲突我就先不拉, 你们说的我都有改,而且我加了很多新的功能,感谢佬

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.

3 participants