Skip to content

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

Open
@kmariunas

Description

@kmariunas

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions