How do I update the instructions of my realtime Op...
# ask-ai
m
How do I update the instructions of my realtime OpenAI instance? Python backend
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to update the instructions for your realtime OpenAI instance using a Python backend, you can easily do that with the
update_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:
Copy code
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:
Copy code
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:
Copy code
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