Can I set up the conversation between my agent and...
# ask-ai
f
Can I set up the conversation between my agent and another agent that simulate human counterpart for integration and concurrency testing?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can set up a conversation between your agent and another agent to simulate a human counterpart for integration and concurrency testing. This is a great way to see how your agents behave, how accurate their responses are, and how well they perform in a controlled setting. To get agent-to-agent communication working, you'll want to configure the
RoomInputOptions
when you start the agent session. Here's a simple example to guide you:
Copy code
await session.start(
    agent=SimpleEvaluationAgent(),
    room=ctx.room,
    room_input_options=RoomInputOptions(
        participant_kinds=[
            rtc.ParticipantKind.PARTICIPANT_KIND_AGENT,
        ]
    ),
)
If you're looking for an easier setup, you can also use
listen_to_agents=True
. This makes sure your agent listens to and processes input from other agents in the room. For the best results, I recommend using isolated rooms for each test, defining clear personas and conversation scripts, and integrating these tests into your CI/CD pipelines. If you'd like, there's a full implementation example available in the LiveKit agents repository that you might find really helpful. Sources: How to test your agent using another agent | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | docs/index.yaml | README.md
f
Provide code example to add 2 agents to the same room
t
I'm happy to walk you through an example of how to add two agents to the same room in LiveKit. Let's take a look: Python Example:
Copy code
from livekit.api import AccessToken, VideoGrants, RoomConfiguration, RoomAgentDispatch

# Create an access token
api_key = "your-api-key"
api_secret = "your-api-secret"
token = AccessToken(api_key=api_key, api_secret=api_secret)
token.identity = "participant-identity"
token.add_grant(VideoGrants(room_join=True, room="my-room"))

# Dispatch two agents to the same room
token.with_room_config(
    RoomConfiguration(
        agents=[
            RoomAgentDispatch(agent_name="conversation-agent", metadata="agent1-data"),
            RoomAgentDispatch(agent_name="moderator-agent", metadata="agent2-data"),
        ]
    )
)

# Generate the token
jwt_token = token.to_jwt()
print("Token:", jwt_token)
When you use this token to join the room, both agents will be dispatched automatically. Pretty neat, right? Node.js Example:
Copy code
import { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
import { AccessToken } from 'livekit-server-sdk';

const at = new AccessToken();
at.identity = 'my-participant';
at.addGrant({ roomJoin: true, room: 'my-room' });

at.roomConfig = new RoomConfiguration({
  agents: [
    new RoomAgentDispatch({
      agentName: "conversation-agent",
      metadata: "agent1-data"
    }),
    new RoomAgentDispatch({
      agentName: "moderator-agent", 
      metadata: "agent2-data"
    })
  ]
});

const token = await at.toJwt();
console.log("Token:", token);
If you're interested in more advanced setups, you can also use the Agent Dispatch API to explicitly dispatch agents after the room is created. Feel free to reach out if you'd like me to guide you through that or if you have any other questions. I'm here to help! Sources: Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | How to Enable Agent-to-Agent Speech Detection in LiveKit | Job lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs | Authentication | LiveKit Docs
f
provide example within entrypoint function for LiveKit Agents
t
I'd love to walk you through an example of how to add two agents to the same room using an entrypoint function for LiveKit Agents. Here's a sample code snippet for you:
Copy code
from livekit.agents import (
    Agent,
    AgentSession,
    JobContext,
    WorkerOptions,
    cli,
)
from livekit.plugins import deepgram, openai, silero

# Agent 1 - Conversation Handler
async def conversation_agent_entrypoint(ctx: JobContext):
    await ctx.connect()

    agent = Agent(
        instructions="You are a helpful conversation assistant.",
    )
    session = AgentSession(
        vad=silero.VAD.load(),
        stt=deepgram.STT(model="nova-3"),
        llm=openai.LLM(model="gpt-4o-mini"),
        tts=openai.TTS(voice="echo"),
    )

    await session.start(agent=agent, room=ctx.room)

# Agent 2 - Moderator
async def moderator_agent_entrypoint(ctx: JobContext):
    await ctx.connect()

    agent = Agent(
        instructions="You are a room moderator. Monitor conversations and provide guidance.",
    )
    session = AgentSession(
        vad=silero.VAD.load(),
        stt=deepgram.STT(model="nova-3"),
        llm=openai.LLM(model="gpt-4o-mini"),
        tts=openai.TTS(voice="nova"),
    )

    await session.start(agent=agent, room=ctx.room)

# Register Agent 1
if __name__ == "__main__":
    cli.run_app(WorkerOptions(
        entrypoint_fnc=conversation_agent_entrypoint,
        agent_name="conversation-agent"  # Unique agent name
    ))

# Register Agent 2 (run separately)
if __name__ == "__main__":
    cli.run_app(WorkerOptions(
        entrypoint_fnc=moderator_agent_entrypoint,
        agent_name="moderator-agent"  # Unique agent name
    ))
Each agent is set up with its own entrypoint function and a unique name, which helps keep things organized. You can run these agents in separate processes, and they’ll connect to the same room seamlessly. If anything feels unclear or if you'd like me to provide more examples, please don’t hesitate to ask—I’m here to help!