I am trying to update the system prompt in real ti...
# ask-ai
m
I am trying to update the system prompt in real time I want to understand the difference in using
update_instructions
and
update_chat_ctx
t
Thanks for reaching out, Somil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — this is a great question. You want to update the system prompt in real time, so here’s a clear distinction between the two methods and when to use each. • update_instructions ◦ What it does: Replaces or changes the agent’s system prompt (the instructions that define the agent’s identity, role, and primary task). ◦ When to use it: Use this when you want the agent’s overall behavior or purpose to change — for example switching from “gather customer information” to “handle billing inquiries,” or changing tone/role (helpful assistant → strict auditor). ◦ Effect: Affects how the agent interprets and responds to all future messages because the core directive has changed. • update_chat_ctx ◦ What it does: Adds to or edits the conversation history / chat context (messages, facts, corrections) without changing the agent’s core instructions. ◦ When to use it: Use this to inject new information, correct earlier messages, or provide contextual facts that should influence the current conversation but do not change the agent’s role. For example: adding a user-provided fact, correcting a previously stated date, or inserting recent transaction details. ◦ Effect: Influences the next replies by updating the context the agent uses, while the agent’s fundamental objective remains the same. Guidance on choosing between them • If you want the agent to behave differently overall (new role, goal, personality) — use update_instructions. • If you only need to adjust what the agent knows for the current thread or fix/augment the dialogue — use update_chat_ctx. If you’d like, tell me which change you’re trying to make (example system prompt text, or the contextual info you want injected) and I can suggest the exact call sequence and what to expect after applying it. Sources: Tool definition and use | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation
m
Copy code
if updated_instructions != self.instructions:
            await self.update_instructions(updated_instructions)
This is my current snippet now if I had to update the system prompt using update_chat_ctx how should I do it ?
t
Thanks — I see your snippet and that you want to switch from calling
update_instructions
to using
update_chat_ctx
to accomplish a live change to what the agent "knows" or follows. Important note up front:
update_chat_ctx
updates the conversation history (chat messages), not the agent's core system instructions. You can simulate a system prompt change by inserting a new system-role message into the chat context (a system message has the same effect as a system prompt for subsequent responses), but this does not literally replace the agent's stored
instructions
. Use this approach when you want the agent to behave as if its system prompt has changed for the remainder of the conversation, without calling
update_instructions
. Below is an example pattern that adapts your snippet to add a system message via
update_chat_ctx
. It: • Checks if the desired "system prompt" text differs, • Inserts a system-role message into the chat context, • Leaves
self.instructions
unchanged (unless you still want to update that separately).
Copy code
# pseudocode / example
if updated_instructions != self.instructions:
    # create a system-role message to inject into chat context
    system_message = {
        "role": "system",
        "content": updated_instructions
    }

    # call update_chat_ctx to append or replace messages in the conversation history
    # exact API params may vary — adapt to your method signature
    await self.update_chat_ctx(messages=[system_message])

    # optional: keep local copy in case you want to track that you've injected this
    # self.last_injected_system = updated_instructions
Notes and recommendations • Use a system-role message (
"role": "system"
) so the model treats it like a system prompt for following replies. • Decide whether to append the system message or replace prior system messages in the chat context. Appending allows history preservation; replacing avoids multiple conflicting system messages. If your
update_chat_ctx
supports editing specific messages, consider replacing the previous system message instead of appending. • If you truly need to update the agent's underlying instruction state (so other components that read
self.instructions
see the change), continue to update
self.instructions
as well. Injecting into
chat_ctx
affects only the model's next outputs, not stored instruction variables elsewhere. • After injecting, test a quick prompt to confirm the new system message influences responses as you expect. If you want, share the exact signature of your
update_chat_ctx
call or the client SDK you're using and I’ll provide an exact code example that replaces the previous system message instead of appending.