pref(tools):优化tools调用提示词以及格式#232
Merged
Merged
Conversation
Collaborator
Author
|
/review -codex |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
/review -codex |
| continue | ||
| } | ||
| content := strings.TrimSpace(message.Content) | ||
| if content == "" || content == microCompactClearedMessage { |
Contributor
There was a problem hiding this comment.
If a tool succeeds with empty Content but meaningful ToolMetadata, this branch skips projection entirely. The provider adapters do not serialize ToolMetadata, so the next model round receives an empty tool message and loses the result semantics completely. That is reachable for generic ToolManager/adapter implementations even if most built-in tools currently return "ok". Please either project metadata-only tool results as well, or normalize successful empty-content results before they are persisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
本次 PR 聚焦解决 NeoCode 在任务执行过程中反复调用同一工具的问题,并优先落地两项最小、直接、可验证的优化。
第一项是升级 tool result 的回灌格式,不再只把裸
Content返回给模型,而是把工具名称、执行状态、调用 ID、截断标记以及关键 metadata 一并整理成稳定的结构化文本,让模型能准确理解“这次工具调用到底发生了什么”。第二项是补充参考 Codex 风格的 anti-loop prompt 约束,在默认系统提示中明确“最小必要工具”“不要重复相同参数调用”“写入成功后最多做一次定向验证”“结果已回答问题时应停止工具调用”等行为边界。
本次改动不引入新的顶层模块,也不提前加入 runtime 侧的硬拦截去重逻辑,而是先通过更强的结果表达和更明确的提示词约束,降低重复调用的发生概率。
主要改动
internal/tools新增统一的模型侧 tool result 格式化逻辑,将工具结果收敛为包含tool、status、tool_call_id、truncated、meta.*和content的结构化文本。internal/runtime中调整 tool message 回灌方式,写回 session 和 provider 上下文时不再只传递原始ToolResult.Content,而是传递格式化后的结构化结果。internal/context的默认系统提示中补充 anti-loop 规则,明确最小必要工具原则、同参数重复调用限制、写入后验证上限以及何时应停止工具调用并直接回答用户。internal/tools、internal/context、internal/runtime相关测试,覆盖工具结果格式化、提示词规则和 runtime 回灌链路。预期收益
ok或弱结果而继续重复调用同一工具的概率。