From 236beefb708a6cd91b673978ddf4ebf045a9844c Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sat, 23 May 2026 16:59:20 +0900 Subject: feat: key fallback using agent models[] hierarchy, background tool modes, copy truncation - Agent rate-limit fallback now iterates through agent's configured models[] in strict order - Frontend sends agentModels with each /chat request; backend uses buildFallbackSequence() - Emits notice event on fallback so chat shows which key failed and what's being tried next - Child agents inherit parent's agentModels for fallback - Added statusCode propagation from AI SDK errors for programmatic 429 detection - Copy button truncates all tool results at 300 chars (was 200 for 4 specific tools) - run_shell, summon, youtube_transcribe: background mode support - summon: blocking mode by default with getResult callback --- packages/core/src/tools/summon.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'packages/core/src/tools/summon.ts') diff --git a/packages/core/src/tools/summon.ts b/packages/core/src/tools/summon.ts index 29f27d1..22ab35b 100644 --- a/packages/core/src/tools/summon.ts +++ b/packages/core/src/tools/summon.ts @@ -3,6 +3,9 @@ import type { ToolDefinition } from "../types/index.js"; export interface SummonCallbacks { spawn(options: { task: string; tools: string[]; workingDirectory?: string }): Promise; + getResult( + agentId: string, + ): Promise<{ status: "done"; result: string } | { status: "error"; error: string }>; } export function createSummonTool( @@ -12,12 +15,15 @@ export function createSummonTool( return { name: "summon", description: [ - "Spawn a new child agent to work on a task independently. Returns immediately with an agent_id — does NOT wait for the child to finish.", + "Spawn a new child agent to work on a task independently.", + "", + "By default, blocks until the child agent finishes and returns the result directly.", + "Set background=true to return immediately with an agent_id instead — use retrieve to collect the result later.", "", "The child agent runs in its own tab visible to the user. Use the 'retrieve' tool with the returned agent_id to get the result when needed.", "", "Pattern for parallel work:", - " 1. Call summon multiple times to start several agents", + " 1. Call summon multiple times with background=true to start several agents", " 2. Do your own work or wait", " 3. Call retrieve for each agent_id to collect results", "", @@ -64,12 +70,19 @@ export function createSummonTool( .describe( "Absolute path for the child to work in. Defaults to the current working directory.", ), + background: z + .boolean() + .optional() + .describe( + "If true, returns immediately with an agent_id for later retrieval. If false (default), blocks until the child agent finishes and returns the result directly.", + ), }), execute: async (args: Record): Promise => { const task = args.task as string; const tools = (args.tools as string[] | undefined) ?? ["read_file", "list_files", "todo"]; const workingDirectory = (args.working_directory as string | undefined) ?? defaultWorkingDirectory; + const background = (args.background as boolean | undefined) ?? false; try { const agentId = await callbacks.spawn({ @@ -77,6 +90,16 @@ export function createSummonTool( tools, workingDirectory, }); + + if (!background) { + // Block until the child agent completes + const result = await callbacks.getResult(agentId); + if (result.status === "done") { + return result.result; + } + return `Error from child agent: ${result.error}`; + } + return [ `Agent spawned successfully.`, `agent_id: ${agentId}`, -- cgit v1.2.3