Skip to content

Multiple tool call failure with Gemini #6843

@apremalal

Description

@apremalal

What happened?

Describe the bug
Use of gemini models with multiple tool calls leads to openai.BadRequestError. This happens only if I set model_client_stream=True
To Reproduce

Following snippet will reproduce the issue.

from autogen_core.tools import BaseTool, FunctionTool
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from typing import List
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core import CancellationToken
import asyncio


async def get_current_time() -> str:
    return "The current time is 12:00 PM."

async def get_stock_price(stock: str ="MFST") -> str:
    return "The stock price is 500 dollors."


async def main():
    tools: List[BaseTool] = [
        FunctionTool(
            get_current_time,
            name="get_current_time",
            description="Get current time in Paris.",
        ),
        FunctionTool(
            get_stock_price,
            name="get_stock_price",
            description="Fetch the stock price for a given company."
        ),
    ]
    model_client = OpenAIChatCompletionClient(
            model="gemini-2.5-flash",
            api_key="",
    )

    response = await AssistantAgent(
            name="Agent",
            model_client=model_client,
            model_client_stream=True,
            reflect_on_tool_use=True,
            tools=tools,
            max_tool_iterations=10,
            system_message= "You are an assistant with some tools that can be used to answer some questions",
        ).on_messages([TextMessage(content="What is current time of Paris now? And what is stock price of MSFT", source="user")], CancellationToken())

    print(response)



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

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.6.4

Other library version.

No response

Model used

gemini-2.5-flash

Model provider

Google Gemini

Other model provider

No response

Python version

3.11

.NET version

None

Operating system

Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions