little-kite-91953
10/14/2025, 9:42 AMtall-airline-16756
10/14/2025, 9:43 AMtall-airline-16756
10/14/2025, 9:43 AMConversationItemCreateEvent with a SystemItem that carries your system message, which gently guides the AI's behavior and responses.
Here’s a simple way to do it:
1. Define the System Message: Start by creating a SystemItem with this structure:
{
"type": "message",
"role": "system",
"content": [
{
"type": "input_text",
"text": "Your system message here."
}
]
}
2. Create the Event: Next, use the conversation.item.create event to add your system message into the conversation context:
{
"type": "conversation.item.create",
"item": {
"type": "message",
"role": "system",
"content": [
{
"type": "input_text",
"text": "You are a helpful assistant."
}
]
}
}
3. Send the Event: If you’re working with JavaScript, you can send the event through the real-time model’s websocket connection like this:
await model.sendEvent({
type: 'conversation.item.create',
item: {
type: 'message',
role: 'system',
content: [{ type: 'input_text', text: 'Adjust your tone to be more formal.' }],
},
});
And if Python is your language of choice, the livekit.plugins.openai.realtime.utils.livekit_item_to_openai_item function is a handy tool to help you create a compatible system message.
If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
Sources: plugins/openai/src/realtime/realtime_model.ts | LLM Integration & Real-time Models | livekit/livekit_composite | DeepWiki | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | OpenAI Realtime API plugin guide | LiveKit Docslittle-kite-91953
10/14/2025, 9:53 AMtall-airline-16756
10/14/2025, 9:54 AMllm.ChatContext class. This helps keep things smooth and uniform whether you’re working with OpenAI, LangChain, or AWS.
Here’s a simple guide to get you started:
1. Create a Chat Context: Begin by using the llm.ChatContext class to set up your system messages:
from livekit.agents import llm
chat_ctx = llm.ChatContext()
chat_ctx.add_message(role="system", content="You are a helpful AI assistant.")
2. Multiple System Messages: You can layer your instructions by adding several system messages:
chat_ctx.add_message(role="system", content="Always respond in a professional tone.")
chat_ctx.add_message(role="system", content="Focus on providing accurate technical information.")
3. Provider-Agnostic Handling: The great part is that LiveKit automatically adapts these system messages to fit the right format for whichever AI model you’re using, whether it’s OpenAI, AWS, or LangChain.
If you’d like, I’m here to help with more details or examples tailored to your specific integration—just let me know!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | LangChain integration guide | LiveKit Docslittle-kite-91953
10/14/2025, 10:55 AMtall-airline-16756
10/14/2025, 10:56 AMupdate_instructions() method to set persistent system-level instructions:
await activity.update_instructions("You are a helpful AI assistant.")
2. Check Chat Template Compatibility: It’s a good idea to confirm that the AI model’s chat template supports system messages. Some templates might not recognize system roles unless they’re explicitly supported.
3. Use update_chat_ctx() for Initial Context: If you want to set system messages right at the start of a session, you can use update_chat_ctx() to inject that initial context:
initial_ctx = llm.ChatContext()
initial_ctx.add(llm.ChatMessage(role="system", text="You are a helpful assistant."))
await model.update_chat_ctx(initial_ctx)
4. Verify Model-Specific Behavior: Keep in mind that different models handle system messages in their own ways. For example, the OpenAI Realtime API maps system messages to realtime.ConversationItemSystemMessage, while others might need specific formatting.
If you’d like, I’m here to help you implement these changes or troubleshoot any issues further. Just let me know!
Sources: client/lib/chat/actions.tsx | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Pipeline nodes and hooks | LiveKit Docs | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | tests/test-chat-template.cpplittle-kite-91953
10/14/2025, 11:02 AMtall-airline-16756
10/14/2025, 11:03 AMupdate_chat_ctx() method, which lets you insert messages into the chat history for the AI to consider during your conversation.
Here’s a simple way to get started:
1. Copy the Current Chat Context: It’s a good idea to copy the existing chat context first so you won’t accidentally overwrite any other messages.
chat_ctx = self.chat_ctx.copy()
2. Add a System or Developer Message: Then, use the add_message method to add your message:
chat_ctx.add_message(
role="system",
content="You are now in troubleshooting mode."
)
3. Update the Chat Context: Finally, save your changes by calling `update_chat_ctx()`:
await self.update_chat_ctx(chat_ctx)
This way, your message becomes part of the conversation history and helps guide the AI’s responses. If you’d like, I’m here to walk you through more examples or answer any other questions you have!
Sources: livekit/agent/livekit_agent_session.pb.go | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | docs/index.yaml | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | Pipeline nodes and hooks | LiveKit Docs