how to make 2 agents talk to each other after bein...
# ask-ai
b
how to make 2 agents talk to each other after being dispatched to the same room?
t
Thanks for reaching out, mateuszkasprowicz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! To help two agents communicate smoothly within the same room, you'll want to set up the
RoomInputOptions
just right. By default, agents don't listen to each other unless we explicitly configure it. No worries though—here are two friendly ways you can make this happen: • Option 1: Use
listen_to_agents=True
Simply set the
listen_to_agents
flag to
True
when you're defining
RoomInputOptions
. Here's a quick example:
Copy code
room_io = RoomIO(
    session,
    room=ctx.room,
    input_options=RoomInputOptions(
        listen_to_agents=True
    )
)
• Option 2: Use
participant_kinds
with
PARTICIPANT_KIND_AGENT
Another way is to explicitly include
PARTICIPANT_KIND_AGENT
in the
participant_kinds
list. Check out this example:
Copy code
room_io = RoomIO(
    session,
    room=ctx.room,
    input_options=RoomInputOptions(
        participant_kinds=[rtc.ParticipantKind.PARTICIPANT_KIND_AGENT]
    )
)
Both of these methods work beautifully to let agents detect and chat with each other. Just make sure both agents are connected to the same room and that Text-to-Speech (TTS) is set up if you want vocal responses. If you need any more help, feel free to ask—we’re here for you! Sources: Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | agents/src/voice/room_io/room_io.ts | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | How to Enable Agent-to-Agent Speech Detection in LiveKit | livekit-agents/livekit/agents/voice/room_io/room_io.py
b
there's no argument called listen_to_agents
t
Hi there! It looks like the
listen_to_agents
argument isn’t available in the current version of
RoomInputOptions
. But don’t worry—you can still enable agent-to-agent communication by using the
participant_kinds
argument. This lets you specify which types of participants the agent should listen to. Here’s a friendly example of how you can set it up:
Copy code
room_io = RoomIO(
    session,
    room=ctx.room,
    input_options=RoomInputOptions(
        participant_kinds=[rtc.ParticipantKind.PARTICIPANT_KIND_AGENT]
    )
)
This way, agents are clearly included as participants that can be detected and interacted with. If you have any questions or want me to walk you through it further, just let me know—I’m here to help! Sources: examples/voice_agents/realtime_joke_teller.py
b
lk room participants list test-room-27990ec2-3274-4ffd-8f03-ac2614c72f21 Using default project [golearn-test-mk] agent-AJ_ofiDzpB7zc54 (ACTIVE) tracks: 0 agent-AJ_746gYZ6Z74Am (ACTIVE) tracks: 0 it shows no tracks after they are connected in the room - why?
t
I'm sorry to hear you're experiencing issues with agents not showing tracks after connecting to a room. Let's walk through some key points together to help resolve this: 1. Agent Initialization: First, please check that the agents have fully initialized and moved into active states like "speaking" or "listening." Sometimes, tracks won’t show up if the agents are still stuck in the "connecting" state. 2. Track Publishing: Make sure the agents are actually publishing their audio or video tracks once they join the room. Without this, the tracks won’t be visible. 3. Subscription Logic: It’s important that the client or other participants are subscribing to the agents' tracks. You can use hooks like
useTracks()
or listen for
TrackSubscribed
events to confirm subscriptions are working properly. 4. Dispatch Timing: If multiple agents are dispatched at the same time, there might be a slight delay before tracks appear. Adding retry logic or polling can help wait for the tracks to become available. 5. Reconnection Handling: In case agents reconnect, please ensure they republish their tracks and that subscriptions are re-established accordingly. Please don’t hesitate to reach out if you’d like me to walk you through any of these steps in more detail or provide specific code examples. I’m here to help! Sources: Sources/LiveKit/Core/Room+EngineDelegate.swift | src/components/playground/Playground.tsx | complex-agents/ivr-agent/ivr-agent-frontend/src/App.tsx | Web and mobile frontends | LiveKit Docs | Building voice agents | LiveKit Docs