How can I add a system prompt while the conversati...
# ask-ai
s
How can I add a system prompt while the conversation is ongoing to redirect o reinforce where te conversation should be headed?
t
Thanks for reaching out, Roman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To add a system prompt during an ongoing conversation in LiveKit, you can use the following methods: • Using the
update_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