{"record":{"id":"e772e1d6600ea1d2","repo":"mastra-ai/mastra","slug":"agent-generate-failed","errorCode":"AGENT_GENERATE_FAILED","errorMessage":"AGENT_GENERATE_FAILED","messagePattern":"AGENT_GENERATE_FAILED","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent.ts","lineNumber":8035,"sourceCode":"      structuredOutput: mergedOptions.structuredOutput\n        ? {\n            ...mergedOptions.structuredOutput,\n            // Convert PublicSchema to StandardSchemaWithJSON at API boundary\n            // This follows the same pattern as Tool/Workflow constructors\n            schema: toStandardSchema(mergedOptions.structuredOutput.schema),\n          }\n        : undefined,\n      messages,\n      methodType: 'generate',\n      // Use agent's maxProcessorRetries as default, allow options to override\n      maxProcessorRetries: mergedOptions.maxProcessorRetries ?? this.#maxProcessorRetries,\n    } as unknown as InnerAgentExecutionOptions<any> & { _threadStreamPubSub?: PubSub };\n\n    const result = await this.#execute(executeOptions);\n\n    if (result.status !== 'success') {\n      if (result.status === 'failed') {\n        throw new MastraError(\n          {\n            id: 'AGENT_GENERATE_FAILED',\n            domain: ErrorDomain.AGENT,\n            category: ErrorCategory.USER,\n          },\n          // pass original error to preserve stack trace\n          result.error,\n        );\n      }\n      throw new MastraError({\n        id: 'AGENT_GENERATE_UNKNOWN_ERROR',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: 'An unknown error occurred while streaming',\n      });\n    }\n\n    if (typeof result.result?.getFullOutput !== 'function') {","sourceCodeStart":8017,"sourceCodeEnd":8053,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent.ts#L8017-L8053","documentation":"After Agent.generate() delegates to the internal #execute() workflow, the execution result came back with status 'failed'. Mastra wraps the original error (preserving its stack trace) in an AGENT_GENERATE_FAILED MastraError so callers get a consistent error type from generate(). The root cause is always attached as the cause.","triggerScenarios":"agent.generate() completes but the internal execution workflow's result.status === 'failed' — e.g. the underlying model call, tool, or workflow step threw and the failure propagated up through #execute().","commonSituations":"Invalid API keys causing provider auth failures; malformed tool schemas; model provider outages/rate limits; invalid toolChoice or unsupported parameters passed to the model.","solutions":["Inspect error.cause (the original error passed to MastraError) to find the root failure — it preserves the stack trace.","Verify model credentials, base URLs, and rate limits for the provider.","Validate tool definitions/schemas and request options passed to generate().","Add retry logic for transient provider failures if applicable."],"exampleFix":"try {\n  await agent.generate('hi');\n} catch (e) {\n  console.error('generate failed:', e.cause ?? e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await agent.generate(prompt);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'AGENT_GENERATE_FAILED') {\n    logger.error('generate failed', { cause: e.cause, stack: (e.cause as Error)?.stack });\n  }\n  throw e;\n}","preventionTips":["Always log e.cause — the original error is attached deliberately.","Pre-validate model credentials and tool schemas in CI smoke tests.","Wrap agent.generate in retry logic for transient provider errors."],"tags":["agent","generate","execution-failed","wrapped-error"],"backgroundTag":"wrapped-execution-failure","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}