How do change an agent’s prompt externally?
# ask-ai
c
How do change an agent’s prompt externally?
t
Thanks for reaching out, Bryce. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to change an agent’s prompt on the fly in LiveKit, you can use the
update_instructions
method from the
Agent
class. It’s super handy because it lets you update what the agent’s instructions are while everything’s running, even in the middle of a session. Here’s a quick example:
Copy code
await agent.update_instructions("You are now a voice assistant for phone calls.")
You can call this method whenever something happens, like when a user says something or through an RPC call. And if you ever want to swap out the agent entirely with new instructions, you can do that too using
session.update_agent()
. Feel free to ask if you want me to walk you through more examples or if you have any questions! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | complex-agents/ivr-agent/README.md | Workflows | LiveKit Docs | AI Voice Assistant Quickstart | LiveKit Docs | tools/server/public_legacy/index-new.html