how to skip user message and agent message to upda...
# ask-ai
l
how to skip user message and agent message to update in chat context
✅ 1
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you want to skip (exclude) user and agent messages when updating the chat context. Quick answer and options: • You cannot directly mutate the live
ChatContext
. Create a copy, filter out the messages you want to skip, then update or use that copy for the next action. • Use the
copy()
helpers to exclude common categories: ◦ exclude_instructions / excludeInstructions — omit system/developer prompts ◦ exclude_function_call / excludeFunctionCall — omit tool/function calls ◦ exclude_handoff / excludeHandoff — omit handoff markers ◦ exclude_empty_message / excludeEmptyMessage — omit empty messages ◦ exclude_config_update (Python) — omit agent config updates Examples: 1. Python (exclude instructions & function calls)
Copy code
next_ctx = self.chat_ctx.copy(exclude_instructions=True, exclude_function_call=True)
1. Node.js (same)
Copy code
const nextAgentCtx = this.chatCtx.copy({ excludeInstructions: true, excludeFunctionCall: true });
• To remove specific user or agent turns beyond those categories, call
copy()
, then programmatically filter the returned messages (e.g., drop items where role === 'user' or role === 'assistant'), and either: ◦ pass that filtered
chat_ctx
into
generate_reply()
for a single reply, or ◦ call
update_chat_ctx()
with the modified snapshot to apply changes. If you tell me whether you’re using Python or Node.js and whether you want this only for a single reply or to permanently update the stored context, I’ll give the exact code snippet for your case. Sources: How to Build a Background Observer for Voice AI Guardrails | LiveKit | Chat context | LiveKit Documentation | Agent speech and audio | LiveKit Documentation | Agents and handoffs | LiveKit Documentation, with interactive elements