In my SIP webhook handler, I need to pass agent co...
# ask-ai
a
In my SIP webhook handler, I need to pass agent configuration (instructions, voice settings, etc.) to the dispatched agent. The room already exists when my webhook fires. Should I call updateRoomMetadata() before createDispatch(), or should I pass everything via the dispatch metadata parameter? What's the best practice for telephony agents?
t
Thanks for reaching out, Basil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m glad you asked about passing agent configuration in your SIP webhook handler! A really effective approach is to use the metadata parameter during agent dispatch instead of relying on updateRoomMetadata(). The metadata parameter is designed specifically for job-specific configuration and is available right in the agent's entrypoint function when they start up. This way, you can be confident that important configuration details—like instructions or voice settings—are delivered promptly and reliably to the agent. On the other hand, using updateRoomMetadata() can be a bit tricky because it depends on timing and isn’t perfectly synced with the job dispatch lifecycle, which might cause some hiccups. If you’d like me to walk you through examples or clarify anything else, just let me know—I’m here to help! Sources: Job lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs | SIP dispatch rule | LiveKit Docs
a
hmm that's exactly what I'm doing but then as soon as the call is answered it starts with the default insteructions and settings that's set for the agent worker by default if there's no dynamic metada passed
t
Let's work together to figure out why the metadata isn't being applied. Could you please confirm a few things for me? • Are you using explicit agent dispatch with an
agent_name
set, or is it automatic dispatch? • Can you check if the metadata is included in the
CreateAgentDispatchRequest
? • Have you tried adding logging to your agent's
entrypoint
function to see if the metadata is actually being received? • Are you able to tell the difference between SIP participant metadata and job metadata? Knowing these details will really help us pinpoint where the issue might be. I'm here to help every step of the way! Sources: SIP dispatch rule | LiveKit Docs | Agents telephony integration | LiveKit Docs | Agent dispatch | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | pkg/service/agent_dispatch_service.go
a
here is how I'm dispatching // Prepare job metadata for the agent worker const jobMetadata = { agentConfig, agentId: config.agentId, timestamp: new Date().toISOString(), source, roomName, customData: config.customData || {}, } // Dispatch agent to the room const agentName = config.agentName || this.configService.get<string>('LIVEKIT_AGENT_NAME', 'kleem-agent') try { const dispatch = await this.agentDispatchClient.createDispatch( roomName, agentName, { metadata: JSON.stringify(jobMetadata) } ) this.logger.log('🚀 Agent dispatched:', { roomName, agentName, agentId: config.agentId, dispatchId: dispatch.id, source, }) return { dispatchId: dispatch.id, agentConfig, agentId: config.agentId, } } catch (error) { this.logger.error(
Failed to dispatch agent to room ${roomName}:
, error) throw error }
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!