aloof-scooter-47164
11/30/2025, 4:59 PMtall-airline-16756
11/30/2025, 4:59 PMtall-airline-16756
11/30/2025, 4:59 PMinstructions passed to session.generate_reply with the OpenAI realtime model replace the agent/model system instructions or are appended for that single speech handle.
They do not replace the system instructions. instructions are transient directives applied only to that single reply: they guide the LLM for that turn, are combined with the existing system context, and do not overwrite the agent or model's core instructions. If you provide user_input instead, that text is added to chat history as a user message; instructions are used internally and not recorded in history.
Sources: Agent speech and audio | LiveKit docsaloof-scooter-47164
11/30/2025, 5:03 PMtall-airline-16756
11/30/2025, 5:04 PMsession.say can be used with the OpenAI Realtime model.
Yes — you can use session.say with Realtime, but you must configure a TTS plugin in your AgentSession. session.say relies on a TTS instance to synthesize audio; the Realtime model itself doesn't provide built-in script-to-speech for say. Example:
session = AgentSession(
llm=openai.realtime.RealtimeModel(voice="marin"),
tts="cartesia/sonic-3",
)
session.say("Hello")
If you prefer not to attach a TTS plugin, use session.generate_reply(instructions="...") to have the Realtime model produce the reply content directly.
Sources: Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docsaloof-scooter-47164
11/30/2025, 5:04 PMtall-airline-16756
11/30/2025, 5:05 PMsession.say() uses that TTS, and let the OpenAI Realtime model handle other replies. The TTS is only used for session.say() calls; other responses (e.g., generate_reply() or normal realtime replies) are produced by the Realtime model’s built-in speech generation.
Example:
session = AgentSession(
llm=openai.realtime.RealtimeModel(voice="marin"), # realtime handles normal replies
tts="cartesia/sonic-3", # used only for session.say()
)
await session.say("This uses the TTS plugin")
# other replies remain handled by the Realtime model
Would you like an example in your language/runtime or guidance on TTS voice selection?
Sources: Realtime model plugins | LiveKit Docsaloof-scooter-47164
12/01/2025, 9:05 PMtall-airline-16756
12/01/2025, 9:05 PMAgentSession with openai.realtime.RealtimeModel or a lower-level realtime connection?
3. Which kind of update do you want:
◦ persistent system-level context for future turns,
◦ a temporary per-turn instruction, or
◦ appending a user/assistant message into visible chat history?
1. Do you need the update to occur mid-stream (while Realtime is actively responding) or only between replies?
2. Any runtime preferences (sync vs async) or need to include TTS/`session.say` behavior?
Tell me these and I’ll send a targeted Python (or Node) example plus notes on constraints and expected behavior.
Sources: Agents v0.x migration guide - Node.js | LiveKit Docs | Agents v0.x migration guide - Python | LiveKit docs | Agents and handoffs | LiveKit docsaloof-scooter-47164
12/01/2025, 9:06 PMtall-airline-16756
12/01/2025, 9:07 PMAgentSession using openai.realtime.RealtimeModel. Yes — you can. Use update_chat_ctx() from your Agent (or AgentSession) to persist changes so they're used by subsequent turns, even while the realtime session is active.
Quick example (Python):
from livekit.agents import Agent, ChatContext, ChatMessage
class MyAgent(Agent):
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
# Example: add persistent system-level info or RAG result
rag_content = await my_rag_lookup(new_message.text_content())
turn_ctx.add_message(role="system", content=f"RAG: {rag_content}")
# Persist the updated context so future realtime replies use it
await self.update_chat_ctx(turn_ctx)
Notes and best practices
• Enable text modality on the Realtime model (modalities=["text"]) to ensure reliable text access and transcription when doing mid-stream updates.
• Prefer modifying the provided turn_ctx and calling update_chat_ctx() rather than mutating global state.
• Use lifecycle hooks like on_user_turn_completed() to inject context before the agent generates the next reply.
• Test mid-stream behavior (concurrent streams) to ensure timing meets your requirements.
Would you like a complete runnable example (including session init with RealtimeModel(modalities=["text"])) or guidance for handling concurrent updates?
Sources: OpenAI Realtime API plugin guide | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Azure OpenAI Realtime API and LiveKit | LiveKit docs | Using the Testing Framework with Realtime Models