Skip to content

Conversation

@habema
Copy link
Contributor

@habema habema commented Jan 18, 2026

Summary

Fixes Missing corresponding tool call for tool response message errors when using Gemini models. The message ordering fix that was already applied to Anthropic models is now also applied to Gemini models, since they seem have the same requirement that tool calls must immediately precede their corresponding tool responses.

Error:

litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Missing corresponding tool call for tool response message. Received - message={'role': 'tool', 'tool_call_id': 'call_c1f7ac7f4d564f0ab55574de3052', 'content': '{"success": true, "result": {"webBuildErrors": {}}, "error": null}'}, last_message_with_tool_calls={'role': 'assistant', 'content': "It's currently 12:16 PM. Is there anything I can help you with in your app today?"}

Repro Script:

import asyncio
from datetime import datetime

from agents import Agent, Runner, function_tool

# function_call_output preceeds function_call
history_list = [
    {
        "type": "message",
        "role": "user",
        "content": [{"type": "input_text", "text": "Hi. What time is it?"}],
    },
    {
        "call_id": "call_04de935c15ad4e4b9ac226e5c2e8",
        "output": '{"success":true,"result":{"time":"12:16 PM","format":"%I:%M %p"},"error":null}',
        "type": "function_call_output",
    },
    {
        "arguments": '{"format": "%I:%M %p"}',
        "call_id": "call_04de935c15ad4e4b9ac226e5c2e8",
        "name": "get_server_time",
        "type": "function_call",
        "id": "__fake_id__",
        "provider_data": {
            "model": "vertex_ai/gemini-3-flash-preview",
            "response_id": "Cc9sadGmNLCAz_IPqPSEqQw",
            "thought_signature": "CiEBjz1rX65+CQhe4AGRK95x8byJ82UbcroiDLuw+NNisjI=",
        },
    },
    {
        "id": "__fake_id__",
        "content": [
            {
                "annotations": [],
                "text": "It's currently 12:16 PM. Is there anything I can help you with in your app today?",
                "type": "output_text",
                "logprobs": [],
            }
        ],
        "role": "assistant",
        "status": "completed",
        "type": "message",
        "provider_data": {
            "model": "vertex_ai/gemini-3-flash-preview",
            "response_id": "C89sab_sG-mEz_IPvYGN0AY",
        },
    },
]


@function_tool
def get_server_time() -> str:
    """
    Returns the current time.
    """
    return datetime.now().strftime("%I:%M %p")


agent = Agent(
    name="Assistant",
    model="litellm/vertex_ai/gemini-3-flash-preview",
    instructions="You are a helpful agent.",
    tools=[get_server_time],
)


async def main():
    result = await Runner.run(agent, history_list + [{"content": "How about now?", "role": "user"}])
    print(result.final_output)


if __name__ == "__main__":
    asyncio.run(main())

@seratch seratch added this to the 0.6.x milestone Jan 18, 2026
@seratch seratch merged commit bb727b1 into openai:main Jan 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants