> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Handoffs

> Split a workflow across specialized agents and switch control between them.

Agent handoffs let you split complex workflows across specialized agents. The primary agent detects intent and calls a `function_tool` to hand control to the right agent, which completes the request.

## Handoff vs Transfer

"Handoff" and "transfer" are easy to confuse. They differ in who receives the conversation and whether context is passed along.

| Term                               | Conversation moves to                                      | Context passed                  | Covered in                                      |
| :--------------------------------- | :--------------------------------------------------------- | :------------------------------ | :---------------------------------------------- |
| **Agent Handoff**                  | Another **AI agent** in the same session                   | Optional, via `inherit_context` | This page                                       |
| **Agent Transfer** (Call Transfer) | A **human or another phone number**, connected immediately | No                              | [Call Transfer](/build/telephony/call-transfer) |

In short: a **handoff between agents** keeps the conversation with the bot and only switches which agent is in control. A **transfer** hands the live call to a person. A transfer is **cold** when the person is connected with no briefing, and **warm** when they receive context before the call connects.

## Context Sharing

When switching agents, the `inherit_context` flag controls whether the new agent is aware of the previous conversation.

| Value                             | Behavior                                      | When to Use                                                     |
| --------------------------------- | --------------------------------------------- | --------------------------------------------------------------- |
| `inherit_context=True`            | The new agent receives the full chat context. | Maintaining continuity so the user does not repeat information. |
| `inherit_context=False` (default) | The new agent starts with a fresh state.      | Switching to a completely unrelated task.                       |

## Example

A travel agent hands off to a booking specialist from a function tool, passing the
conversation context along. The handoff is driven by the tool's **return value**: return the
next `Agent` instance (constructed with `inherit_context=True`).

<CodeGroup>
  ```python title="Python" Python theme={null}
  from zeroruntime import Agent, function_tool

  class TravelAgent(Agent):
      def __init__(self):
          super().__init__(
              agent_id="travel",
              instructions="You are a travel assistant. Help with travel questions and guide users to booking.",
          )

      @function_tool()
      async def transfer_to_booking(self) -> Agent:
          """Transfer the user to a booking specialist."""
          # Returning an Agent instance performs the handoff;
          # inherit_context=True passes the existing chat context.
          return BookingAgent(inherit_context=True)

  class BookingAgent(Agent):
      def __init__(self, inherit_context: bool = False):
          super().__init__(
              agent_id="booking",
              instructions="You are a booking specialist. Help users book or modify reservations.",
              inherit_context=inherit_context,
          )
  ```

  ```typescript title="Node JS" Node JS theme={null}
  import { Agent, function_tool } from '@zeroruntime/js-sdk';

  class BookingAgent extends Agent {
    constructor(inherit_context = false) {
      super({
        agent_id: 'booking',
        instructions: 'You are a booking specialist. Help users book or modify reservations.',
        inherit_context,
      });
    }
  }

  class TravelAgent extends Agent {
    constructor() {
      super({
        agent_id: 'travel',
        instructions:
          'You are a travel assistant. Help with travel questions and guide users to booking.',
      });
    }

    transfer_to_booking = function_tool({
      name: 'transfer_to_booking',
      description: 'Transfer the user to a booking specialist.',
      parameters: {},
      // Returning an Agent performs the handoff; inherit_context passes the
      // existing chat context to the agent taking over.
      execute: async () => new BookingAgent(true),
    });
  }
  ```
</CodeGroup>

`inherit_context` controls whether the receiving agent starts with the full chat context
(continuity) or a clean slate (unrelated task).

## What's Next

<CardGroup cols={2}>
  <Card title="Context Window" icon="window-maximize" href="/build/context-management/context-window">
    Manage conversation history automatically.
  </Card>

  <Card title="Context Management" icon="brain" href="/build/context-management/access-context">
    How ChatContext records conversation memory.
  </Card>
</CardGroup>

## References

<Tabs>
  <Tab title="Python">
    #### Examples

    <CardGroup cols={2}>
      <Card title="Multi-Agent Switch" icon="github" href="https://github.com/ZeroRuntimeAI/zeroruntime-python-examples/blob/main/context/multi_agent_switch.py">
        Switch control between multiple agents.
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Node JS">
    #### Examples

    <CardGroup cols={2}>
      <Card title="Multi-Agent Switch" icon="github" href="https://github.com/ZeroRuntimeAI/zeroruntime-js-examples/blob/main/context/multi_agent_switch.ts">
        Switch control between multiple agents.
      </Card>
    </CardGroup>
  </Tab>
</Tabs>
