Skip to content

@sqlrooms/ai / streamSubAgent

Function: streamSubAgent()

streamSubAgent<TOOLS>(agent, prompt, store, parentToolCallId, abortSignal?): Promise<AgentStreamOutput>

Streams a sub-agent with the given prompt, collecting tool call progress for live UI rendering via the store, and returns the final text output along with the collected tool calls.

When a tool with needsApproval is encountered, the stream pauses, surfaces an approval request through the store, waits for the user's response, then restarts the stream with the approval response so the agent loop can continue.

Type Parameters

Type ParameterDefault type
TOOLS extends ToolSetToolSet

Parameters

ParameterTypeDescription
agentToolLoopAgent<never, TOOLS, any>The ToolLoopAgent to run
promptstringThe prompt string to send to the agent
storeAgentStreamStoreStore providing updateAgentProgress / clearAgentProgress / approval methods
parentToolCallIdstringThe parent tool call ID for progress tracking
abortSignal?AbortSignalOptional abort signal for cancellation

Returns

Promise<AgentStreamOutput>

The final text and collected tool calls from the agent