Function: createSubAgentTool()
@providerprotocol/agents / index / createSubAgentTool
Function: createSubAgentTool()
Section titled “Function: createSubAgentTool()”createSubAgentTool(
options):Tool
Defined in: src/subagent/index.ts:209
Creates a UPP Tool from a UAP Agent with full event propagation.
This function wraps an agent as a tool that can be invoked by a parent agent, enabling hierarchical agent architectures. The resulting tool handles all event propagation automatically.
Per UAP-1.0 Section 8.7, this helper:
- Emits
subagent_startbefore execution begins - Forwards inner events during streaming execution (when
stream: true) - Emits
subagent_endafter completion (success or failure) - Provides execution context to sub-agent for tracing
The created tool accepts an optional ToolExecutionContext as a second
parameter, which is injected by injectToolContext() during execution.
Parameters
Section titled “Parameters”options
Section titled “options”Configuration for the sub-agent tool
Returns
Section titled “Returns”Tool
A Tool definition that executes the sub-agent when called
Throws
Section titled “Throws”Re-throws any error from the sub-agent after emitting a subagent_end event with success: false
Examples
Section titled “Examples”const summarizer = agent({ model: anthropic('claude-haiku-4-20250514'), system: 'You summarize text concisely.',});
const summarizerTool = createSubAgentTool({ agent: summarizer, name: 'summarize', description: 'Summarize the given text', parameters: { type: 'object', properties: { text: { type: 'string', description: 'Text to summarize' }, maxLength: { type: 'number', description: 'Max summary length' }, }, required: ['text'], }, buildPrompt: (params) => `Summarize this in ${params.maxLength ?? 100} words:\n\n${params.text}`, subagentType: 'summarizer',});
// Use in a parent agentconst parentAgent = agent({ model: anthropic('claude-sonnet-4-20250514'), tools: [summarizerTool],});const tool = createSubAgentTool({ agent: myAgent, name: 'helper', description: 'A helper agent', parameters: { type: 'object', properties: {} }, buildPrompt: (params) => params.task as string, stream: false, // Only emit start/end events, no inner events});CreateSubAgentToolOptions for configuration details