Skip to content

BadRequestError: tool_call_id not found when using Claude/OpenAI with session history containing tool calls #4348

@thesynapses

Description

@thesynapses

🔴 Required Information

Please ensure all items in this section are completed to allow for efficient
triaging. Requests without complete information may be rejected/deprioritized.
If an item is not applicable to you, please mark it as N/A

Describe the Bug:
When using Claude via Vertex AI or OpenAI models with ADK, replaying session history that contains tool calls results in a BadRequestError because tool_call_id is missing.

Steps to Reproduce:

  1. Use ADK with session continuity (loading previous session events)
  2. The previous session contains tool calls (function_call and function_response)
  3. Use Claude via Vertex AI or the OpenAI model via LiteLLM
  4. Send a follow-up message that requires replaying the session history

Root Cause Analysis

  1. Gemini API returns id=None for function calls
  2. ADK's populate_client_function_call_id() generates adk-{uuid} IDs to fill this gap
  3. Before sending history to LLM, remove_client_function_call_id() strips all adk-* prefixed IDs, setting them to None
  4. Claude via Vertex AI and OpenAI requires tool_call_id on tool response messages to match them to function calls
  5. With IDs stripped, these models fail with BadRequestError

Expected Behavior:
Session history with tool calls should work correctly with Claude/OpenAI models. The adk-* function call IDs should be preserved since:

  • Claude via Vertex AI requires tool_call_id
  • OpenAI models require a matching tool_call_id
  • Gemini ignores extra IDs (generates its own or uses None)

Observed Behavior:
What actually happened? Include error messages or crash stack traces here.

Environment Details:

  • ADK version: 1.2.3+
  • Python version: 3.11
  • Model: Claude via Vertex AI (also affects OpenAI via LiteLLM)

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: Claude via Vertex AI (also affects OpenAI via LiteLLM)

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression:
Did this work in a previous version of ADK? If so, which one? No

Logs:
Please attach relevant logs. Wrap them in code blocks (```) or attach a
text file.

litellm.BadRequestError: litellm.BadRequestError: VertexAIException BadRequestError - 
{'error': {'message': "tool_call_id '...' not found in list of function calls in the chat history"}}

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Labels

answered[Status] This issue has been answered by the maintainermodels[Component] Issues related to model supportrequest clarification[Status] The maintainer need clarification or more information from the author

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions