Skip to content

Tool calling with Gemini + structured_output #236

Open
@ant31

Description

@ant31

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues.

Describe the bug

When using tool calling combined with output_type on a Agent using Gemini as model it fails with:

BadRequestError: Error code: 400 - [{'error': {'code': 400, 'message': "For controlled generation of only function calls (forced function calling), please set 'tool_config.function_calling_config.mode' field to ANY instead of populating 'response_mime_type' and 'response_schema' fields. For more details, see: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#tool-config", 'status': 'INVALID_ARGUMENT'}}]

When

  • there's no tools it works
  • output_type is str it works
  • when both are set it fails

Debug information

  • Agents SDK version: v0.0.4 and main
  • Python 3.12

Repro steps

class MyContext:
    def __init__(self, user_name: str) -> None:
        self.user_name = user_name

@function_tool
async def get_user_name(ctx: RunContextWrapper[MyContext]) -> str:
    print(f"User id: {ctx.context.user_name}")
    return ctx.context.user_name

class GreetAnswer(BaseModel):
  user_name: str
  answers: list[str]



hiagent = Agent(
    name="HiAgent",
    instructions="Greet the user by it's name",
    model=OpenAIChatCompletionsModel(model="gemini-1.5-pro",
                                     openai_client=openai_aclient("gemini")),
    output_type=GreetAnswer,
    tools=[get_user_name]
)

res = (await Runner.run(hiagent, context=MyContext(user_name="ant31"), input="Hi")).final_output

Expected behavior

I expect to works the same than with openai models.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions