how can I have my agent start speaking, only after...
# ask-ai
w
how can I have my agent start speaking, only after the SIP call status is active?
t
Thanks for reaching out, Arthur. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To make sure your agent starts talking only after the SIP call status is active, you can keep an eye on the
sip.callStatus
attribute of the participant. Here’s a friendly step-by-step on how to do this: 1. Create the SIP Participant: Use the
create_sip_participant
method to kick off the call. This will start dialing the user and return right away. 2. Watch the Call Status: After you create the participant, keep checking the
sip.callStatus
attribute. It’ll switch to
active
once the call is answered. 3. Let the Agent Speak: As soon as the call status hits
active
, use the agent's
generate_reply
method to get the conversation going. Here’s a handy Python snippet to guide you:
Copy code
import asyncio

async def monitor_call_status(participant):
    start_time = asyncio.get_event_loop().time()
    while asyncio.get_event_loop().time() - start_time < 30:
        call_status = participant.attributes.get("sip.callStatus")
        if call_status == "active":
            print("Call is active, agent will start speaking.")
            await session.generate_reply(
                instructions="Greet the user and offer your assistance."
            )
            return
        elif call_status == "hangup":
            print("Call has been ended.")
            break
        await asyncio.sleep(0.1)
    print("Call monitoring timed out.")
This way, your agent will jump in right after the call connects. If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: agents/src/pipeline/pipeline_agent.ts | Make outbound calls | LiveKit Docs | Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs | Agents telephony integration | LiveKit Docs