@@ -69,6 +69,93 @@ async def url_match(url: str) -> EvaluationResult:
6969# Agents call: evaluators(name="url_match", arguments={"url": "..."})
7070```
7171
72+ # # Agent Tools
73+
74+ # ## AgentTool
75+
76+ ```python
77+ from hud.tools import AgentTool
78+ ```
79+
80+ Wraps a scenario as a tool that can be called by another agent. Essential for building ** hierarchical agent systems** where an orchestrator delegates to specialized subagents.
81+
82+ ** Constructor Parameters:**
83+ | Parameter | Type | Description | Default |
84+ | ---------- - | ------ | ------------ - | -------- - |
85+ | `task` | `Task` | Task template from `env(" scenario_name" )` | Required |
86+ | `model` | `str ` | Model for subagent (via gateway) | `None ` |
87+ | `agent` | `type[MCPAgent]` | Custom agent class | `None ` |
88+ | `agent_params` | `dict ` | Additional agent parameters | `{}` |
89+ | `name` | `str ` | Tool name for orchestrator | From scenario |
90+ | `description` | `str ` | Tool description | Auto- generated |
91+ | `trace` | `bool ` | Enable tracing for standalone runs | `False ` |
92+
93+ < Note> Must provide either `model` or `agent` , not both.< / Note>
94+
95+ ** Eval- Only Parameters:**
96+
97+ Parameters with `| None = None ` are hidden from the orchestrator but available for evaluation:
98+
99+ ```python
100+ @ env.scenario(" investigate" )
101+ async def investigate(
102+ query: str , # Visible - orchestrator passes this
103+ expected_finding: str | None = None , # Hidden - only used in eval scoring
104+ ):
105+ response = yield f " Investigate: { query} "
106+
107+ # Scoring uses expected_finding but orchestrator never sees it
108+ if expected_finding and response:
109+ yield 1.0 if expected_finding in response else 0.5
110+ else :
111+ yield 1.0 if response else 0.0
112+ ```
113+
114+ ** Usage:**
115+ ```python
116+ from hud import Environment
117+ from hud.tools import AgentTool
118+
119+ # Subagent environment with scenario
120+ sentry_env = Environment(name = " sentry-agent" )
121+
122+ @ sentry_env.scenario(" investigate" )
123+ async def investigate_sentry(query: str ):
124+ yield f " Investigate Sentry: { query} "
125+
126+ # Create orchestrator
127+ orchestrator = Environment(name = " orchestrator" )
128+
129+ # Wrap subagent scenario as tool
130+ tool = AgentTool(
131+ sentry_env(" investigate" ), # Task template
132+ model = " gpt-4o-mini" ,
133+ name = " investigate_sentry" ,
134+ description = " Investigate errors in Sentry" ,
135+ )
136+ orchestrator.add_tool(tool.mcp)
137+
138+ # Now orchestrator agent can call investigate_sentry(query="...")
139+ ```
140+
141+ ** Trace Continuity:**
142+
143+ When called from within an eval context, AgentTool automatically:
144+ 1 . Inherits the parent' s trace_id
145+ 2 . Skips duplicate trace registration
146+ 3 . Routes all inference/ tool calls to the parent trace
147+
148+ ```python
149+ async with hud.eval(task) as ctx:
150+ agent = create_agent(" gpt-4o" )
151+ result = await agent.run(ctx)
152+ # All subagent activity appears in this single trace
153+ ```
154+
155+ ** See Also:** [Ops Diagnostics Cookbook](/ cookbook/ ops- diagnostics) for a complete hierarchical agent example.
156+
157+ -- -
158+
72159# # Core Tools
73160
74161# ## BashTool
0 commit comments