many-forest-60185
09/05/2025, 3:35 AMtall-airline-16756
09/05/2025, 3:35 AMtall-airline-16756
09/05/2025, 3:36 AMupdate_instructions() method. This lets you tweak the instructions sent to the OpenAI Realtime API while your session is running—pretty handy, right?
1. Update Instructions on the Agent:
await agent.update_instructions("You are now a customer support specialist.")
This will refresh the instructions for your agent and the current session. For example:
class ChangeInstructionsAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a helpful agent...")
async def on_enter(self):
if self.session.participant.name.startswith("sip"):
await self.update_instructions("You are a helpful agent speaking on the phone.")
self.session.generate_reply()
2. Update Instructions on the Realtime Session:
await realtime_session.update_instructions("You are a helpful assistant.")
This updates the instructions directly for the session.
Just a quick reminder: make sure you have the OpenAI plugin installed (pip install "livekit-agents[openai]~=1.2") and that your OpenAI API key is set up in the .env file.
If you hit any bumps or want to chat more about it, just let me know—I’m here to help!
Sources: web/src/components/code-viewer.tsx | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/tts.py | complex-agents/ivr-agent/agent.py | OpenAI Realtime API integration guide | LiveKit Docs