This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Timothy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Great question! You don’t need to take down your agent deployed on LiveKit Cloud to spin up a local agent for testing. LiveKit’s system is designed to support multiple workers at the same time, so your local agent can happily run alongside your cloud-deployed agent. When you run a local agent in development mode, it simply registers as an additional worker alongside your cloud agent. The server will then notify one of the registered workers about a new job, and if that worker doesn’t accept, the job will be passed on to another available worker. This way, everything keeps running smoothly! For testing, you can run your local agent in development mode using:
Copy code
python myagent.py dev
This mode is really handy because it enables hot reloading, letting you test changes locally while your production agent keeps running. It’s a great way to develop and test without any interruptions to your service. Sources: TEMPLATE.md | README.md | README.md
b
I only want to test changes on my local agent. The versions are not the same
t
To help you test changes on your local agent without impacting your cloud-deployed agent, a great approach is to keep things separate by using different LiveKit projects or instances for development and production. This way, your local agent connects to its own environment, keeping your production setup safe and sound. Here are some friendly steps to get you started: • Use separate LiveKit projects: You can create a new project in LiveKit just for testing. Each project comes with its own unique credentials (URL, API key, and secret), so they won’t mix. • Configure environment variables: It’s helpful to set up different environment files for development and production. For example:
Copy code
# Development Environment (.env.dev)
LIVEKIT_URL=wss://your-dev-project.livekit.cloud
LIVEKIT_API_KEY=your_dev_api_key
LIVEKIT_API_SECRET=your_dev_api_secret
• Run your local agent in development mode: Simply start your agent locally with this command:
Copy code
python myagent.py dev
• Test in a sandbox environment: You can also use the LiveKit dashboard’s sandbox section to safely test your agent with the same project credentials, without touching production. If you'd like, I’m here to walk you through setting up a separate LiveKit project or configuring your environment for isolated testing—just let me know!
b
How can I hardcode the identity of the agent?
t
I'm happy to help you hardcode the identity of an agent in LiveKit! There are a few ways to do this depending on what fits your needs best: • Worker Pattern: You can set the identity right when accepting job requests in your worker. Here's a simple example:
Copy code
async def job_request_cb(job_request: agents.JobRequest):
    await job_request.accept(
        TextStreamingAgent.create,
        identity="text-streaming-agent",
        name="Text Streaming Agent",
    )
• Agent Dispatch: If you want more explicit control over which agents join specific rooms, using named agents works great. For example:
Copy code
dispatch = await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="test-agent", 
        room=room_name, 
        metadata="my_metadata"
    )
)
• Access Tokens: Another way is setting the identity through access tokens, which is especially useful for avatar sessions or participant-specific setups:
Copy code
token = api.AccessToken(api_key, api_secret)
    .with_identity("identity")
    .with_grants(api.VideoGrants(room_join=True, room="my-room"))
    .to_jwt()
• CLI Configuration: And if you're working with CLI-based deployments, you can configure the identity in a TOML file like this:
Copy code
[agent]
id = "AG_xxxxxxxxxxxxx"
If you'd like, I can walk you through any of these methods in more detail—just let me know which one sounds best for you! Sources: server/agent.py | examples/agent_dispatch.py | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | ivr-nagivator/flask_livekit/extension.py | examples/other/transcription/multi-user-transcriber.py
b
I use the access token option but the identity printed on the agent is
agent-<some-random-string?
t
Thanks for reaching out! The identity pattern
agent-<random-string>
happens because LiveKit wants to make sure every participant in a room has a unique identity. So, if multiple agents try to join with the same identity (like "agent"), LiveKit kindly adds a random string to keep things unique and avoid any mix-ups. If you'd like to have more control over the identities and prevent this from happening, here are a couple of friendly tips: • Generate unique identities: Try creating a unique identifier for each agent instance before you generate the access token. • Set the identity explicitly: When you create the access token, you can specify a unique identity for the agent. Here's a little example:
Copy code
token = api.AccessToken(api_key, api_secret)
    .with_identity("my-unique-agent")
    .with_grants(api.VideoGrants(room_join=True, room="my-room"))
    .to_jwt()
If you’d like, I’m here to help you step-by-step with implementing this—just let me know! Sources: livekit-agents/livekit/agents/inference/_utils.py | Rooms, participants, and tracks | LiveKit Docs | plugins/anam/src/avatar.ts | src/pages/api/token.ts | app/api/connection-details/route.ts
b
How can Iist all participants in a room
t
To help you list all participants in a room, you can use the Room Service API's
ListParticipants
method. Here’s a friendly example using the Python SDK:
Copy code
from livekit import api
from livekit.protocol import room as room_proto

# Initialize the LiveKit API
lkapi = api.LiveKitAPI()

# Create the request
list_request = room_proto.ListParticipantsRequest(room="your-room-name")

# List participants
participants_response = await lkapi.room.list_participants(list_request)

# Access the participants
for participant in participants_response.participants:
    print(f"Identity: {participant.identity}")
    print(f"Name: {participant.name}")
    print(f"State: {participant.state}")
    print(f"Joined at: {participant.joined_at}")
    print(f"Metadata: {participant.metadata}")
    print(f"SID: {participant.sid}")
Just a quick note: this method needs
room_admin
permission, so please make sure your API token has the right grants. If you’d like, I’m here to help you with any part of this—just let me know! Sources: livekit-api/livekit/api/room_service.py | mcp/server.py | livekit-api/src/services/room.rs | Managing participants | LiveKit Docs
b
I don't see the agent as a participant
How can I get the identity of the agent when I join the room? Here is my code:
Copy code
jwt_token = token.to_jwt()
    room = rtc.Room()
    await room.connect(LIVEKIT_URL, jwt_token)
    print(f"Connected to LiveKit room: {ROOM_NAME}")

    lkapi = api.LiveKitAPI(LIVEKIT_URL, API_KEY, API_SECRET)

    # Create the request
    list_request = room_proto.ListParticipantsRequest(room=ROOM_NAME)

    # List participants
    participants_response = await lkapi.room.list_participants(list_request)
t
Hi there! To help you find the identity of your agent when it joins a room, you can easily retrieve it either from the job context or from the room's local participant. Let me walk you through both options: • Using Job Context:
Copy code
from livekit.agents import get_job_context

# Get the agent's identity from the job context
job_ctx = get_job_context()
agent_identity = job_ctx.token_claims().identity
print(f"Agent identity: {agent_identity}")
• Using the Room's Local Participant:
Copy code
# Fallback method using the room's local participant
agent_identity = room.local_participant.identity
print(f"Agent identity: {agent_identity}")
Also, if you want to keep an eye on everyone joining the room and spot agents specifically, you can check their
kind
field like this:
Copy code
async def on_participant_join(job_ctx, participant):
    print(f"Participant joined: {participant.identity}")
    if participant.kind == ParticipantKind.AGENT:
        print(f"Agent joined with identity: {participant.identity}")
If you'd like, I’m here to help you with the next steps or any other questions you might have. Just let me know! Sources: livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/avatar.py | Job lifecycle | LiveKit Docs | Core Platform Architecture & Authentication | livekit/livekit_composite | D... | agents/src/job.ts | Rooms, participants, and tracks | LiveKit Docs
b
This is my "client" side code
I need to know what the agent's identity is
t
I'd love to help you retrieve the agent's identity from the client side! To make sure I guide you in the best way, could you please share a bit more: • Which frontend framework or SDK are you working with (like React, vanilla JavaScript, or a mobile SDK)? • Are you trying to identify a specific type of agent, or just any agent in the room? • Do you want to differentiate between multiple agents, or simply know when an agent is present?