Skip to content

Fix s02 orphaned tool_result repair ordering in normalize_messages#199

Open
shyboy429 wants to merge 4 commits intoshareAI-lab:mainfrom
shyboy429:fix/s02-tool-result-order
Open

Fix s02 orphaned tool_result repair ordering in normalize_messages#199
shyboy429 wants to merge 4 commits intoshareAI-lab:mainfrom
shyboy429:fix/s02-tool-result-order

Conversation

@shyboy429
Copy link
Copy Markdown

Summary

This fixes normalize_messages() so missing tool_result blocks are inserted
immediately after the assistant message that contains the originating tool_use,
instead of being appended to the end of the message list.

Why

Anthropic's Messages API requires each tool_result block to correspond to a
tool_use block in the previous assistant message. Appending orphaned
tool_result blocks to the end can break that invariant and cause 400 errors.

Changes

  • repair orphaned tool_result blocks in-place after the matching assistant message
  • update the Chinese teaching doc example to match the implementation
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 9, 2026

@shyboy429 is attempting to deploy a commit to the crazyboym's projects Team on Vercel.

A member of the Team first needs to authorize it.

@CrazyBoyM CrazyBoyM force-pushed the main branch 2 times, most recently from 36897b1 to d882d01 Compare April 14, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants