agreeable-window-53636
04/17/2026, 9:22 PMtall-airline-16756
04/17/2026, 9:23 PMtall-airline-16756
04/17/2026, 9:23 PM{{metadata.key}}) in your agent builder prompts to substitute metadata into the agent’s base instructions.
Updating instructions while the agent is live
• Use update_instructions() at runtime to replace the agent’s system prompt immediately without restarting the session. The change is applied to the current session and recorded in conversation history as an AgentConfigUpdate.
• For single-reply guidance (transient), call `session.generate_reply(instructions="...")`; those instructions affect only that reply and do not replace the agent’s base instructions.
If you want, tell me:
• Whether you plan to send simple metadata values or full prompt strings at dispatch, and
• Which SDK/language you’re using (Python, JS, etc.),
and I’ll provide a short code example tailored to your setup.
Sources: Agent dispatch | LiveKit Documentation | Job lifecycle | LiveKit Documentation | Agent Builder | LiveKit Documentation | Prompting guide | LiveKit Documentation | External data and RAG | LiveKit Documentation, with interactive elementsagreeable-window-53636
04/17/2026, 9:24 PMagreeable-window-53636
04/17/2026, 9:24 PMtall-airline-16756
04/17/2026, 9:24 PMctx.job.metadata (JSON) and either:
◦ Build the effective system prompt from metadata values, or
◦ Substitute metadata into templated instructions defined in the agent builder.
Example flow (HTTP + Python)
1) Dispatch / create the job via HTTP (include metadata)
• POST /jobs (or your dispatch endpoint)
• Body example (JSON):
{
"agent_name": "my-agent",
"metadata": {
"role": "support",
"greeting": "Hello — I'm here to help with billing."
},
"other_job_fields": "..."
}
2) Python agent entrypoint reads metadata and applies it to instructions
• In your agent handler, parse ctx.job.metadata, then set the session/system prompt or use those values when generating replies. For example:
@server.rtc_session(agent_name="my-agent")
async def my_agent(ctx: JobContext):
metadata = json.loads(ctx.job.metadata)
role = metadata.get("role", "assistant")
greeting = metadata.get("greeting", "Hello!")
# Option A: Set effective instructions at session start
await self.update_instructions(f"You are a {role}. {greeting}")
# Option B: Use metadata per-reply without changing base instructions
reply = await session.generate_reply(instructions=f"Use a {role} tone. Start with: {greeting}")
await session.send(reply)
Notes
• Use metadata templating in your agent builder prompts (e.g., {{metadata.greeting}}) if you prefer prompts to be managed in the builder and just supply values via metadata.
• update_instructions() affects the current session; since you only create new sessions, calling it at session start sets the instruction for that new session only.
• session.generate_reply(instructions=...) is transient (per-reply) and won’t persist beyond that reply.
If you want, I can:
• Provide a concrete HTTP request example for your specific dispatch endpoint, or
• Show a complete minimal Python agent file that reads metadata and sets instructions at session start. Which would you prefer?, with interactive elementstall-airline-16756
04/17/2026, 9:25 PMfrom fastapi import FastAPI, Body
from livekit_agents import Agent, server, JobContext # adjust imports to your code
app = FastAPI()
current_instructions = "Default instructions for new sessions"
class Assistant(Agent):
def __init__(self, instructions: str):
super().__init__(instructions=instructions)
@app.post("/update-instructions")
def update_instructions(payload: dict = Body(...)):
global current_instructions
current_instructions = payload["instructions"]
return {"status": "ok", "instructions_preview": current_instructions[:120]}
@server.rtc_session(agent_name="my-agent")
async def my_agent(ctx: JobContext):
# Read the latest instructions when creating the agent for this session
assistant = Assistant(instructions=current_instructions)
session = assistant.create_session(...) # your existing session startup
await session.start(agent=assistant, room=ctx.room)
Notes and options
• Persist the instruction in a DB or file if you need it to survive restarts instead of a global variable.
• This pattern ensures existing sessions keep their original instructions because each session is created with the instruction value read at creation time.
• If you ever want transient per-session overrides, you can also pass metadata or use generate_reply(instructions=...) for single replies (but that’s per-reply, not a global change).
Want a version that uses a database for persistence or a complete runnable example tied to your current agent code? Share which web framework and persistence you prefer and I’ll produce it.
Sources: Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Build a salary negotiation coach with a LemonSlice avatar | LiveKit | Agent speech and audio | LiveKit Documentation | Gemini Live API plugin | LiveKit Documentation, with interactive elementsagreeable-window-53636
04/17/2026, 9:26 PMagreeable-window-53636
04/17/2026, 9:26 PMtall-airline-16756
04/17/2026, 9:26 PM