Can you have multiple agents in a room at once?
# ask-ai
r
Can you have multiple agents in a room at once?
t
Thanks for reaching out, Trevor. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, multiple agents can join a LiveKit room simultaneously! This is made possible through the agent dispatch system, which lets you assign several agents to the same room, either automatically or manually. To make sure agents can interact with each other smoothly, you'll want to adjust the room settings to enable agent-to-agent communication. You can do this by setting
agents_allowed=True
in the
RoomInputOptions
or by specifying
participant_kinds = [rtc.ParticipantKind.PARTICIPANT_KIND_AGENT]
. This setup helps ensure that agents can easily detect and respond to one another within the room. Sources: Sources/LiveKit/Types/RoomConfiguration.swift | How to Enable Agent-to-Agent Speech Detection in LiveKit | Knowledge Base Content | livekit/livekit_composite | DeepWiki | test/agent_test.go | Agent dispatch | LiveKit Docs
r
can you share an example?
t
I'd love to share an example that shows how to configure multiple agents in a LiveKit room—it’s pretty straightforward and really helpful! Explicit Agent Dispatch in Room Configuration:
Copy code
from livekit import api
from livekit.proto import RoomConfiguration, RoomAgentDispatch

token = api.AccessToken("api-key", "secret-key")
token.identity = "participant-identity"
token.add_grant(api.VideoGrant(room="my-room", room_join=True))

# Dispatch multiple agents
token.room_config = RoomConfiguration(
    agents=[
        RoomAgentDispatch(agent_name="transcriber-agent", metadata="{}"),
        RoomAgentDispatch(agent_name="summarizer-agent", metadata="{}"),
    ]
)

jwt_token = token.to_jwt()  # Use this token when joining the room
With this setup, both
transcriber-agent
and
summarizer-agent
will automatically connect to the room as soon as the participant joins. It’s a neat way to make sure everything’s ready to go! If you have any questions or want me to walk you through more examples, just let me know—I’m here to help! Sources: Authentication & Token Management | livekit/livekit_composite | DeepWiki | README.md | Building Multi-Agent Architectures with LiveKit Agents | Knowledge Base Content | livekit/livekit_composite | DeepWiki | Agent dispatch | LiveKit Docs
r
how does agent-to-agent communication work?
t
Agent-to-agent communication in LiveKit can be achieved through several helpful mechanisms that make collaboration smooth and effective: 1. Speech-Based Communication: To enable real-time spoken conversations between agents, you can configure
RoomInputOptions
to include agent participants:
RoomInputOptions.participant_kinds = [rtc.ParticipantKind.PARTICIPANT_KIND_AGENT]
This setup allows agents to hear and respond to each other naturally, especially when text-to-speech (TTS) is configured properly. It’s a great way to have seamless two-way conversations. 2. Task Delegation: Agents can use the
function_tool
to call functions on other agents or transfer control. For example, an intake agent can collect user info and then pass it to a specialist agent for more detailed assistance. This helps keep things organized and efficient. 3. Data and Control Communication: Agents can exchange data messages and control signals through LiveKit’s data channels. This includes: 4. Context Sharing: Using the
UserData
class, agents can share important context like user details during handoffs. This ensures interactions stay stateless and scalable, making the process even more reliable. These wonderful tools work together to support complex workflows and help agents collaborate in real-time. If you’d like, I’m here to provide more details or examples—just let me know! Sources: How to Enable Agent-to-Agent Speech Detection in LiveKit | Building Multi-Agent Architectures with LiveKit Agents | README.md | complex-agents/note-taking-assistant/README.md | AI Agents Framework | livekit/livekit_composite | DeepWiki
r
I have 2 specialist agents that need to pass back and forth to each other. the prompt is too big to add more logic for handoff. how can i workaround this
t
Handling large prompts during agent handoffs can feel a bit tricky, but don’t worry—I’m here to guide you through some helpful techniques that make this process smoother by passing only the essential information between agents. Let’s explore a few strategies together: 1. Pass Context Between Agents: When you’re handing off to another agent, it’s a great idea to pass the
chat_ctx
(chat context) along. This way, the new agent gets the conversation history without needing to resend those large prompts. For example:
Copy code
return TechnicalSupportAgent(chat_ctx=self.session.chat_ctx)
2. Truncate and Filter Context: You can keep things neat by truncating the context to only the most relevant messages. Here’s how you might do that in JavaScript:
Copy code
const truncatedChatCtx = userdata.prevAgent.chatCtx
  .copy({
    excludeInstructions: true,
    excludeFunctionCall: false,
  })
  .truncate(6);
This approach keeps just the last 6 messages and skips any unnecessary instructions. 3. Deduplicate Context: To prevent sending duplicate messages, you can add some deduplication logic like this:
Copy code
const existingIds = new Set(chatCtx.items.map((item) => item.id));
const newItems = truncatedChatCtx.items.filter((item) => !existingIds.has(item.id));
chatCtx.items.push(...newItems);
4. Summarize Context: Another helpful tip is to summarize the conversation history and include that summary in the new agent’s instructions. This reduces redundancy nicely:
Copy code
chat_ctx.add_message(
    role="system",
    content=f"You are the {agent_name}. {userdata.summarize()}"
)
By using these methods, you can keep your handoffs efficient while maintaining a smooth and continuous conversation. If any part feels unclear or you’d like more examples, just let me know—I’m happy to help! Sources: Workflows | LiveKit docs | examples/src/restaurant_agent.ts | complex-agents/medical_office_triage/README.md | Live Conversations with AI using ChatGPT and WebRTC | AI-Powered Change Summarization | livekit/livekit_composite | DeepWiki