API Reference
agentAsTool
function agentAsTool(options): Tool;Defined in: tools/agent-as-tool.ts:137
Wrap an agent as a Tool another agent can call.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | AgentAsToolOptions | The sub-agent's identity (name/description) and run config. |
Returns
A Tool ready for runAgent or a ToolRegistry.
Remarks
The returned tool's execute runs a child runAgent with the model's
task as the prompt and returns its final answer as the tool result
content. The full child RunResult rides ToolResult.details
(never sent to the model) for hooks and the tracer. By default each call is
context-isolated (fresh session per call); see AgentAsToolOptions for
continuity, result shaping, and the injectable run.
See
Example
const researcher = agentAsTool({
name: "researcher",
description: "Researches a question and reports findings.",
model,
system: "You are a meticulous researcher. Answer concisely.",
tools: [webSearchTool(backend)],
});
// The orchestrator calls it like any tool:
await runAgent({ ...opts, tools: [researcher], prompt: "Compare X and Y." });