fix: filter extra fields from tool_use blocks to prevent Anthropic API rejection

PS
1y ago
+13-2

Summary

  • Filters tool_use blocks to only include fields that Anthropic accepts in requests: type, id, name, and input
  • Prevents agent failures on step 2+ caused by the caller field being rejected

Problem

Anthropic's API returns a caller field in tool_use response blocks (introduced with programmatic tool calling), but rejects this field when sent back in subsequent requests. The current model_dump() preserves all fields, causing validation errors.

Test plan

  • Unit tests pass
  • Manual test with multi-step agent execution

🤖 Generated with Claude Code


Summary by cubic

Strip unsupported fields from tool_use blocks before sending to Anthropic to prevent validation errors and multi-step agent failures. Only type, id, name, and input are kept; caller is removed.