mastra-ai/mastra · error

No result received from agent execution on iteration ${itera

Error message

No result received from agent execution on iteration ${iterationCount}

What it means

During each loop iteration, the workflow consumes the agent's structured-output stream and awaits stream.object; if the parsed result is falsy, this error declares that no structured result was produced for the current iteration. It guards downstream logic (task-status diffing, completion checks) from operating on a nonexistent result.

Source

Thrown at packages/agent-builder/src/workflows/workflow-builder/workflow-builder.ts:412

            finalMessage = '';
          }

          if (chunk.type === 'tool-result') {
            console.info(JSON.stringify(chunk, null, 2));
          }

          if (chunk.type === 'finish') {
            console.info(chunk);
          }
        }

        await stream.consumeStream();
        finalResult = await stream.object;

        console.info(`Iteration ${iterationCount} result:`, { finalResult });

        if (!finalResult) {
          throw new Error(`No result received from agent execution on iteration ${iterationCount}`);
        }

        const postIterationTaskStatus = await AgentBuilderDefaults.manageTaskList({ action: 'list' });
        const postCompletedTasks = postIterationTaskStatus.tasks.filter(task => task.status === 'completed');
        const postPendingTasks = postIterationTaskStatus.tasks.filter(task => task.status !== 'completed');

        allTasksCompleted = postPendingTasks.length === 0;

        console.info(
          `After iteration ${iterationCount}: ${postCompletedTasks.length}/${expectedTaskIds.length} tasks completed in taskManager`,
        );

        // If agent needs clarification, break out and suspend
        if (finalResult.status === 'needs_clarification' && finalResult.questions && finalResult.questions.length > 0) {
          console.info(
            `Agent needs clarification on iteration ${iterationCount}: ${finalResult.questions.length} questions`,
          );
          break;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry the iteration/run — empty structured outputs are often transient model behavior
  2. Use a model that supports structured/object output reliably and check provider logs for refusals or truncation
  3. Validate the response schema is correct and not over-constrained (unsatisfiable schemas yield no valid object)
  4. Reduce input size or split tasks if the context window is being exceeded
  5. Add logging around stream.text/error before awaiting stream.object to capture what the model actually returned
Defensive patterns

Strategy: retry

Validate before calling

// before the run: confirm the model supports structured output and the schema compiles
export function assertStructuredOutputCapable(modelId: string, allowed: string[]) {
  if (!allowed.includes(modelId)) throw new Error(`${modelId} may not support structured object output`);
}

Type guard

export function hasResult(r: unknown): r is { status: string; [k: string]: unknown } {
  return r != null && typeof r === 'object' && 'status' in r;
}
// after await stream.object: if (!hasResult(finalResult)) retry or fail fast

Try / catch

let finalResult = await stream.object;
if (!finalResult) {
  if (attempt < maxAttempts) { await sleep(backoff(attempt)); return retryIteration(); }
  throw new Error(`No result received from agent execution on iteration ${iterationCount}`);
}

Prevention

When it happens

Trigger: The model stream ended without emitting a valid object matching the response schema: empty/refused completion, output failing schema validation so stream.object resolves to undefined, or the stream erroring/finishing early after consumeStream().

Common situations: Model refusing or returning empty output (content filter, overlong context), a model that does not reliably support structured output, malformed schema causing silent parse failure, or provider timeouts producing truncated streams.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/73eab9f4bdf7330b. Report an issue: GitHub.