I'm making a telephony agent, connectivity is all ...
# ask-ai
r
I'm making a telephony agent, connectivity is all working properly, but the agent needs to load configuration from the database before it can connect to the room. This initialization process is taking long enough that LiveKit's SIP Trunk is then rejecting the connection with
ALLOTTED_TIMEOUT
. Is there a way to increase this timeout so that the agent has more time to load before it gives up?
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you avoid the
ALLOTTED_TIMEOUT
error, you can increase the timeout by adjusting the
ringing_timeout
parameter. There are a couple of ways to do this: • Trunk-Level Timeout: You can set the
ringing_timeout
in the SIP Inbound Trunk configuration. This will apply a default timeout for all calls using that trunk, making it a convenient option. • Participant-Level Timeout: Alternatively, when creating a SIP participant, you can specify the
ringing_timeout
. For example, in Node.js:
Copy code
const participant = await sipClient.createSipParticipant(
  sipTrunkId,
  phoneNumber,
  roomName,
  {
    ringingTimeout: 60 // 60 seconds timeout
  }
);
Feel free to adjust the timeout value (say, between 60 and 120 seconds) to best fit your agent's initialization time. If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: packages/javascript/CHANGELOG.md | packages/livekit-server-sdk/src/SipClient.ts | lib/livekit/sip_service_client.rb | pkg/service/sip.go
r
I've set the
ringingTimeout
on the inbound trunk configuration in LiveKit Cloud, but the issue is still happening. Is there a way to set the
ringingTimeout
on participant through the dispatch rules in LiveKit Cloud?
t
Thanks for reaching out! I wanted to share that the
ringingTimeout
parameter can’t be set directly on participants through dispatch rules in LiveKit Cloud. Instead, this setting is available at the SIP trunk level or when you create a SIP participant programmatically, like using the
CreateSIPParticipant
API. If you’re looking to control the timeout for calls dispatched via a rule, the best approach is to make sure the
ringingTimeout
is set correctly on the SIP trunk(s) linked to that dispatch rule. Please feel free to ask if you’d like me to walk you through this or if you have any other questions—I’m here to help! Sources: protobufs/livekit_sip.proto | SIP APIs | LiveKit docs | SIP dispatch rule | LiveKit docs
r
I need to access sip headers from the participant to be able to configure the agent properly. What is the best way to do this without it taking a long time to start the agent session?
t
I'm happy to help you access SIP headers without causing any delay to your agent sessions! You can do this by configuring the
headers_to_attributes
option in your SIP trunk or dispatch rule. This handy feature maps specific SIP headers (like
X-Customer-ID
) directly to participant attributes, so they’re ready and waiting as soon as the participant joins the room. Here’s an example you can try in your SIP trunk configuration:
Copy code
{
  "headers_to_attributes": {
    "X-Customer-ID": "customer_id",
    "X-Tenant": "tenant"
  }
}
Once set up, these attributes become immediately accessible programmatically, helping your agent get started right away without any extra waiting. If you’d like, I’m here to walk you through the setup or answer any questions you might have—just let me know! Sources: SIP participant | LiveKit docs | protobufs/rpc/io.proto
r
In nodejs, how can I reliably access those attributes in the entrypoint function?
t
In Node.js, you can easily access participant attributes in the entrypoint function using the
JobContext
object. Let me share a simple example with you:
Copy code
import { JobContext } from 'livekit-server-sdk';

async function entrypoint(ctx: JobContext) {
  // Connect the agent to the room
  await ctx.connect();

  // Access room participants
  const participants = Array.from(ctx.room.participants.values());
  for (const participant of participants) {
    console.log('Participant identity:', participant.identity);
    console.log('All attributes:', participant.attributes); // { key1: 'value1', ... }

    // Access specific attribute
    const task = participant.attributes['task'];
    if (task) {
      console.log('Task:', task);
    }
  }

  // Listen for attribute changes
  ctx.room.on('participant_attributes_changed', ({ changed_attributes, participant }) => {
    console.log('Attributes changed:', changed_attributes);
    console.log('Updated attributes:', participant.attributes);

    // Handle specific attribute change
    if ('voice' in changed_attributes) {
      const newVoice = participant.attributes['voice'];
      console.log(`Participant ${participant.identity} changed voice to: ${newVoice}`);
    }
  });
}
This example shows you how to grab attributes from participants and keep track of any updates in real-time. If anything is unclear or if you'd like me to walk you through it step-by-step, please don't hesitate to ask—I'm here to help! Sources: agent/main.py | examples/agent-dispatch/index.ts | Participant attributes and metadata | LiveKit docs | Building an Automated IVR Menu Caller | LiveKit Docs