famous-finland-27043
11/01/2025, 4:34 AMtall-airline-16756
11/01/2025, 4:34 AMtall-airline-16756
11/01/2025, 4:35 AMautoSubscribe option is enabled (which it is by default).
This way, your participants can communicate smoothly without any special agent setup. If you have any questions or need a hand with any step, just let me know—I’m here to help!
Sources: examples/rpc/README.md | lib/src/options.dart | test/agent_test.go | How to Enable Agent-to-Agent Speech Detection in LiveKitfamous-finland-27043
11/01/2025, 4:39 AMtall-airline-16756
11/01/2025, 4:40 AMRoomConfiguration only if the situation calls for it. For instance, you could check the user role or room metadata before deciding to add the agent to the configuration.
2. Explicit Dispatch via API: Another way is to turn off automatic agent dispatch in your worker setup by setting auto_register=False. Then, you can use the CreateAgentDispatchRequest API to dispatch the agent programmatically, based on what's happening in real time—like participant behavior or other triggers.
With either method, the agent will only join the room when you want them to. If you'd like, I’m here to help with code examples or to clarify anything further—just let me know!
Sources: SIP dispatch rule | LiveKit Docs | Sources/LiveKit/Types/RoomConfiguration.swift | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | pkg/loadtester/agentloadtester.go | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik...famous-finland-27043
11/01/2025, 4:44 AMtall-airline-16756
11/01/2025, 4:45 AMfrom livekit import AccessToken, VideoGrant
import os
def generate_token(identity, room_name, interview_type):
# Create an access token with the necessary permissions
token = AccessToken(
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET")
)
# Add identity and room permissions
token.identity = identity
token.add_grant(VideoGrant(room=room_name))
# Add metadata to include the interview type
token.metadata = f"{{'interview_type': '{interview_type}'}}"
return token.to_jwt()
if __name__ == "__main__":
# Example usage
room_name = "example-room"
identity = "participant-1"
interview_type = "technical" # Set the interview type here
# Generate the token with metadata
token = generate_token(identity, room_name, interview_type)
# Use the token in your application logic
print(f"Generated token: {token}")
# Example: Pass the token to your agent logic
if interview_type == "technical":
agents.cli.run_app(
agents.WorkerOptions(entrypoint_fnc=entrypoint, agent_name="interview-agent")
)
else:
print("No agent required for this type of session.")
I hope this helps clarify how to include the interview type in the token metadata! The main function then uses this information to decide whether to dispatch the agent. If you have any questions or want to explore this further, please don’t hesitate to ask—I’m here to help!famous-finland-27043
11/01/2025, 4:46 AMtall-airline-16756
11/01/2025, 4:46 AMfrom livekit import AccessToken, VideoGrant
from flask import Flask, request, jsonify
import os
app = Flask(__name__)
@app.route('/token', methods=['POST'])
def generate_token():
data = request.json
identity = data.get('identity')
room_name = data.get('roomName')
# Create an access token
token = AccessToken(
api_key=os.getenv('LIVEKIT_API_KEY'),
api_secret=os.getenv('LIVEKIT_API_SECRET'),
identity=identity
)
# Add room permissions and metadata
token.add_grant(VideoGrant(room=room_name, room_join=True, can_publish=True, can_subscribe=True))
token.metadata = f"{{'interview_type': '{data.get('interviewType', 'default')}'}}"
return jsonify({'token': token.to_jwt()})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
Here’s a quick overview:
• Your backend offers a /token endpoint that takes in identity, roomName, and interviewType.
• The token we generate includes some handy metadata like interview_type, and it's sent back to your client.
On the client side, you just call this endpoint to get your token and connect to the LiveKit room smoothly. If you hit any bumps or want to dive deeper, just let me know—I’m here to help!
Sources: Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | README.md | lib/services/token_service.dart | Generating tokens | LiveKit docs | app/src/main/java/io/livekit/android/example/voiceassistant/TokenExt.ktfamous-finland-27043
11/01/2025, 4:48 AMtall-airline-16756
11/01/2025, 4:48 AMRoomConfiguration. Here's a friendly example to help you get started:
from livekit import AccessToken, VideoGrant, RoomConfiguration, RoomAgentDispatch
import os
import json
def generate_token_with_agent(identity, room_name, interview_type):
# Create an access token
token = AccessToken(
api_key=os.getenv('LIVEKIT_API_KEY'),
api_secret=os.getenv('LIVEKIT_API_SECRET'),
identity=identity
)
# Add room permissions
token.add_grant(VideoGrant(room=room_name, room_join=True, can_publish=True, can_subscribe=True))
# Conditionally add agent dispatch based on interview type
if interview_type == "technical":
token.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="interview-agent",
metadata=json.dumps({"interview_type": interview_type})
)
]
)
)
return token.to_jwt()
if __name__ == "__main__":
# Example usage
room_name = "example-room"
identity = "participant-1"
interview_type = "technical" # Set the interview type here
# Generate the token with conditional agent dispatch
token = generate_token_with_agent(identity, room_name, interview_type)
print(f"Generated token: {token}")
Here’s what’s happening in this example:
• The RoomConfiguration includes an agent dispatch only when the interview_type matches the condition (like "technical").
• The metadata field carries structured JSON data that the agent can use to tailor its behavior during execution.
On the agent side, you can easily access this metadata inside the entrypoint function to customize how the agent responds:
def entrypoint(job):
metadata = json.loads(job.metadata or "{}")
interview_type = metadata.get("interview_type")
if interview_type == "technical":
# Initialize technical interview logic
pass
else:
# Handle other cases
pass
This approach ensures your agent is dispatched only when the conditions you set in the token generation are met. If anything feels unclear or if you want to dive deeper into any part, please don’t hesitate to ask—I’m here to help!
Sources: packages/livekit-server-sdk/src/AgentDispatchClient.ts | examples/agent_dispatch.py | Agent dispatch | LiveKit Docs | Authentication | LiveKit Docs | Job lifecycle | LiveKit Docsfamous-finland-27043
11/01/2025, 7:08 AMtall-airline-16756
11/01/2025, 7:09 AMagent_name in your worker setup. This way, your agent won’t auto-connect to any room unless you explicitly dispatch it. Let’s walk through the steps together:
1. Disable Auto Dispatch by Naming the Agent
In your LiveKit worker code, you can set the agent_name within the WorkerOptions like this:
from livekit.agents import Worker
worker = Worker(
worker_name="my-named-agent", # Assign a specific name to the agent
auto_register=False # Optional: Prevent auto-registration
)
By giving your agent a unique agent_name, it won’t auto-connect to any rooms and will only join when you dispatch it explicitly.
2. Dispatch Agent via Token Configuration
When you generate the participant’s access token, you can include the agent dispatch details inside the RoomConfiguration. Here’s an example:
from livekit import AccessToken, VideoGrant, RoomConfiguration, RoomAgentDispatch
import os
import json
def generate_token_with_agent(identity, room_name, interview_type):
token = AccessToken(
api_key=os.getenv('LIVEKIT_API_KEY'),
api_secret=os.getenv('LIVEKIT_API_SECRET'),
identity=identity
)
token.add_grant(VideoGrant(room=room_name, room_join=True, can_publish=True, can_subscribe=True))
if interview_type == "technical":
token.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="my-named-agent",
metadata=json.dumps({"interview_type": interview_type})
)
]
)
)
return token.to_jwt()
In this snippet, the agent will only be dispatched if the interview_type matches your condition, like "technical". This gives you great control over when agents join.
3. Verify Agent Dispatch
Lastly, make sure your agent service is up and running with the same agent_name. If you want, you can also use the LiveKit API to list or debug dispatches to confirm everything is working smoothly.
If you have any questions or need a hand with any of these steps, please don’t hesitate to reach out. I’m here to help!
Sources: livekit-api/livekit/api/agent_dispatch_service.py | SIP dispatch rule | LiveKit Docs | Agent dispatch | LiveKit Docs | Agents telephony integration | LiveKit Docs | Authentication | LiveKit Docsfamous-finland-27043
11/01/2025, 7:12 AMtall-airline-16756
11/01/2025, 7:13 AMagent_name
In your agent worker setup, you’ll want to assign a specific agent_name in the WorkerOptions. This simple step disables automatic dispatch for that agent:
from livekit.agents import Worker
worker = Worker(
opts=WorkerOptions(
agent_name="my-agent", # Disables automatic dispatch
entrypoint_fnc=agent_entrypoint
)
)
Just a heads-up: agents without an agent_name are automatically dispatched, so this part is really important.
2. Avoid Including agents in Room Configuration
When you generate access tokens, make sure the roomConfig doesn’t include any agents unless you actually want them dispatched:
from livekit import AccessToken, VideoGrant
def generate_token(identity, room_name):
token = AccessToken(
api_key="your_api_key",
api_secret="your_api_secret",
identity=identity
)
token.add_grant(VideoGrant(room=room_name, room_join=True, can_publish=True, can_subscribe=True))
return token.to_jwt()
3. Do Not Use the Agent Dispatch API
Also, please double-check that there are no explicit dispatch calls made via the AgentDispatchService API. For example, avoid doing this:
# Example of dispatch API call to avoid
agentDispatchClient.createDispatch("room-name", "agent-name", metadata={})
4. Verify No Active Dispatches
Finally, you can use the listDispatch method to confirm that no agents are currently dispatched to a room:
dispatches = agentDispatchClient.listDispatch("room-name")
if dispatches:
print("Agents are dispatched:", dispatches)
By following these steps, you’ll have full control so agents only join rooms when you explicitly want them to. If anything feels unclear or you want to dive deeper into any part, just let me know—I’m here to help!
Sources: Agents telephony integration | LiveKit Docs | Agent dispatch | LiveKit Docs | livekit-agents/livekit/agents/worker.py | packages/livekit-server-sdk/src/AgentDispatchClient.ts | livekit-api/livekit/api/agent_dispatch_service.pyfamous-finland-27043
11/01/2025, 7:15 AMtall-airline-16756
11/01/2025, 7:15 AMagent_name in the worker configuration is a great way to make sure the agent won't auto-dispatch to any room unless it's specifically requested. So, if the agent_name doesn’t match any dispatch request (like through room configuration or API), the agent simply won’t join the room.
Also, when you include an agent dispatch in the roomConfig of the access token, it explicitly sends that particular agent to the room, which overrides the usual behavior. This way, only the agent you want will be dispatched based on what’s set in the token.
If you’d like, I’m here to help with any other questions or to walk you through the implementation—just let me know!famous-finland-27043
11/01/2025, 8:17 AMtall-airline-16756
11/01/2025, 8:18 AMreq = api.RoomCompositeEgressRequest(
room_name="my-room",
layout="speaker",
gcp=api.GCPUpload(bucket="my-bucket", credentials="...")
)
egress_info = await lkapi.egress.start_room_composite_egress(req)
This will record all the shared audio and video in the room and save it directly to your cloud storage. Pretty handy, right?
2. Transcription
While LiveKit doesn’t provide built-in transcription without an agent, you can still achieve this by forwarding audio to an external WebSocket server using Track Egress:
track_req = api.TrackEgressRequest(
room_name="my-room",
track_id="audio-track-id",
websocket_url="wss://your-stt-service/ws"
)
await lkapi.egress.start_track_egress(track_req)
Your WebSocket server will then receive the raw audio and can process it with an external speech-to-text service like Whisper or Google STT. This way, you keep things flexible and powerful!
3. Duration Tracking
To keep track of how long your session lasts, you can use the Egress API to get the start and end times:
response = await lkapi.egress.list_egress(ListEgressRequest(room_name="my-room"))
duration = response.egress_info[0].ended_at - response.egress_info[0].started_at
This will give you the session duration based on the egress lifecycle, so you always know exactly how long things ran.
Summary:
• Egress Saving: Fully supported without needing an agent.
• Transcription: Can be done externally via Track Egress and an STT service.
• Duration Tracking: Easily handled through the Egress API.
If you’d like, I’d be more than happy to help you with a complete example that ties all these steps together. Just let me know!
Sources: Session recording and transcripts | LiveKit Docs | egress/recording_agent.py | Universal Egress | livekit-agents/livekit/agents/inference/stt.py | livekit-api/livekit/api/egress_service.pyfamous-finland-27043
11/01/2025, 8:20 AMtall-airline-16756
11/01/2025, 8:21 AMreq = api.RoomCompositeEgressRequest(
room_name="my-room",
layout="speaker",
output=api.S3Upload(bucket="my-bucket", region="us-east-1")
)
res = await lkapi.egress.start_room_composite_egress(req)
This way, all shared audio and video in the room is recorded and saved directly to your cloud storage.
2. Transcription via Agent
You can deploy a LiveKit agent with transcription enabled but without publishing audio. This means the agent listens and transcribes without joining the conversation:
await session.start(
agent=Transcriber(),
room=ctx.room,
room_output_options=RoomOutputOptions(
transcription_enabled=True,
audio_enabled=False,
),
)
The transcriptions are available in real time or can be forwarded to other services as needed.
3. Duration Tracking
The agent can keep track of session duration by noting when participants join and leave. Alternatively, you can use the Egress API to get the start and end times like this:
response = await lkapi.egress.list_egress(ListEgressRequest(room_name="my-room"))
duration = response.egress_info[0].ended_at - response.egress_info[0].started_at
4. Room Cleanup
Don’t forget to delete the room once the session ends to stop recording and tidy up resources.
This setup lets your agent handle all the backend work quietly in the background, without joining the chat. If you have any questions or want help with the implementation, just let me know—I’m here to help!
Sources: Universal Egress | CreateRoom() is Taking Too Long | examples/other/transcription/transcriber.py | Session recording and transcripts | LiveKit Docsfamous-finland-27043
11/01/2025, 8:23 AMtall-airline-16756
11/01/2025, 8:23 AMfrom livekit.agents import Worker, WorkerOptions, Job
from livekit import RoomOutputOptions
import json
# Define the transcriber agent class
class Transcriber:
async def entrypoint(self, job: Job):
# Parse metadata if needed
metadata = json.loads(job.metadata or "{}")
room_name = metadata.get("room_name", "default-room")
# Start the session with transcription enabled but no audio publishing
await job.start(
room=room_name,
room_output_options=RoomOutputOptions(
transcription_enabled=True, # Enable transcription
audio_enabled=False # Disable audio publishing
)
)
# Listen for transcription events
async for event in job.events():
if event.type == "user_input_transcribed":
transcription = event.data.get("text")
print(f"Transcription: {transcription}")
elif event.type == "conversation_item_added":
item = event.data
print(f"Conversation item: {item}")
# Perform cleanup when the session ends
print("Session ended.")
# Configure the worker to run the transcriber agent
if __name__ == "__main__":
worker = Worker(
opts=WorkerOptions(
agent_name="transcriber-agent", # Name of the agent
entrypoint_fnc=Transcriber().entrypoint
)
)
worker.run()
Key Features:
• Transcription: The agent listens for transcription events like user_input_transcribed and logs the transcribed text.
• Non-Participatory: The audio_enabled=False option ensures the agent does not publish audio or participate in the conversation.
• Metadata Handling: The agent can use metadata passed during dispatch to customize its behavior (e.g., room name).
I hope this helps you get started! If you have any questions or need further assistance setting up your LiveKit backend or connecting the agent to the right room, please don’t hesitate to reach out. I’m here to help!famous-finland-27043
11/01/2025, 8:25 AMtall-airline-16756
11/01/2025, 8:25 AMkind field is set to AGENT, which helps everyone tell it apart from regular users. Plus, other participants can identify the agent using the isAgent property, and if you want to, you can filter agents using the agentParticipants property.
If you have any questions or need a hand with managing agent visibility or filtering participants, just let me know—I’m here to help!
Sources: Rooms, participants, and tracks | LiveKit docs | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | Sources/LiveKit/Agent/Room+Agent.swift | src/components/playground/Playground.tsxfamous-finland-27043
11/01/2025, 8:26 AMtall-airline-16756
11/01/2025, 8:27 AMfamous-finland-27043
11/01/2025, 11:54 AM