square-activity-46232
07/07/2025, 7:11 PMtall-airline-16756
07/07/2025, 7:11 PMtall-airline-16756
07/07/2025, 7:12 PMupdate_instructions
function: This function updates an existing instruction message or inserts a new one if it's missing. Example:`update_instructions(chat_ctx, instructions="Your new system prompt here", add_if_missing=True)`
• Directly modifying the chat context: You can update an existing system message or insert a new one at the beginning of the chat context. Example:`system_msg = chat_ctx.items[0]
if isinstance(system_msg, llm.ChatMessage) and system_msg.role == "system":
system_msg.content.append("Your new instructions here")
else:
chat_ctx.items.insert(0, llm.ChatMessage(role="system", content=["Your new instructions here"]))`
• Using the SystemItemCreate
interface: This allows you to create a system message by specifying the content, role (set to "system"), and type (set to "message").
These methods help redirect or reinforce the conversation effectively.
Sources: GitHub::livekit::agents | examples/voice_agents/llamaindex-rag/retrieval.py | SystemItemCreate | LiveKit Agents