I am configuring an agent to make outbound calls a...
# ask-ai
s
I am configuring an agent to make outbound calls and I'm trying to pass metadata to it, but the metadata is never sent to agent despite using the exact same command provided in the docs. Agent code:
Copy code
async def entrypoint(ctx: JobContext):
    """
    Main entry point for the agent worker - handles inbound/outbound calls
    """

    print(ctx.job)

...
and I'm using the following command to make the call:
Copy code
lk --project development dispatch create \
    --new-room \
    --agent-name my-telephony-agent \
    --metadata 'foo'
Using project [development]
Dispatch created: id:"AD_QBCpejWRFdLH"  agent_name:"my-telephony-agent"  room:"room-5tYmBygSMCnT"  metadata:"foo"  state:{created_at:1756817153983250007}
but looking at the printed logs I don't see any metadata:
Copy code
id: "AJ_PuNzxb9iqYQt"
room {
  sid: "RM_EneXZhGWfcCB"
  name: "room-4nM5uniACPBC"
  empty_timeout: 300
  creation_time: 1756817537
  enabled_codecs {
    mime: "video/H264"
  }
  enabled_codecs {
    mime: "video/VP8"
  }
  enabled_codecs {
    mime: "video/VP9"
  }
  enabled_codecs {
    mime: "video/AV1"
  }
  enabled_codecs {
    mime: "audio/red"
  }
  enabled_codecs {
    mime: "audio/opus"
  }
  version {
    unix_micro: 1756817537065403
  }
  departure_timeout: 20
  creation_time_ms: 1756817537049
}
state {
  status: JS_RUNNING
  started_at: 1756817537519467213
  updated_at: 1756817537519467213
  worker_id: "AW_A8w5qUaVboo9"
  agent_id: "A_fFk383vGUpRV"
}
What am I missing? Why is there no metadata in the job context?
t
Thanks for reaching out, Redouane. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! The metadata you pass during dispatch should show up in the agent's
JobContext
under
ctx.job.metadata
. But it looks like it’s not showing up in your logs right now. No worries though—here are a few things you can check to get it sorted: 1. Make sure the metadata is passed as a string. If you’re sending structured data, use JSON. For example:
--metadata '{"key":"value"}'
. 2. In your agent’s code, try logging
ctx.job.metadata
directly to see if it’s there. Something like this works:
Copy code
import json

async def entrypoint(ctx: JobContext):
    metadata = ctx.job.metadata
    print(f"Metadata: {metadata}")
    if metadata:
        parsed_metadata = json.loads(metadata)
        print(f"Parsed Metadata: {parsed_metadata}")
1. Double-check that your agent is registered correctly with the
agent_name
you’re using in the dispatch command. 2. Take a look at the dispatch creation response to see if the metadata is included there. If it’s missing, the issue might be with how the dispatch command is set up. If you’re still running into trouble after trying these steps, just give me a shout! I’m here to help you figure it out. Sources: examples/agent_dispatch.py | examples/agent-dispatch/index.ts | flows/declarative_flow.py | Agent dispatch | LiveKit Docs | Job lifecycle | LiveKit Docs
s
is the
agent_name
mandatory for this to work properly? My agent does get the job currently so it seems to be dispatched as expected, but still the metadata can't be found in the job context
t
Hey there! Just to clarify, the
agent_name
isn’t directly tied to the metadata itself, but it’s super important for enabling explicit dispatch. This is the feature that lets metadata get passed along to the
JobContext
. Without setting
agent_name
, explicit dispatch won’t work, and your job context won’t include the metadata. Since your agent is receiving the job, it looks like dispatch is happening, but the missing metadata hints that explicit dispatch might not be fully set up yet. Here are a few things to double-check: 1. Make sure the
agent_name
is included in the dispatch command or configuration. 2. Confirm that the metadata is being sent as a string (JSON is usually best) in the dispatch command. 3. Try explicitly logging
ctx.job.metadata
in your agent’s entrypoint to see if it’s there. If you’ve already done all this and it’s still not working, just give me a shout and we’ll dig into it together! Sources: Dispatching agents | LiveKit Docs | livekit-protocol/livekit/protocol/agent.py | Making calls using SIP | LiveKit Docs
s
ok setting the agent name fixed the issue, thanks.
t
You're very welcome! I'm happy to hear that setting the
agent_name
did the trick. If anything else comes up or you have more questions, just give me a shout—I'm here to help!
c
Hey @shy-train-51607 sorry to bother you, im having the same issue but sporadicly. I've seen that im getting a duplicated dispatch when i run the dispatch command and thats the problem (you can check it wit lk dispatch list <room_id>). This is not a problem if you run the agent locally but it is in production, would it be a problem for you to verify if you are having duplicated dispatches too? thanks!
t
It sounds like you’re running into some occasional duplicate dispatches, which can definitely be tricky in production. To help you out better, could you share a few details with me? • The exact command you’re using to create the dispatch. • The
room_id
where you’re seeing these duplicate dispatches. • Any patterns or situations you’ve noticed when the duplicates happen (like during high load or certain settings). Once I have this info, I’ll do my best to help you figure out what’s going on and get it sorted out.
s
Hi @clean-architect-57780, I'm deploying to production tomorrow, still running tests now. I will let you know if get the same issue. Thanks for your message!
✅ 1
t
Thanks so much for the update! If the issue pops up again or you need a hand during your production deployment, just give me a shout. Wishing you the best of luck with everything!