how to extract the caller's number from session me...
# ask-ai
m
how to extract the caller's number from session metadata?
t
Thanks for reaching out, Fancy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to extract the caller's phone number from session metadata — here’s how to do that for SIP participants. • Check the participant is a SIP participant (kind equals
PARTICIPANT_KIND_SIP
/
ParticipantKind.SIP
). • Read the
sip.phoneNumber
attribute from the participant's attributes — it contains the caller's number in E.164 format. Example (Python):
Copy code
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
    phone_number = participant.attributes.get("sip.phoneNumber")
    if phone_number:
        print(f"Caller phone number: {phone_number}")
Example (Node.js/TypeScript):
Copy code
if (participant.kind === ParticipantKind.SIP) {
  const phoneNumber = participant.attributes['sip.phoneNumber'];
  console.log(`Caller phone number: ${phoneNumber}`);
}
Notes: •
sip.phoneNumber
is populated for inbound calls and may be omitted if a dispatch rule has
HidePhoneNumber
enabled. • If not present, also check participant identity or job metadata (outbound calls may pass numbers via job metadata). Sources: SIP participant | LiveKit docs | Agents telephony integration | LiveKit docs
m
Can a subagent extract session metadata or can it only be done by the main agent?
t
You're asking whether a subagent can extract session metadata or if only the main agent can do that — short answer: yes, a subagent can. • Any agent instance (main or subagent after a handoff) can access session and job context. • Accessible data includes:
ctx.room.metadata
,
ctx.job.metadata
,
participant.attributes
/
participant.metadata
, and
session.userdata
. •
session.userdata
is useful for passing custom state between agents during handoffs. If you want, tell me which metadata field you need (e.g.,
sip.phoneNumber
, job metadata, or
session.userdata
) and which language/runtime you’re using — I’ll provide a short code example. Sources: Job lifecycle | LiveKit docs | Agents and handoffs | LiveKit docs
m
once some metadata is extracted by the main agent, can it be saved into eg. userdata and be carried over to all other agents for the rest of the session?
t
Yes — you can save metadata extracted by the main agent into
session.userdata
and it will be available to all subsequent agents for the rest of that session. • Use
session.userdata
to store any custom state or structured data (e.g., caller number, disposition, flags). • When an agent hands off control, include the updated `session.userdata`; the next agent reads the same
session.userdata
. • Accessible fields include
ctx.room.metadata
,
ctx.job.metadata
, and
participant.attributes
, but
session.userdata
is the explicit mechanism for passing custom state between agents. If you’d like, tell me your language/runtime and the specific fields you want to persist and I’ll provide a concise code example.
m
do subagents need their own entrypoints at all?
t
You're asking if subagents need their own entrypoints — short answer: no. • A single entrypoint handles the session (e.g., the
room_join
handler). • Subagents are instantiated and activated via handoffs within that session; they reuse the original entrypoint and share session context. • Implement subagent-specific logic in lifecycle methods like
on_enter()
or by returning/updating the active agent during a tool call; no separate network entrypoint is required. Sources: examples/drive-thru | livekit/livekit_composite | DeepWiki | Agents and handoffs | LiveKit docs