When I send a system message and ask the AI about ...
# ask-ai
l
When I send a system message and ask the AI about it, the AI doesn’t seem to know anything about it. Why is this? Is this expected behaviour?
t
Thanks for reaching out, Tom. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're right to notice that — this is expected. When you send a message during a live session, the system treats it as regular user input unless your application explicitly applies it as a system-level instruction. System (or "system prompt") instructions are normally set at agent initialization (for example via an
instructions
parameter) or updated via explicit API calls such as
update_instructions()
. Sending a message labeled “system” in the chat stream does not automatically change the agent’s internal system prompt or behavior. If your goal is to change the agent’s role/behavior at runtime, you can: • Initialize the agent with the desired system instructions (so they are applied from the start), or • Use the API method to update instructions during the session (
update_instructions()
or equivalent in your SDK) so the agent recognizes the new system-level instruction. If you’d like, tell me how you’re sending the message (which SDK or topic you’re using and a short example of the payload), and I’ll suggest the precise call or pattern to make it act as a true system instruction. Sources: Prompting guide | LiveKit docs | Events and error handling | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs | Agents (Python) | livekit/livekit_composite | DeepWiki
l
I have this code: The AI only seems to know about system messages I send if sync is true - but I need a way to send system messages without forcing a reply. how can i do this if this code is not valid? async def send_system_message(self, _message_: str, _sync_: bool = False) -> None: “”"Send a system message to the AI. Adds a SYSTEM/DEVELOPER role message to the chat context. If sync is True, immediately syncs with Realtime model (may trigger response). If False (default), message is added to context but only included in the model’s NEXT natural response (won’t trigger immediate reply). Also broadcasts to frontend for debug logging. Args: message: The system message to send (no brackets needed) sync: If True, immediately sync with Realtime model (may trigger response). If False (default), message is added to context but only included in the model’s NEXT natural response (won’t trigger immediate reply). Use sync=True only when you explicitly want the AI to respond. “”" if hasattr(self, ‘session’) and self.session: # Copy current chat context chat_ctx = self.chat_ctx.copy() # Add system message chat_ctx.add_message( role=“system”, content=message ) if sync: # Sync with Realtime model - may trigger response logger.info(f”CHAT CONTEXT: {chat_ctx}“) await self.update_chat_ctx(chat_ctx) logger.info(f”[SYSTEM] System message sent and synced: {message}“) else: # Just update local context - included in next natural response # This avoids triggering an immediate response from Realtime models self._chat_ctx = chat_ctx logger.info(f”[SYSTEM] System message buffered (no sync): {message}“)
t
You're correct that your current approach won't reliably make the Realtime model "see" the system message unless you sync it. Here's the concise, correct pattern and why it works. What’s happening • Realtime models only use context that's been pushed to the Realtime session. Setting a local
self._chat_ctx
copy does not deliver the message to the model. • Calling
update_chat_ctx()
sends the context to the model — but calling it alone doesn't have to force an immediate reply. Generating a reply is a separate action. Fix: always sync context, but only trigger a response when you want one 1. Add the system message to a copy of your chat context. 2. Call
await self.update_chat_ctx(chat_ctx)
so the model receives the instruction. 3. Only call the reply generation API (
generate_reply()
,
say()
, or similar) if
sync=True
. Suggested implementation:
Copy code
async def send_system_message(self, message: str, sync: bool = False) -> None:
    chat_ctx = self.chat_ctx.copy()
    chat_ctx.add_message(role="system", content=message)

    # Ensure Realtime model receives the instruction
    await self.update_chat_ctx(chat_ctx)
    logger.info(f"[SYSTEM] System message sent: {message}")

    # Only generate a response if explicitly requested
    if sync:
        await self.session.generate_reply(instructions=message)
Optional: if your Realtime plugin supports disabling auto-response (e.g.,
create_response=False
or server-side VAD settings), use that so the model never auto-generates replies and you control every response via
generate_reply()
. If you want, tell me which SDK/plugin and the session methods you have available (e.g.,
generate_reply
,
say
, turn-detection options) and I’ll tailor the exact call names. Sources: Azure OpenAI Realtime API and LiveKit | LiveKit docs | Testing and evaluation | LiveKit Docs | Agent speech and audio | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Realtime model plugins | LiveKit Docs
l
update_chat_ctx seems to make the AI reply, even without calling generate_reply
t
Thanks — I hear your frustration. You're seeing
update_chat_ctx()
trigger a reply because the Realtime session is configured to auto-generate responses when context changes or when it detects turns. Here’s how to prevent that while still making the model "know" the system message. Why it replies • Some Realtime setups auto-create responses when new context is pushed or when turn-detection/auto-response is enabled. So calling
update_chat_ctx()
can indirectly cause the model to respond even if you don't call
generate_reply()
. What you can do • Always call
update_chat_ctx()
so the model receives the system message. • Disable the model's auto-response behavior (turn-detection / create_response) so updates don't generate replies automatically. • If you can't disable auto-response globally, push the context and immediately suppress/ignore any auto-generated reply, or use a server-side flag to mark the update as "silent." Practical options • Disable auto-response (recommended): ◦ Set the Realtime turn-detection or server VAD option to not create responses (e.g.,
create_response=False
or equivalent) so context syncs silently. Then call
generate_reply()
only when you want a response. • If disabling isn't available: ◦ Call
update_chat_ctx()
as usual, then ignore or discard the immediate auto-generated response and only use replies you trigger explicitly. • Use an explicit "silent" update API or metadata if your SDK supports it (some implementations allow sending context updates with a flag that prevents auto-generation). Concise code pattern 1. Ensure auto-response is off. 2. Sync context:
Copy code
await self.update_chat_ctx(chat_ctx)  # model sees system message
# do NOT call generate_reply() unless you want a response
If you tell me which SDK/version or the exact Realtime options you have available (e.g., turn-detection settings or whether
create_response
is exposed), I’ll give the exact flag or code snippet to turn off auto-responses.
l
I want VAD to trigger a reply automatically, but not system messages. Is this possible?
t
Yes — that is possible. Acknowledging your goal: you want VAD (user speech) to auto-trigger replies, but system messages to be added silently (not cause an immediate reply). What to do • Add system messages with role="system" (or "assistant") to the chat context — these do not count as user turns and will not trigger VAD-based auto-replies. • Ensure VAD/turn-detection remains enabled so transcribed user speech is injected as
role="user"
, which will continue to auto-generate replies. • Do not rely on local-only updates; push the system message into the Realtime session with the session/context API so the model actually sees it but is still treated as a system message. Practical patterns 1) Silent system update (recommended)
Copy code
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(role="system", content=message)
# Push the context so the model knows it, but don't call generate_reply()
await self.update_chat_ctx(chat_ctx)
# Do not call session.generate_reply() here — VAD (user speech) will still create replies
2) If update_chat_ctx() currently auto-generates responses in your setup • Turn off automatic response for context pushes (set the turn-detection/create_response flag so updates don't auto-generate), while keeping VAD-based create_response=True. ◦ Example conceptual flags: ▪︎ For VAD turns: create_response=True ▪︎ For context updates: create_response=False • If your SDK doesn't expose per-update flags, push the system message as role="system" via the agent/chat API (not as a user/turn) — the platform treats system messages as non-user turns and won’t trigger VAD behavior. 3) Fallback if you cannot change auto-response behavior • Push the system message and immediately discard/ignore any auto-generated reply produced by that push, relying instead on VAD-triggered replies for user speech. • Or add a metadata flag with the message (e.g.,
silent: true
) and have your app ignore model outputs produced in response to messages tagged silent. If you tell me which SDK/version and which flags/methods you currently have available (for example, whether
turn_detection
or a
create_response
option is exposed, or whether
update_chat_ctx()
accepts metadata), I’ll give the exact flag names and a tailored snippet. Sources: Pipeline nodes and hooks | LiveKit docs | Improving voice AI's turn detection with transformers | Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs
l
I am using the python SDK. Show me how so set the flags so system messages do not create responses but user ones do
t
Acknowledging your goal: you want VAD (user speech) to auto-trigger replies, but system messages to be added silently (no auto-reply). With the Python SDK you control this by where/how you push context and by letting VAD-driven user turns be the only place you call reply generation. Short answer • Add system messages with
role="system"
and sync them with
update_chat_ctx()
so the model sees them. • Ensure you only call
session.generate_reply()
(or equivalent) from the user-turn handler (e.g.,
on_user_turn_completed
) when VAD/STT injects a
role="user"
message. • If your Realtime setup auto-generates on any context push, disable auto-response for context pushes and keep it enabled for VAD turns (see flags below). Concrete patterns 1) Normal / recommended (system messages silent, VAD triggers replies)
Copy code
# add system message and sync so model knows it (no immediate reply)
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(role="system", content=message)
await self.update_chat_ctx(chat_ctx)
# DO NOT call generate_reply() here
Then in your VAD/user-turn handler:
Copy code
async def on_user_turn_completed(self, turn_ctx, new_message):
    # new_message will be role="user"
    await self.session.generate_reply()   # VAD triggers this — agent speaks
2) If update_chat_ctx() currently causes an automatic reply • Prefer per-turn flags if your SDK exposes them: ◦ For VAD turns: set create_response=True ◦ For context updates: set create_response=False • Example conceptual usage (SDK method names may vary):
Copy code
# push system context silently
await self.update_chat_ctx(chat_ctx, create_response=False)

# VAD configured to create responses
# (turn detection / VAD remains create_response=True by default)
3) Fallback if no per-update flag exists • Push the system message, then immediately discard any auto-generated reply produced by that push; only honor replies generated from
on_user_turn_completed
. • Or attach metadata
silent: true
when adding the system message and have your app ignore outputs associated with silent updates. What I need to give exact code • Which Python SDK version you’re using and whether you’re using a Realtime LLM (e.g., OpenAI Realtime) or non-realtime model. Also tell me whether
update_chat_ctx()
in your SDK accepts a
create_response
or similar flag. With that I’ll provide the exact call signatures and a copy-paste snippet. Sources: Pipeline nodes and hooks | LiveKit docs