millions-greece-12478
10/10/2025, 2:25 AMtall-airline-16756
10/10/2025, 2:25 AMtall-airline-16756
10/10/2025, 2:25 AMllm.ChatContext object containing earlier conversation messages through the chat_ctx parameter. This way, your agent starts off with a meaningful context.
• Update Context of a Running Agent: If your session is already active, you can use the update_chat_ctx() method to dynamically refresh the current context. This updates both the local and server-side contexts seamlessly.
• Reuse Context from Previous Sessions: Once a session ends, you can grab the conversation history using session.chat_ctx_copy() and then pass it along to a new agent instance to keep the conversation flowing smoothly.
Just a quick note: Gemini Realtime doesn’t support removing messages from the chat context. The context works in an additive way, so you can add or replace the full context but can’t delete individual messages.
If you’d like, I’m here to provide more details or walk you through some examples—just let me know!
Sources: Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | agent/main.py | plugins/google/src/beta/realtime/realtime_api.ts | Agents v0.x migration guide - Python | LiveKit Docs | complex-agents/personal_shopper/README.mdmillions-greece-12478
10/10/2025, 2:31 AMmillions-greece-12478
10/10/2025, 2:31 AMtall-airline-16756
10/10/2025, 2:31 AMllm.ChatContext.fromMessages to build a new chat context with the messages you want to include.
4. Update the Chat Context: Then, call session.updateChatCtx(updatedChatContext) to apply your new context. This will update both the local and server-side context seamlessly.
Here’s an example to make it clearer:
import { RealtimeModel, RealtimeSession } from '@livekit/agents';
import * as llm from '@livekit/agents/llm';
const model = new RealtimeModel({
instructions: "You are a helpful assistant.",
model: 'gemini-2.0-flash-live-001',
voice: 'Puck',
temperature: 0.8,
});
const session: RealtimeSession = model.session();
const updatedChatContext = llm.ChatContext.fromMessages([
llm.ChatMessage.create({ role: 'user', content: 'Hello, I want to ask about weather.' }),
llm.ChatMessage.create({ role: 'assistant', content: 'I can help with that.' }),
]);
await session.updateChatCtx(updatedChatContext);
Just a quick note: Gemini Realtime doesn’t currently support removing messages from the chat context, so be sure to keep the full conversation history when you update.
If you run into any issues or have questions along the way, please don’t hesitate to reach out—I’m here to help you!
Sources: plugins/google/src/beta/realtime/realtime_api.ts | examples/voice_agents/README.md | agent/main.pymillions-greece-12478
10/10/2025, 2:32 AMfromMessages. Let me check if it’s a constructor or different method:millions-greece-12478
10/10/2025, 2:34 AMCannot read properties of undefined (reading 'push') - the ChatContext doesn’t have a messages array initialized. And it’s still timing out, which means even attempting to call updateChatCtx is breaking the session.
The fundamental issue: We’re trying to update the chat context AFTER the session has started and after the greeting has been sent. This corrupts Gemini’s state.