Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid_request_error when using "chat_completions" with triage agent (gemini -> any other model) #237

Open
kmariunas opened this issue Mar 19, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@kmariunas
Copy link

Describe the question

openai.BadRequestError: Error code: 400 - {'error': {'code': 'invalid_request_error', 'message': "messages.1.content.1.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'", 'type': 'invalid_request_error', 'param': None}}

I get this error when one agent passes it's tool usage info and other stuff to my anthropic agent.

I see that the input looks like this: [{'content': 'Please search for my memory about smart cities', 'role': 'user'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': '\n', 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': '', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': '', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}], and the fake ids are converted to empty strings afterwards, am i doing something wrong?

Debug information

  • Agents SDK version: (e.g. v0.0.4)
  • Python version (e.g. Python 3.12)

Repro steps

Ideally provide a minimal python script that can be run to reproduce the issue.


async def main_reproduce():
    set_default_openai_api("chat_completions")
    anthropic = AsyncOpenAI(
            api_key="",
            base_url="https://api.anthropic.com/v1/"
        )
    gemini = AsyncOpenAI(
            api_key="",
            base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
        )

    gen_agent = Agent(
            name="General Chat Agent",
            instructions="provide a response and use tools",
            model=OpenAIChatCompletionsModel(model="claude-3-5-sonnet-20241022", openai_client=anthropic),
            handoff_description="general",
        )
    
    triage = Agent(
            name="Handoff agent",
            instructions="choose the correct agent to respond",
            model=OpenAIChatCompletionsModel(model="gemini-2.0-flash-001", openai_client=gemini),
            handoffs=[gen_agent]
        )
    result = await Runner.run(triage, "Help me remember the past month")
    print(result.final_output)


asyncio.run(main_reproduce())

Expected behavior

A clear and concise description of what you expected to happen.

@kmariunas kmariunas added the bug Something isn't working label Mar 19, 2025
@kmariunas
Copy link
Author

kmariunas commented Mar 19, 2025

using two gemini models works, even though the input_list still has empty call_id ids
{'content': 'Help me remember the past month', 'role': 'user'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': '', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': '', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}, {'id': '__fake_id__',

@kmariunas
Copy link
Author

Using two anthropic models works as well, they generate 'call_id' value

[{'content': 'Help me remember the past month', 'role': 'user'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': "I'll help you transfer to the General Chat Agent who can assist with recalling and discussing past events.", 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': 'toolu_0166CqqT3JEj3XXFCqSRp2QM', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': 'toolu_0166CqqT3JEj3XXFCqSRp2QM', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': "I aim to help, but I should note that I don't have access to your personal memories or experiences from the past month. To help you remember, I can:\n\n1. Ask you questions about specific aspects you want to recall\n2. Help you walk through the timeline of the past month \n3. Discuss major public events that happened during that time\n\nWhat specifically would you like to remember about the past month? I can guide our conversation from there.", 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}]

@kmariunas kmariunas changed the title invalid_request_error when using "chat_completions" with triage agent invalid_request_error when using "chat_completions" with triage agent (gemini -> any other model) Mar 19, 2025
@rm-openai
Copy link
Collaborator

Yeah looks like this is an issue with Gemini. Specifically, when I ran this curl snippet: https://ai.google.dev/gemini-api/docs/openai#function-calling

The response has empty IDs for the tool call:

{"choices":[{"finish_reason":"tool_calls","index":0,"message":{"role":"assistant","tool_calls":[{"function":{"arguments":"{\"location\":\"Chicago, IL\"}","name":"get_weather"},"id":"","type":"function"}]}}],"created":1742394406,"model":"gemini-2.0-flash","object":"chat.completion","usage":{"completion_tokens":7,"prompt_tokens":41,"total_tokens":48}}

That is incompatible with openai, anthropic etc.

I'm not totally sure how to work around this - any suggestions?

@kmariunas
Copy link
Author

Maybe for gemini specifically it would be possible to replace call_id with some random id? Feels hacky, but would be really nice to have all of the models available for agents 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants