# 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.

- **Category**: Agentic AI
- **Subcategory**: Multi-Agent
- **Canonical URL**: https://designpattern.fyi/patterns/agent_as_tool_embedding/

---

## 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.



## Use Cases
- 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.






## Trade-offs


### 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.




### Considerations & Drawbacks

- 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.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/agent-as-tool-embedding/)

