Skip to content

fix tool_use id handling for anthropic models on session resume#5157

Open
knQzx wants to merge 2 commits intogoogle:mainfrom
knQzx:fix-anthropic-tool-use-ids
Open

fix tool_use id handling for anthropic models on session resume#5157
knQzx wants to merge 2 commits intogoogle:mainfrom
knQzx:fix-anthropic-tool-use-ids

Conversation

@knQzx
Copy link
Copy Markdown

@knQzx knQzx commented Apr 4, 2026

Summary

  • when using anthropic models (claude) via ADK, resuming a session fails with BadRequestError because tool_use IDs get corrupted during replay
  • two fixes: (1) preserve function call IDs for AnthropicLlm models in contents.py, (2) sanitize tool_use IDs in anthropic_llm.py so invalid/empty IDs get replaced with a valid generated ID instead of empty string

Test plan

  • added 6 unit tests for _sanitize_tool_use_id (valid, None, empty, invalid chars)
  • added 1 integration test for AnthropicLlm ID preservation in contents flow
  • all 63 tests pass

fixes #5074

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 4, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 4, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 4, 2026

Response from ADK Triaging Agent

Hello @knQzx, thank you for your contribution!

Before we can merge this PR, you'll need to sign the Contributor License Agreement (CLA). You can do so by following the instructions at https://cla.developers.google.com/.

Thanks!

@knQzx
Copy link
Copy Markdown
Author

knQzx commented Apr 4, 2026

I have signed the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

anthropic_llm: part_to_message_block does not sanitize tool_use IDs, causing BadRequestError on session resume

2 participants