Skip to main content
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

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?")
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 — so you can see the full tree, token usage, and timings across all agents in one place.