bright-eye-88478
08/28/2025, 4:13 PMtall-airline-16756
08/28/2025, 4:13 PMtall-airline-16756
08/28/2025, 4:13 PMAgentSession constructor:
session = AgentSession(
min_endpointing_delay=1.0 # Wait 1 second after user stops speaking
)
• Add a Custom Delay in `on_user_turn_completed`: You can also program a delay using asyncio.sleep() inside the on_user_turn_completed callback. Here's how:
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
await asyncio.sleep(1.0) # Add a 1-second delay
self.session.generate_reply(instructions="Respond to the user")
• Manage Initial Speech: For outbound calls, you can have the agent stay quiet at first and only reply after the user starts talking. Just make sure to call generate_reply() only when it’s the right time.
If you want, I’m here to help you set any of these up—just let me know!
Sources: VoicePipelineAgent | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | Agents telephony integration | LiveKit Docsbright-eye-88478
08/28/2025, 4:18 PMtall-airline-16756
08/28/2025, 4:19 PMclass MyAgent(Agent):
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
# Wait for the user to finish their turn
if new_message.text:
# Then respond naturally to what they said
self.session.generate_reply(instructions="Respond naturally to the user.")
So, in this example, the on_user_turn_completed method makes sure the agent waits until the user has finished their turn (we check this with new_message.text) before jumping in with a reply. Feel free to tweak the response logic to fit what you need.
Just give me a shout if you want me to walk you through more details or help customize it further!bright-eye-88478
08/28/2025, 5:05 PMtall-airline-16756
08/28/2025, 5:06 PMsip.callStatus participant attribute. Once the user answers, this changes to active. You can listen for these participant events in the LiveKit room to catch that update.
• Synchronous detection: When you create a SIP participant with the create_sip_participant API, just set wait_until_answered=True. This will pause the call until the user answers or it fails, so you get a clear confirmation right away.
These tips are great for SIP-based outbound calls. If you want me to walk you through more details or give you some examples, just let me know—I’m here to help!
Sources: Making calls using SIP | LiveKit Docs | Making outbound calls | LiveKit Docs | agent.pybright-eye-88478
08/28/2025, 5:39 PMtall-airline-16756
08/28/2025, 5:39 PMsip.callStatus in LiveKit, you can find it in the SIP participant's attributes field. This little attribute tells you what's going on with the SIP call right now, and you can keep an eye on it as things happen.
For example, you might do something like this:
call_status = participant.attributes.get("sip.callStatus")
Here’s a quick rundown of what the sip.callStatus values mean:
• active: The call is live and the SIP participant is active in the room.
• automation: The call is connected, and DTMF tones are being sent.
• dialing: The outbound call is on its way, waiting for someone to pick up.
• hangup: The call has finished.
• ringing: An incoming call is ringing right now.
Also, you can listen for changes with events like on_participant_attributes_changed to catch updates to sip.callStatus as they happen. If you want me to walk you through anything else, just let me know—I’m happy to help!
Sources: SIP participant | LiveKit Docs | Making calls using SIP | LiveKit Docs | telephony/sip_lifecycle.py | livekit/livekit_sip.pb.gobright-eye-88478
08/28/2025, 5:48 PMtall-airline-16756
08/28/2025, 5:49 PMactive, dialing, ringing, or hangup)
◦ sip.phoneNumber: The caller or dialed phone number (unless HidePhoneNumber is turned on)
◦ sip.trunkID: The SIP Trunk ID used for the call
◦ sip.ruleID: The SIP Dispatch Rule ID for inbound calls
◦ sip.trunkPhoneNumber: Phone number linked to the SIP trunk
◦ sip.h.:* These are automatically mapped SIP headers with the sip.h. prefix
• Ingress Participant Attributes:
◦ ingress.ingressID: The Ingress ID tied to the participant
◦ ingress.resourceID: The resource ID for the ingress session
• Custom Attributes: Feel free to define your own custom attributes for participants by including them in the access token or updating them on the fly via SDKs. These live in the attributes field.
• Metadata: Each participant also has a metadata field to store any app-specific data you want, all packed into a single string.
If you want me to walk you through any of these or need some examples, just let me know — I’m happy to help!
Sources: Participant attributes and metadata | LiveKit Docs | rpc/io.pb.go | SIP participant | LiveKit Docsbright-eye-88478
08/28/2025, 6:18 PMtall-airline-16756
08/28/2025, 6:19 PMRuntimeError: cannot use mark_generation_done: no active generation is running pops up when _mark_generation_done() gets called but there isn’t an active generation going on. No worries though—here’s how you can fix it:
• Authorize Generation: Make sure you start a generation with _authorize_generation() before you try to mark it as done:
speech_handle._authorize_generation()
• Wait for Authorization: If you’re working asynchronously, use _wait_for_authorization() to keep things in the right order:
await speech_handle._wait_for_authorization()
• Safe Cleanup: Before marking a generation done, double-check that one is actually active:
if speech_handle._generations: # Just making sure a generation exists
speech_handle._mark_generation_done()
• Use High-Level APIs: It’s often easier to let methods like AgentSession.generate_reply() or SpeechHandle.wait_for_playout() handle the lifecycle for you.
• Handle Interruptions: If a generation gets interrupted, confirm its state before cleaning up:
if speech_handle.interrupted and speech_handle._generations:
speech_handle._mark_generation_done()
If you want me to walk you through any of this or share some examples, just let me know—I’m happy to help!
Sources: livekit-agents/livekit/agents/voice/agent_activity.pybright-eye-88478
09/03/2025, 5:18 PMtall-airline-16756
09/03/2025, 5:19 PMon_participant_attributes_changed event in LiveKit, you can easily set up an event handler on the Room object. This event pops up whenever a participant's attributes get updated. Here’s a quick example to get you started:
Python Example:
@room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes: dict[str, str], participant: rtc.Participant):
print(f"Attributes changed: {changed_attributes}")
print(f"All attributes: {participant.attributes}")
Just a few things to keep in mind:
• Participants need the canUpdateOwnMetadata permission in their access token to update their own attributes.
• If you want to delete an attribute, just set its value to an empty string ('').
• This event fires for all participants (both local and remote) and gives you the full set of updated attributes.
This approach works smoothly across all LiveKit SDKs, like Python, JavaScript, Go, and more. If you want me to walk you through examples for a specific platform, just let me know—I’m happy to help!
Sources: livekit-rtc/livekit/rtc/room.py | Job lifecycle | LiveKit Docs | Inside a session | LiveKit Docs | Participant attributes and metadata | LiveKit Docs | src/room/events.ts