some-breakfast-27057
09/20/2025, 2:20 PMnew_chat_ctx = self.session.chat_ctx.truncate(max_items=20)
3. return NewAgent(chat_ctx=new_chat_ctx)tall-airline-16756
09/20/2025, 2:20 PMtall-airline-16756
09/20/2025, 2:20 PMbefore_llm_cb callback in VoicePipelineAgent to trim down the message history before it reaches the LLM. For instance, keeping just the last 15 messages can be really helpful.
• Context Transfer Between Agents: The BaseAgent.on_enter method gives you the option to truncate chat context to include only the last N messages, while also letting you keep important system messages or function calls if you wish.
• Filtering During Context Copy: With the copy method of ChatContext, you can exclude things like function calls, instructions, and empty messages. This way, you have fine-grained control over what context gets transferred.
• Explicit Use in Agent Handoff: When doing warm transfers, the TransferAgent can receive a filtered and nicely summarized version of the conversation history by using the copy method with exclusion options and creating a clear textual summary.
These approaches are designed to keep your conversations on point while making the best use of tokens. If you'd like, I’m here to help with more details or walk you through some examples to get you started!
Sources: complex-agents/medical_office_triage/README.md | agents/src/voice/agent_activity.ts | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Agent-assisted warm transfer | LiveKit Docs | VoicePipelineAgent | LiveKit Docs