8.5 Worker Result Delivery
After a sub-Agent / Worker completes its task, how does the result get back to the parent safely and reliably? This involves two fundamentally different return paths, a notification deduplication mechanism, and security classification against prompt injection.
Synchronous vs Asynchronous: Two Return Paths
Worker result delivery is divided into synchronous and asynchronous paths, with completely different mechanisms:
Synchronous path (finalizeAgentTool() in agentToolUtils.ts):
When a sub-Agent executes synchronously, the parent Agent blocks and waits. Upon completion, the system extracts the text content from the sub-Agent's last assistant message (excluding intermediate tool call processes), wraps it as an AgentToolResult, and embeds it directly as a tool_result in the parent conversation.
// Synchronous result structure
{
status: 'completed',
agentId: string,
content: [{ type: 'text', text: 'Final result text' }],
totalToolUseCount: number,
totalDurationMs: number,
totalTokens: number,
}Asynchronous path (enqueueAgentNotification() in LocalAgentTask.tsx):