<#C088ZNU7QQ5|ask-ai> Please explain, from a techn...
# ask-ai
c
#ask-ai Please explain, from a technical standpoint, the difference between agent handoffs and tasks. Since both can have distinct sets of instruction and tools, my interest is particularly in context management and pipeline components. Under which circumstances will the websocket connections to external services be reestablished? Also, please explain this sentence from the docs "Unlike agents, tasks do not persist; they take temporary control only while executing.". What does the "do not persist" part mean?
t
Thanks for reaching out, tscdl. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking for a technical comparison of agent handoffs vs tasks with emphasis on context management, pipeline components, when external WebSocket connections are (re)established, and what "do not persist" means. I'll address each point directly. 1) High-level distinction • Agent handoff: a transfer of control from one long-lived Agent instance to another. The new agent receives a reference to the prior agent's
ChatContext
and becomes the ongoing controller of the session. Agents persist for the lifetime of their control over the session and can maintain instructions, tools, and conversational flow long-term. • Task: a short-lived, stateless execution unit created by an agent to complete a specific objective and return a typed result. A task temporarily takes control of execution, runs to completion (or error), returns its result to the parent agent, and is then destroyed. 2) Context management • Agents keep session-level state: each Agent is associated with an
AgentSession
and a
ChatContext
that represent ongoing conversational context, toolsets, and instructions. That state persists across turns while the agent remains active. • Tasks run within the parent agent's session context: a task sees and can operate on the current
AgentSession
and pipeline context while it runs, but it does not become a persistent owner of that state. When a task completes, the parent agent resumes with any results the task returned. Tasks do not retain or continue evolving context after completion. 3) Pipeline components and tools • Agents define their toolset and instruction set persistently while active; they can call tools and orchestrate pipelines across many turns. • Tasks may declare their own temporary tools and instructions to accomplish their single objective. Those tools/instructions are scoped to the task's lifetime. Pipeline components (LLM, STT, TTS, plugins) are used via the same session-level plumbing; tasks reuse the session’s pipeline rather than creating an independent, persistent pipeline. 4) WebSocket connections to external services (when they are reestablished) • WebSocket connections to external services (LLM providers, STT/TTS plugins, etc.) are managed per-session by the
AgentSession
. Because both handoffs and tasks operate within the same `AgentSession`: ◦ A handoff does not by itself close or reestablish those connections—the
AgentSession
continues, so existing WebSocket connections persist and are reused. ◦ A task likewise does not cause connections to be dropped or re-created; it uses the active session connections while executing. • Connections are only reestablished if the underlying connection is severed (network errors, timeouts, provider-side disconnects) or explicitly replaced/overridden by configuration. The lifecycle of agents vs tasks does not trigger automatic reconnection. 5) What "do not persist" means for tasks • "Do not persist" means tasks are ephemeral: they exist only for the duration of their execution. They do not remain registered as active controllers of the session, they do not maintain ongoing state after completion, and they do not continuously listen or react to new events once finished. Any state produced by a task is returned to the initiating agent; if persistent behavior is needed, the agent (or a long-lived agent instance) must own that state. If you'd like, I can: • Show an example sequence of messages and session state during a handoff vs during a task run. • Outline how to design tools/instructions when you need persistent behavior vs one-off operations. Sources: Agents and handoffs | LiveKit docs | Workflows | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Tasks and task groups | LiveKit docs
c
Perfect, thanks. So we could summarize that the big conceptual difference is actually the way state access and persistance is handled?
SomeTask(AgentTask[bool])
- all it care about is the boolean state prop. While an
Agent()
accesses AgentSession[SomeMainStateObject] As a result, if I manage state independently from Session, Agent and Task - what difference remains?
t
You're right that state access and persistence are the central conceptual difference. If you move state outside of Session/Agent/Task, here are the remaining practical differences to keep in mind: • Ownership & control ◦ Agent: long-lived controller of session flow — owns which tools/instructions are active, when to call tasks, and how to react to external events over time. ◦ Task: short-lived executor that temporarily seizes control to perform a single operation and returns a result. • Lifecycle & event handling ◦ Agent: persists across turns, can continue to receive and handle new events, push updates, or react to external inputs. ◦ Task: runs to completion and then is gone; it does not receive new events or continue reacting after it returns. • Tool/instruction scope ◦ Agent: persistent instruction set and tool registration; can update or keep stateful integrations across interactions. ◦ Task: scoped tools/instructions for that run only; any configuration is ephemeral unless the agent persists results externally. • Concurrency and coordination ◦ Agent: can orchestrate multiple tasks, manage queuing, retries, and coordination logic. ◦ Task: single-shot; coordination and concurrency control must be handled by the agent or external orchestrator. • Observability & debugging ◦ Agent: easier to trace session-level history, metrics, and long-running behavior. ◦ Task: ephemeral traces unless you persist logs/state externally. • Error handling and recovery ◦ Agent: can implement retries, fallbacks, and longer-lived recovery logic. ◦ Task: error handling is limited to its execution window; longer recovery must be handled by the agent. If you centralize state externally, tasks become pure workers operating on that state and agents become the orchestrators that maintain session semantics, event handling, coordination, and persistence policies. Would you like a short example showing how an agent would call a task that reads/writes external state and how retries or events are handled?