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

# Multi-Agent

> Compose specialists by exposing one agent as a tool to another

<Info>
  Source: [`07_agent_as_tool.py`](https://github.com/opper-ai/opper-sdks/blob/main/python/examples/agents/07_agent_as_tool.py), [`08_multi_agent.py`](https://github.com/opper-ai/opper-sdks/blob/main/python/examples/agents/08_multi_agent.py) · [`07-agent-as-tool.ts`](https://github.com/opper-ai/opper-sdks/blob/main/typescript/examples/agents/07-agent-as-tool.ts), [`08-multi-agent.ts`](https://github.com/opper-ai/opper-sdks/blob/main/typescript/examples/agents/08-multi-agent.ts)
</Info>

Use `agent.as_tool(...)` (Python) / `agent.asTool(...)` (TS) to wrap a specialist agent as a callable tool, then attach it to a coordinator. The coordinator decides when to delegate and to whom.

## Coordinator + specialist

<CodeGroup>
  ```python Python theme={null}
  from opperai.agent import Agent

  geographer = Agent(
      name="geographer",
      instructions="You are a geography expert. Be precise and concise.",
  )

  coordinator = Agent(
      name="coordinator",
      instructions=(
          "You are a helpful assistant. For geography questions, "
          "use the geography_expert tool. Otherwise answer directly."
      ),
      tools=[
          geographer.as_tool(
              name="geography_expert",
              description="Ask a geography expert. Pass the full question as input.",
          ),
      ],
  )

  result = await coordinator.run("What are the three largest countries by area?")
  ```

  ```typescript TypeScript theme={null}
  import { Agent } from "opperai";

  const geographer = new Agent({
    name: "geographer",
    instructions: "You are a geography expert. Be precise and concise.",
  });

  const coordinator = new Agent({
    name: "coordinator",
    instructions:
      "You are a helpful assistant. For geography questions, " +
      "use the geography_expert tool. Otherwise answer directly.",
    tools: [
      geographer.asTool({
        name: "geography_expert",
        description: "Ask a geography expert. Pass the full question as input.",
      }),
    ],
  });

  const result = await coordinator.run("What are the three largest countries by area?");
  ```
</CodeGroup>

The sub-agent's tool input is a single string (the prompt). Its output is `{ output, usage, iterations, ... }`, which is captured in the coordinator's `result.meta.tool_calls`.

## Pipelines

Stack multiple specialists under one coordinator (researcher → writer → editor, etc.). The coordinator chooses the order based on its instructions. See `08_multi_agent` for a three-agent editorial pipeline.

## Tracing

When tracing is enabled (default), sub-agent calls appear as nested `SubAgent` spans under the coordinator's run. You get the full tree, token usage, and timings for every agent in one place.
