how to transfer the chat history from one agent to...
# ask-ai
w
how to transfer the chat history from one agent to another agent when session is transferred from one agent to another agent?
t
Thanks for reaching out, Sunil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you help me understand a bit better? Are you asking about transferring chat history within a specific LiveKit feature or integration? For example, are you using LiveKit's chat functionality directly, or is this part of a custom setup or a third-party integration? I’m here to help you through this!
w
I have multiple agents. for this example, let us say Agent1 is handling the session and has a conversation history. when Agent1 is transferring call to Agent2, the conversation history of Agent1 should be sent to Agent2 so that Agent2 can begin from where Agent2 has ended.
t
Are you using LiveKit's built-in chat functionality, or is this part of a custom implementation or integration with another system? I want to make sure I understand your setup so I can offer the best possible guidance for you.
w
both are voice agents
both are livekit voice agents
t
To transfer the conversation history between LiveKit voice agents during a session transfer, you can pass the
chat_ctx
(chat context) from the current agent to the new agent. Here’s how you can implement this: • Direct Chat Context Handoff: Pass the existing
chat_ctx
to the new agent during the transfer. For example, in Python: `@function_tool() async def transfer_to_technical_support(self): await self.session.generate_reply(instructions="Inform the customer that you're transferring them to the technical support team.") return TechnicalSupportAgent(chat_ctx=self.session.chat_ctx)`This ensures the new agent inherits the full conversation history, making the transition smooth and seamless. • Context Summarization: If you'd like, you can also summarize the conversation for the new agent by iterating over the
chat_ctx.items
to create a helpful summary. This approach works really well for warm transfers to human agents or supervisors, keeping everyone on the same page. • Custom Session State: For workflows involving multiple agents, you might consider implementing a base class to preserve and truncate context during transfers. This way, you can include just the most recent messages, ensuring the new agent has the most relevant information. Please feel free to reach out if you'd like more details or need a hand with implementing any of these methods. I'm here to help! Sources: Workflows | LiveKit Docs | Workflows | LiveKit Docs | Agent-assisted warm transfer | LiveKit Docs | examples/warm-transfer/warm_transfer.py | complex-agents/medical_office_triage/triage.py