How to allow user (participant) to disconnect and ...
# ask-ai
i
How to allow user (participant) to disconnect and then reconnect to the same room (same session), with past conversation attached?
t
Thanks for reaching out, Jan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To allow a user to disconnect and reconnect to the same room while preserving the past conversation, you can use the
chat_ctx
parameter when initializing an agent. This ensures that the conversation history is retained across sessions. Here’s how you can implement this: 1. When initializing an agent, pass the chat context from the previous session:
Copy code
class HelpfulAssistant(Agent):
    def __init__(self, chat_ctx: ChatContext):
        super().__init__(
            instructions="You are a helpful voice AI assistant.",
            chat_ctx=chat_ctx  # This preserves the conversation history
        )
2. When performing a handoff between agents, pass the chat context:
Copy code
@function_tool()
async def on_consent_given(self):
    """Use this tool to indicate that consent has been given and the call may proceed."""
    # Pass the chat context during handoff
    return HelpfulAssistant(chat_ctx=self.session.chat_ctx)
By default, each new agent starts with a fresh conversation history. To include the prior conversation, set the
chat_ctx
parameter in the
Agent
constructor. Additionally, the complete conversation history for the session is always available in
session.history
, which you can access if needed. Sources: Workflows | LiveKit Docs