{"record":{"id":"1ea8a80d3a754bc4","repo":"mastra-ai/mastra","slug":"agent-model-not-available","errorCode":null,"errorMessage":"Agent model not available","messagePattern":"Agent model not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/core/src/agent/durable/preparation.ts","lineNumber":516,"sourceCode":"      clientTools: execOptions?.clientTools,\n      threadId,\n      resourceId,\n      runId,\n      requestContext,\n      memoryConfig: execOptions?.memory?.options,\n      autoResumeSuspendedTools: execOptions?.autoResumeSuspendedTools,\n      hooks: execOptions?.hooks,\n      delegation: execOptions?.delegation,\n      methodType,\n    });\n  } catch (error) {\n    logger?.warn?.(`[DurableAgent] Error converting tools: ${error}`);\n  }\n\n  // 8. Get model (and model list if configured)\n  const model = await typedAgent.getModel({ requestContext });\n  if (!model) {\n    throw new Error('Agent model not available');\n  }\n\n  // Client-executed results fire only after processors accept the request and\n  // the required runtime model has resolved.\n  if (!tripwireData) {\n    await fireClientToolOutputHooks({\n      messages,\n      tools,\n      abortSignal: execOptions?.abortSignal,\n      logger,\n    });\n  }\n\n  const modelList = await typedAgent.getModelList(requestContext);\n\n  // 8b. Get scorers configuration\n  const overrideScorers = (execOptions as any)?.scorers;\n  let scorers: Record<string, { scorer: any; sampling?: any }> | undefined;","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/durable/preparation.ts#L498-L534","documentation":"During durable execution preparation (prepareForDurableExecution), step 8 resolves the agent's runtime model via agent.getModel({ requestContext }). If it resolves to null/undefined there is no model to persist into the run, so preparation fails with a plain Error('Agent model not available').","triggerScenarios":"Calling generate/stream on a DurableAgent when getModel({ requestContext }) returns undefined — e.g. no model configured on the agent and no model resolvable from the request context, or a dynamic model resolver returning null at runtime.","commonSituations":"Agents declared without a `model` (relying on a default that isn't set), requestContext-based model routing where the context key is missing, or model getters that return null on missing API keys/configuration.","solutions":["Set a static `model` on the Agent constructor options.","If using dynamic model resolution, ensure the requestContext contains the expected key and the resolver returns a valid model.","Log/inspect agent.getModel({ requestContext }) result at startup to catch null resolution early."],"exampleFix":"// before\nconst agent = new Agent({ name: 'helper', instructions: '...' });\n// after\nconst agent = new Agent({ name: 'helper', instructions: '...', model: openai('gpt-4o') });","handlingStrategy":"validation","validationCode":"const model = await agent.getModel({ requestContext });\nif (!model) {\n  throw new Error(`Agent ${agent.name} has no resolvable model; check config and requestContext`);\n}\n// proceed with durable run","typeGuard":"function hasModel(m: unknown): m is MastraLanguageModel {\n  return !!m && typeof m === 'object' && 'doStream' in m;\n}","tryCatchPattern":"try {\n  await durableAgent.generate({ messages });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Agent model not available') {\n    logger.error('Model missing: check agent config or requestContext model key');\n  }\n  throw e;\n}","preventionTips":["Set a static default `model` on every agent so resolution never returns null","Validate dynamic model resolvers in unit tests for missing requestContext keys","Fail fast at boot: call getModel({}) for each agent during startup smoke checks"],"tags":["model","configuration","durable-agent"],"backgroundTag":"model-not-resolved","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}