agents=[ RoomAgentDispatch( ...
# ask-ai
l
agents=[ RoomAgentDispatch( agent_name=AGENT_NAME, metadata=json.dumps({ "call_id": call_id, "from_number": from_number, "contact_name": contact_name, "call_direction": "inbound", "phone_number_id": phone_number_id }), )], how to get the this agent metadata from the entrypoint funtion of new job recievd
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to access the agent metadata you attached in your RoomAgentDispatch from the agent entrypoint when a new job arrives. I’m answering about that exact piece: the metadata field you showed (the JSON string with call_id, from_number, contact_name, etc.). You can read the metadata from the job context at
ctx.job.metadata
and parse it (it’s a JSON string). Below are concise examples for Python and Node.js. Python example
Copy code
import json
from livekit.agents import JobContext

async def entrypoint(ctx: JobContext):
    # metadata is a JSON string on the job object
    metadata = json.loads(ctx.job.metadata)

    call_id = metadata["call_id"]
    from_number = metadata["from_number"]
    contact_name = metadata["contact_name"]
    call_direction = metadata.get("call_direction")
    phone_number_id = metadata.get("phone_number_id")

    # use these values as needed
    print(f"Call ID: {call_id}, From: {from_number}, Contact: {contact_name}")
Node.js / TypeScript example
Copy code
import type { JobContext } from '@livekit/agents';

export default {
  entry: async (ctx: JobContext) => {
    // metadata is a JSON string on the job object
    const metadata = JSON.parse(ctx.job.metadata);

    const callId = metadata.call_id;
    const fromNumber = metadata.from_number;
    const contactName = metadata.contact_name;
    const callDirection = metadata.call_direction;
    const phoneNumberId = metadata.phone_number_id;

    console.log(`Call ID: ${callId}, From: ${fromNumber}, Contact: ${contactName}`);
  },
};
Notes and quick tips • The metadata is sent as a string, so parsing is required (
json.loads
/
JSON.parse
). • Use
.get()
(Python) or optional chaining / checks in JS if some fields may be missing. • If you want to pass structured objects rather than strings, you can still stringify before dispatch and parse inside the entrypoint as shown. If you’d like, tell me: • which language (Python or Node) you’re using, • and paste the exact entrypoint signature you have — I’ll give a ready-to-drop-in snippet for your agent code. Sources: Job lifecycle | LiveKit Documentation | Survey Calling Agent | LiveKit Documentation | Agent dispatch | LiveKit Documentation | sip | livekit/livekit_composite | DeepWiki