jolly-eve-3916
08/15/2025, 2:23 AMtall-airline-16756
08/15/2025, 2:23 AMtall-airline-16756
08/15/2025, 2:24 AMAgentSession
in LiveKit using the Python SDK with livekit-agents
, here’s a friendly step-by-step guide to help you out:
1. Wait for Participant Metadata: Use ctx.wait_for_participant()
to make sure the participant is connected and their metadata is ready before you create the session. Then, parse that metadata into a nice, structured configuration.
2. Create the AgentSession: With your parsed config in hand, you can initialize the AgentSession
. Here’s a quick example:
session = AgentSession(
stt=deepgram.STT(
endpointing_ms=config.endpointing_ms,
# ...
),
min_endpointing_delay=config.min_endpointing_delay,
)
1. Listen for Metadata Changes: Keep an ear out for the participant_metadata_changed
event so you can update the session on-the-fly if the metadata changes after the session is up and running.
@ctx.room.on("participant_metadata_changed")
def on_metadata_changed(old_metadata, participant):
new_metadata = json.loads(participant.metadata)
new_config = parse_session_config(new_metadata)
session.session_update(
endpointing_ms=new_config.endpointing_ms,
min_endpointing_delay=new_config.min_endpointing_delay
)
By patiently waiting for the participant metadata and staying tuned for any changes, you’ll keep your session perfectly in sync and configured just right. Hope this helps!
Sources: agent/main.py | Participant attributes and metadata | LiveKit Docs | External data and RAG | LiveKit Docsjolly-eve-3916
08/15/2025, 2:41 AMtall-airline-16756
08/15/2025, 2:42 AMAgentSession
is created, you can't make dynamic updates to its configuration, like changing the STT settings. The session_update()
method you mentioned isn’t actually part of the core AgentSession
class, and the update_options()
method is currently just a placeholder without any real functionality.
With that in mind, the best way to go about this is to use ctx.wait_for_participant()
to make sure the participant metadata is ready before you create the session. That way, you can set everything up correctly right from the start.
If you have any more questions or want to chat through this further, just let me know—I’m here to help!
Sources: Gladia integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-baseten/livekit/plugins/baseten/stt.py