do you have more doc about 1. 2. *Selective Cont...
# ask-ai
s
do you have more doc about 1. 2. Selective Context Transfer: If you want more control, you can truncate or filter the chat context before passing it along to the new agent.
new_chat_ctx = self.session.chat_ctx.truncate(max_items=20)
3.
return NewAgent(chat_ctx=new_chat_ctx)
t
Thanks for reaching out, MBMBMB. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
LiveKit offers several thoughtful ways to handle selective context transfer, making sure your conversations stay relevant and efficient: • Truncating Context: You can use the
before_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