openai/openai-agents-python

intermittent tool not found error after agent handoff

Closed this issue · 4 comments

Describe the bug

I am seeing a Tool not found exception after the agent handoff intermittently.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/arklex/env/agents/openai_realtime_agent.py", line 413, in receive_events
    async for event in self.session:
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/session.py", line 162, in __aiter__
    raise self._stored_exception
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/openai_realtime.py", line 244, in _listen_for_messages
    await self._handle_ws_event(parsed)
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/openai_realtime.py", line 584, in _handle_ws_event
    await self._handle_output_item(parsed.item)
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/openai_realtime.py", line 442, in _handle_output_item
    await self._emit_event(
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/openai_realtime.py", line 235, in _emit_event
    await listener.on_event(event)
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/session.py", line 204, in on_event
    await self._handle_tool_call(event)
  File "/usr/local/lib/python3.10/site-packages/agents/realtime/session.py", line 451, in _handle_tool_call
    raise ModelBehaviorError(f"Tool {event.name} not found")
agents.exceptions.ModelBehaviorError: Tool getProductCategories not found

The events fire before the exception -

Error in receive_events: Tool getProductCategories not found
agent_start: SalesAgent
audio_interrupted
agent_end: SalesAgent
raw_model_event audio_delta
agent_start: SalesAgent
agent_end: SalesAgent
handoff: AuthAgent -> SalesAgent

Wondering if anyone has seen this behavior before.

Debug information

  • Agents SDK version: 0.2.10
  • Python version: Python 3.10

Repro steps

This issue is hard to reproduce as its happening intermittently.

  1. Have two agents with their own set of tools
  2. Get to the agent handover
  3. Request a tool call
  4. The exception should be thrown

Expected behavior

Tool call to succeed without throwing an exception

Just realized that my tool was named GetProductCategories not getProductCategories. So this issue is due to the model generating a wrong tool call name.

Wondering if there is a good way to gracefully retry in such case

This usually does not occur. If you could share a bit more details such as minimal working code that reproduces the error, it'd be helpful for us to check further.

This issue is stale because it has been open for 7 days with no activity.

This issue was closed because it has been inactive for 3 days since being marked as stale.