mastra-ai/mastra · error

No result received from agent execution

Error message

No result received from agent execution

What it means

After the iteration loop, the workflow re-checks that finalResult exists before reading finalResult.status/questions; if it is still falsy it throws 'No result received from agent execution'. This is the end-of-run guard: it fires when the loop finished without ever producing a usable structured result (note: the preceding max-iterations branch assumes finalResult exists, so reaching here falsy means no iteration yielded a result at all).

Source

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

          break;
        }

        // If agent claims completed but taskManager shows pending tasks, continue loop
        if (finalResult.status === 'completed' && !allTasksCompleted) {
          console.info(
            `Agent claimed completion but taskManager shows pending tasks: ${postPendingTasks.map(t => t.id).join(', ')}`,
          );
          // Continue to next iteration
        }
      }

      if (iterationCount >= maxIterations && !allTasksCompleted) {
        finalResult.error = `Maximum iterations (${maxIterations}) reached but not all tasks completed`;
        finalResult.status = 'in_progress';
      }

      if (!finalResult) {
        throw new Error('No result received from agent execution');
      }

      // If the agent needs clarification, suspend the workflow
      if (finalResult.status === 'needs_clarification' && finalResult.questions && finalResult.questions.length > 0) {
        console.info(`Agent needs clarification: ${finalResult.questions.length} questions`);

        console.info('finalResult', JSON.stringify(finalResult, null, 2));
        return suspend({
          questions: finalResult.questions,
          currentProgress: finalResult.progress,
          completedTasks: finalResult.completedTasks || [],
          message: finalResult.message,
        });
      }

      const finalTaskStatus = await AgentBuilderDefaults.manageTaskList({ action: 'list' });
      const finalCompletedTasks = finalTaskStatus.tasks.filter(task => task.status === 'completed');
      const finalPendingTasks = finalTaskStatus.tasks.filter(task => task.status !== 'completed');

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Fix the per-iteration failure cause (model, schema, credentials) so at least one iteration produces a result
  2. Verify model configuration/credentials — repeated stream failures usually indicate auth or provider issues
  3. Ensure maxIterations is at least 1 in the workflow input
  4. Retry the workflow after checking provider status; log raw stream output per iteration to find why no object ever parsed
Defensive patterns

Strategy: try-catch

Validate before calling

export function assertWorkflowInput(input: { maxIterations?: number }) {
  if (input.maxIterations != null && input.maxIterations < 1) {
    throw new Error('maxIterations must be >= 1');
  }
}
// validate workflow input before start()

Type guard

export function isAgentRunResult(r: unknown): r is { status: string; error?: string; questions?: unknown[] } {
  return r != null && typeof r === 'object' && typeof (r as any).status === 'string';
}
// guard before reading status/questions: if (!isAgentRunResult(finalResult)) throw ...

Try / catch

try {
  await run.start(input);
} catch (e) {
  if (e instanceof Error && e.message === 'No result received from agent execution') {
    // loop never produced a result: check model credentials/provider health and retry
  }
  throw e;
}

Prevention

When it happens

Trigger: Every iteration's stream.object was falsy (see the per-iteration variant) or the loop body never executed/assigned finalResult, so the variable remains undefined after the loop.

Common situations: Persistent provider outages or refusals across all iterations, misconfigured model credentials causing immediate stream failures each iteration, or an edge case where maxIterations allowed zero iterations.

Related errors


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