Please give me instructions on how to handoff and ...
# ask-ai
m
Please give me instructions on how to handoff and initialize to other LiveKit AI agents during a call.
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to guide you through how to handoff and initialize other LiveKit AI agents during a call. Here are some helpful methods you can use: • Python: You can return a tuple containing the new
Agent
instance along with an optional result message. For example:
Copy code
@function_tool()
async def information_gathered(self, context: RunContext, name: str, location: str):
    context.userdata.name = name
    context.userdata.location = location
    return StoryAgent(name, location), "Let's start the story!"
• Node.js: You can use
llm.handoff()
to return the new agent and an optional message. Here’s a simple example:
Copy code
return llm.handoff({
  agent: new SomeAgent(),
  returns: "Transferring the user now"
});
Here are a few key things to keep in mind: • The conversation history is preserved and accessible in
session.history
during handoffs, so nothing gets lost. • You can easily pass user data or context between agents using
context.userdata
or through constructor parameters. • Handoffs are triggered programmatically via tools, but the LLM decides the best moment to invoke them based on how the conversation flows. If you’d like to explore more, the warm transfer example in the LiveKit repository is a great resource to check out. Sources: Tool definition and use | LiveKit docs | Workflows | LiveKit docs | README.md | README.md | Testing and evaluation | LiveKit Docs