Skip to content

fix(s08): append tool_result before compact_history to avoid tool_use… - #502

Open
cookie250825 wants to merge 1 commit into
shareAI-lab:mainfrom
cookie250825:fix/s08-compact-tool-use-id
Open

fix(s08): append tool_result before compact_history to avoid tool_use…#502
cookie250825 wants to merge 1 commit into
shareAI-lab:mainfrom
cookie250825:fix/s08-compact-tool-use-id

Conversation

@cookie250825

Copy link
Copy Markdown

…_id mismatch

When the model calls the compact tool, compact_history() replaces the entire messages list, discarding the assistant message that contains block.id. Any subsequent tool_result referencing that id triggers a 400 BadRequestError:

tool_use_id found in tool_result blocks: call_xxx.
Each tool_result block must have a corresponding tool_use block.

Fix: append the tool_result and user message first, then run compact_history() so the tool_use/tool_result pair is intact before compaction.

Fixes #500

…_id mismatch

When the model calls the compact tool, compact_history() replaces the entire
messages list, discarding the assistant message that contains block.id. Any
subsequent tool_result referencing that id triggers a 400 BadRequestError:

  tool_use_id found in tool_result blocks: call_xxx.
  Each tool_result block must have a corresponding tool_use block.

Fix: append the tool_result and user message first, then run compact_history()
so the tool_use/tool_result pair is intact before compaction.

Fixes shareAI-lab#500
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.

s08: compact 工具在替换历史后追加了孤立的 tool_result——下一次 API 请求报 400 并导致进程崩溃

1 participant