Agent-as-Tool Embedding
Wrap a sub-agent behind a single function-shaped tool signature — the parent calls it like any other tool and never sees the sub-agent's internal turns.
def sub_agent(task: str) -> Result. The parent calls it like any other tool; inside the wrapper, a full agent loop with its own model, tool palette, and step budget runs to completion and returns a structured result. The parent’s context sees only the call and the return value — never the sub-agent’s intermediate turns.Intent & Description
🎯 Intent
Wrap a sub-agent (with its own loop, prompt, and tool palette) behind a single function-shaped tool signature so the parent agent calls it like any other tool and never sees the sub-agent’s internal turns.
📋 Context
A parent agent hits a bounded sub-task — search the web and summarize findings, plan a multi-day itinerary, audit a directory of files — that deserves its own focused loop with its own model, tool palette, and step budget. The parent doesn’t need to watch the sub-task being solved; it only needs the answer.
💡 Solution
Define the sub-agent as def sub_agent(task: str, ...) -> Result. Inside the function: a fresh agent loop with its own model, tool palette, and step budget runs to completion or failure, returning a structured result. Parent context records only the call and the return value. Step budget and timeout are enforced by the wrapper, not by the sub-agent’s prompt.
Real-world Use Case
- A sub-task is well-scoped enough that the parent should see only its result, not its intermediate turns.
- Putting the sub-agent’s internal state into parent context would bloat tokens or couple parent reasoning to sub-agent internals.
- The sub-agent has its own model, tool palette, or step budget that should not leak into the parent loop.
Source
📌 TL;DR
Wrap a full sub-agent loop behind a function signature — the parent calls it like a tool and gets back a result, with all intermediate complexity hidden inside.
Advantages
- Clean composition without ad-hoc multi-agent infrastructure.
- Parent context stays small and stable — no intermediate turn pollution.
- Sub-agent can be swapped or upgraded behind the same function signature.
Disadvantages
- Hidden costs — sub-agent failures or timeouts surprise the parent at call time.
- Debugging requires traceability across the boundary; the parent only sees the return value.
- Recursive nesting can spiral cost if a sub-agent itself spawns more sub-agents.