Skip to content

Realtime Tools cause agent response to cut off #2971

@aligokalppeker

Description

@aligokalppeker

Describe the bug

In Agent SDK, when a tool is registered to a RealtimeAgent, the tool's execution triggers a "create.response" event. That trigger mostly works correctly. But when there is a response in progress, the tool originated "create.response" event causes a cut-off with a RealtimeError.

RealtimeError(message='Conversation already has an active response in progress: resp_DUvxzRrEe3YZSdwIqBdVn. Wait until the response is finished before creating a new one.', type='invalid_request_error', code='conversation_already_has_active_response', event_id=None, param=None)

This causes the agent to get stuck and wait for the customer request to respond.

When a tool is called in the agent, the following is the path that results in the agent response for v0.13.0:

agents.realtime.session.RealtimeSession._enqueue_tool_call_task
agents.realtime.session.RealtimeSession._handle_tool_call
agents.realtime.openai_realtime.OpenAIRealtimeWebSocketModel.send_event
agents.realtime.openai_realtime.OpenAIRealtimeWebSocketModel._send_tool_output

As there are limitless scenarios that can cause this, it primarily happens within the following case;

  • Async tools calls, where outputs are produced simultaneously.
  • When "create.response" is triggered outside the agent, and then the agent runs the tool

This process is improved with v0.13.1, but edge cases seem to exist.

Debug information

  • Agents SDK version in production: v0.14.2
  • Python version: Python 3.11

Repro steps

Trigger multiple tools in an async fashion where each one generates an output.

Expected behavior

Tool-triggered "create.response" messages should be scheduled to occur after the response is completed if a response is in progress.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions