Check for existing issues
What happened?
When using Vertex AI Gemini, if the conversation history contains an assistant message with tool calls followed by another assistant message that only contains text (common in some client flows like Codex or when a model "thinks" out loud before calling a tool), LiteLLM fails to correctly map the subsequent tool result back to the original tool call.
This results in a crash with the following error:
litellm.APIConnectionError: Missing corresponding tool call for tool response message. Received - message={'role': 'tool', 'content': 'Chunk ID: 629156
Wall time: 0.0000 seconds
Process exited with code 1
Original token count: 12
Output:
bwrap: setting up uid map: Permission denied
', 'tool_call_id': 'call_c9266589ae6b421380c5acee31ed'}, last_message_with_tool_calls={'role': 'assistant', 'content': [{'type': 'text', 'text': "Okay, I understand you want to add a card for audio transcription to the AI Solution Showcase. First, I'll explore the project structure to find the right place to add it."}]}
Steps to Reproduce
You can reproduce this by running the following snippet using the internal transformation logic:
import sys
import os
sys.path.insert(0, os.getcwd())
from litellm.llms.vertex_ai.gemini.transformation import _gemini_convert_messages_with_history
# This specific sequence caused the crash
messages = [
{
"role": "assistant",
"tool_calls": [{"id": "call_123", "type": "function", "function": {"name": "get_weather", "arguments": "{}"}}]
},
{
"role": "assistant",
"content": "Checking that for you..."
},
{
"role": "tool",
"tool_call_id": "call_123",
"content": "Sunny"
}
]
print("Running Gemini transformation check...")
try:
result = _gemini_convert_messages_with_history(messages, model="gemini-1.5-flash")
print("\n✅ SUCCESS: The transformation worked!")
print("The fix successfully recovered the tool call name 'get_weather' from the history.")
except Exception as e:
print(f"\n❌ FAILED: {e}")
Relevant log output
❌ FAILED: Missing corresponding tool call for tool response message. Received - message={'role': 'tool', 'tool_call_id': 'call_123', 'content': 'Sunny'}, last_message_with_tool_calls={'role': 'assistant', 'content': 'Checking that for you...'}
What part of LiteLLM is this about?
SDK (litellm Python package)
What LiteLLM version are you on ?
v1.83.10
Twitter / LinkedIn details
No response
Check for existing issues
What happened?
When using Vertex AI Gemini, if the conversation history contains an assistant message with tool calls followed by another assistant message that only contains text (common in some client flows like Codex or when a model "thinks" out loud before calling a tool), LiteLLM fails to correctly map the subsequent tool result back to the original tool call.
This results in a crash with the following error:
Steps to Reproduce
You can reproduce this by running the following snippet using the internal transformation logic:
Relevant log output
What part of LiteLLM is this about?
SDK (litellm Python package)
What LiteLLM version are you on ?
v1.83.10
Twitter / LinkedIn details
No response