how does session.update_agent differ from returnin...
# ask-ai
r
how does session.update_agent differ from returning an agent from a tool?
t
Thanks for reaching out, Trevor. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how
session.update_agent
differs from returning an agent from a tool — here’s a concise comparison and when to use each. • Initiator ◦ Returning an agent from a tool: initiated by the LLM during tool execution (model-driven). ◦ `session.update_agent`: initiated by developer code (programmatic). • Flow ◦ Returning from a tool: tool runs, returns a new Agent (or handoff object); framework performs the handoff after the tool completes and any LLM reply. ◦ `session.update_agent`: code calls
session.update_agent(new_agent)
and the handoff happens immediately without a tool or LLM step. • Use cases ◦ Returning from a tool: use when the LLM should decide to route the conversation (dynamic, context-based routing). ◦ `session.update_agent`: use when your application logic or external events determine the handoff (state, timers, event handlers). • Platform/availability ◦ Returning from a tool: supported in both Node.js (via
llm.handoff()
) and Python. ◦ `session.update_agent`: available in Python only. • Side effects ◦ Both result in a new active agent and room-wide sync; returning from a tool also emits a
conversation_item_added
AgentHandoff item as part of the chat history. Which do you want to implement? I can show a short Python example for
session.update_agent
or a tool-return handoff example depending on your use case. Sources: Agents and handoffs | LiveKit docs | Agent session | LiveKit docs | Agents (Python) | livekit/livekit_composite | DeepWiki