salmon-elephant-7819
12/16/2025, 4:57 AMtall-airline-16756
12/16/2025, 4:57 AMtall-airline-16756
12/16/2025, 4:57 AMagent.update_instructions(instructions: str) to change the agent's system prompt for the current session.
• Send instructions at dispatch time via job.metadata (e.g., dial info) and apply them in the agent entrypoint when the session starts.
How to choose
• Use update_instructions() when you need to change behavior after the call is connected (based on caller attributes, SIP headers, or live context).
• Use metadata when you already know the instructions at dial/dispatch time and want the agent initialized with those instructions.
Example — update at runtime (telephony + SIP participant)
1. Wait for or detect the SIP participant and read attributes:
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
phone = participant.attributes.get('sip.phoneNumber')
1. Update the agent instructions based on the phone or SIP attributes:
if phone == '+15105550100':
await agent.update_instructions(
"You are speaking with a premium customer. Be extra courteous and offer priority support."
)
This updates the LLM system prompt immediately so subsequent agent responses follow the new instructions.
Example — pass via job metadata at dispatch
1. Put instructions into job.metadata when creating the dial job:
{
"instructions": "Handle as high-priority; escalate billing issues."
}
1. Read and apply inside the entrypoint:
dial_info = json.loads(ctx.job.metadata)
custom_instructions = dial_info.get("instructions", "Default instructions")
await agent.update_instructions(custom_instructions)
Follow-ups I can help with
• Show a full example entrypoint or session flow in your codebase language (Python/JS).
• Suggest logic for choosing when to mutate instructions vs. re-dispatching a new agent.
• Help map which SIP attributes or headers you should inspect for routing/instruction rules.
Which follow-up would you like?
Sources: Agents (Python) | livekit/livekit_composite | DeepWiki | SIP participant | LiveKit docs | Agents telephony integration | LiveKit docssalmon-elephant-7819
12/16/2025, 5:02 AMtall-airline-16756
12/16/2025, 5:03 AMjob.metadata, detect a SIP participant, and call agent.update_instructions().
Python (async) entrypoint example
import json
from livekit import rtc
async def entrypoint(ctx):
# 1) Read instructions from job.metadata (if present)
metadata = getattr(ctx.job, "metadata", None)
instructions = None
if metadata:
try:
dial_info = json.loads(metadata)
instructions = dial_info.get("instructions")
except Exception:
pass
# 2) Start agent session
agent = MyAgent() # your Agent implementation
session = AgentSession(agent=agent)
await session.start(room=ctx.room)
# 3) Wait for participant (telephony/SIP)
participant = await ctx.wait_for_participant()
# 4) Inspect SIP attributes and override instructions if needed
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
phone = participant.attributes.get("sip.phoneNumber")
if phone == "+15105550100":
instructions = "You are speaking with a premium customer. Offer priority support."
# 5) Apply instructions at runtime if we have them
if instructions:
await agent.update_instructions(instructions)
# 6) Continue session logic (e.g., bridging audio, handling events)
await session.run_until_ended()
JavaScript/TypeScript (async) entrypoint example
export async function entrypoint(ctx) {
// 1) Read instructions from job.metadata
let instructions = undefined;
if (ctx.job?.metadata) {
try {
const dialInfo = JSON.parse(ctx.job.metadata);
instructions = dialInfo.instructions;
} catch (e) {}
}
// 2) Initialize agent session
const agent = new MyAgent(); // your Agent class
const session = new AgentSession({ agent });
await session.start({ room: ctx.room });
// 3) Wait for participant (telephony/SIP)
const participant = await ctx.waitForParticipant();
// 4) Inspect SIP attributes and optionally override
if (participant.kind === "sip") {
const phone = participant.attributes?.["sip.phoneNumber"];
if (phone === "+15105550100") {
instructions = "You are speaking with a premium customer. Offer priority support.";
}
}
// 5) Apply instructions at runtime
if (instructions) {
await agent.updateInstructions(instructions);
}
// 6) Continue with session lifecycle
await session.runUntilEnded();
}
Notes and next steps
• Replace MyAgent, AgentSession, and session lifecycle calls with your actual implementations.
• Tell me which language (Python or JS) and the Agent/session classes you use if you want a tailored, runnable entrypoint for your codebase.salmon-elephant-7819
12/16/2025, 5:10 AMtall-airline-16756
12/16/2025, 5:10 AMagent.update_instructions() or in job metadata.
1) Premium customer — concierge support "You are a concierge-level support agent speaking with a premium customer. Greet them warmly, use their name if available, apologize for any inconvenience, prioritize rapid resolution, offer white-glove options, and confirm satisfaction before ending the call. Keep language polite, confident, and concise."
2) Bank agent — verify recent transaction "You are a bank verification agent. Politely identify yourself and your bank, verify the customer's identity using two verification questions, then ask about the recent transaction details (date, amount, merchant) to confirm whether they authorized it. If the customer denies the transaction, calmly explain next steps for dispute and card protection. Maintain a reassuring tone, avoid sharing sensitive account data aloud, and escalate suspected fraud per procedure."
3) Outbound sales — polite qualification "You are an outbound sales representative calling a warm lead. Briefly introduce yourself and company, state the purpose of the call, ask two open qualification questions about current needs and budget, and propose a single next step (demo or meeting). Be respectful of time; if they’re unavailable, ask for a better time to follow up."
4) Appointment reminder — confirmation and reschedule "You are an appointment coordinator calling to confirm an upcoming appointment. State the appointment date, time, and location; ask the customer to confirm or reschedule; and offer alternate times if needed. Record confirmations and notify the system of any changes. Keep the call short, friendly, and helpful."
5) Collections — empathetic payment arrangement "You are a collections agent focused on arranging a payment. Use an empathetic tone, state the overdue balance, ask if they can pay now or propose a reasonable payment plan, and clearly explain consequences and available assistance options. Document the agreed plan and confirm next steps and dates."
6) Technical support escalation — gather context "You are a technical support agent initiating an escalation call. Confirm the caller’s identity, summarize the reported issue, ask targeted troubleshooting questions (recreate steps, error messages, recent changes), and collect logs or screenshots if available. Provide a clear timeline for the escalation and next contact point. Stay professional and avoid promising specific timelines."
Tips for customization
• Insert dynamic variables: customer name, account tier, last transaction details.
• Keep prompts 1–3 short focused instructions to avoid conflicting guidance.
• For regulated scenarios (banking/collections), include explicit escalation and data-handling rules.
Would you like any of these rewritten for a specific tone, shorter length, or formatted for direct insertion into job.metadata?