Skip to content

Gemini 2.5 does not work well with function call #1420

@moseshu

Description

@moseshu

Please read this first

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

Question

Gemini 2.5 does not work well with function call

self.npc_agent = Agent[WorldState](
            name="NPC Agent",
            tools=self.bound_tools,
            model=OpenAIChatCompletionsModel(model="gemini-2.5-pro",
                                             openai_client=gemini_client),
            instructions=npc_instructions,
            hooks=CustomAgentHooks("NPC agent")
        )

response =  Runner.run_streamed(self.npc_agent, input=messages,context=self.world_state)
            #logger.info(f"result:{response.final_output}")
            # 3. Process NPC response
            async for event in response.stream_events():
                logger.info(f"event===:{event}")
                if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
                    yield self._text_yield_stream(text=event.data.delta)
                    #logger.info(f"chunk====:{event.data.delta}")
                elif event.type == "run_item_stream_event":
                    if event.item.type == "tool_call_item":
                        logger.info(f"-- Tool was called:{event.item}")
                    elif event.item.type == "tool_call_output_item":
                        logger.info(f"----\n{event.item.output}\n------")
                    elif event.item.type == "message_output_item":
                        logger.info(f"-- Message output1:\n {ItemHelpers.text_message_output(event.item)}")

user: Hi
logs: 
event===:AgentUpdatedStreamEvent(new_agent=Agent(name='NPC Agent'
 ### (NPC agent) 1: Agent NPC Agent started
event===
....

Message output1:
Maya: Welcome to the NexusTech mixer! I'm Maya, the event host. It's great to see you here
event===:RunItemStreamEvent(name='tool_called', item=ToolCallItem(agent=Agent(name='NPC Agent', handoff_description=None, tools=[FunctionTool(name='record_conversation_start_tool'....
-- Tool was called:ToolCallItem(agent=Agent(name='NPC Agent', handoff_description=None,
### (NPC agent) 2: Agent NPC Agent started tool record_conversation_start_tool
### (NPC agent) 3: Agent NPC Agent ended tool record_conversation_start_tool
event===:RawResponsesStreamEvent(data=ResponseCompletedEvent(response=Response(id='__f....
### (NPC agent) 4: Agent NPC Agent ended


From the log information, the model outputs the result first, then calls the function call, and then ends. Logically, the model result should be output after the tool is executed, but the model does not continue to execute after the tool calls. At the same time, the calling logic is not correct. The tool should be called first and then the Message output.

What's worse is that sometimes the model has no raw_response_event and run_item_stream_event?
Why?Does the Gemini model require any special processing?

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