Skip to content

Realtime Handoff is_enabled doesn't work with callable #1860

@mcbortolozzo

Description

@mcbortolozzo

Describe the bug

Passing a callable to the is_enabled to a Handoff of a Realtime Agent doesn't work because RealtimeAgent is not properly imported to the realtime handoffs file.

    async def _is_enabled(ctx: RunContextWrapper[Any], agent_base: AgentBase[Any]) -> bool:
        assert callable(is_enabled), "is_enabled must be non-null here"
>       assert isinstance(agent_base, RealtimeAgent), "Can't handoff to a non-RealtimeAgent"
                                      ^^^^^^^^^^^^^
E       NameError: name 'RealtimeAgent' is not defined

src/agents/realtime/handoffs.py:151: NameError

Debug information

  • Agents SDK version: main branch
  • Python 3.11

Repro steps

Remove the following lines from this test, which are forcing it to pass. This is the same issue that occurs when attempting to run the realtime handoff with a callable in a real application.

# Patch missing symbol in module to satisfy isinstance in closure
import agents.realtime.handoffs as rh
if not hasattr(rh, "RealtimeAgent"):
from agents.realtime import RealtimeAgent as _RT
rh.RealtimeAgent = _RT # type: ignore[attr-defined]

Expected behavior

The Handoff should work as expected with a callable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions