diff --git a/src/tools/delegate-task/sync-result-fetcher.ts b/src/tools/delegate-task/sync-result-fetcher.ts index 3eb454e5f..f2274eae6 100644 --- a/src/tools/delegate-task/sync-result-fetcher.ts +++ b/src/tools/delegate-task/sync-result-fetcher.ts @@ -44,8 +44,17 @@ export async function fetchSyncResult( return { ok: false, error: `No assistant response found.\n\nSession ID: ${sessionID}` } } - const textParts = lastMessage?.parts?.filter((p) => p.type === "text" || p.type === "reasoning") ?? [] - const textContent = textParts.map((p) => p.text ?? "").filter(Boolean).join("\n") + // Search assistant messages (newest first) for one with text/reasoning content. + // The last assistant message may only contain tool calls with no text. + let textContent = "" + for (const msg of assistantMessages) { + const textParts = msg.parts?.filter((p) => p.type === "text" || p.type === "reasoning") ?? [] + const content = textParts.map((p) => p.text ?? "").filter(Boolean).join("\n") + if (content) { + textContent = content + break + } + } return { ok: true, textContent } } diff --git a/src/tools/delegate-task/unstable-agent-task.ts b/src/tools/delegate-task/unstable-agent-task.ts index d806fd935..c0972e7bd 100644 --- a/src/tools/delegate-task/unstable-agent-task.ts +++ b/src/tools/delegate-task/unstable-agent-task.ts @@ -152,8 +152,15 @@ session_id: ${sessionID} return `No assistant response found (task ran in background mode).\n\nSession ID: ${sessionID}` } - const textParts = lastMessage?.parts?.filter((p) => p.type === "text" || p.type === "reasoning") ?? [] - const textContent = textParts.map((p) => p.text ?? "").filter(Boolean).join("\n") + let textContent = "" + for (const msg of assistantMessages) { + const textParts = msg.parts?.filter((p) => p.type === "text" || p.type === "reasoning") ?? [] + const content = textParts.map((p) => p.text ?? "").filter(Boolean).join("\n") + if (content) { + textContent = content + break + } + } const duration = formatDuration(startTime) return `SUPERVISED TASK COMPLETED SUCCESSFULLY