{"record":{"id":"73a80cb803ea1c15","repo":"mastra-ai/mastra","slug":"agent-genereate-scorer-not-found","errorCode":"AGENT_GENEREATE_SCORER_NOT_FOUND","errorMessage":"Mastra not found when fetching scorer. Make sure to fetch agent from mastra.getAgent()","messagePattern":"Mastra not found when fetching scorer\\. Make sure to fetch agent from mastra\\.getAgent\\(\\)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent.ts","lineNumber":6573,"sourceCode":"  }\n\n  /**\n   * Resolves scorer name references to actual scorer instances from Mastra.\n   * @internal\n   */\n  private resolveOverrideScorerReferences(\n    overrideScorers:\n      | MastraScorers\n      | Record<string, { scorer: MastraScorer['name']; sampling?: ScoringSamplingConfig; filter?: ScoringFilter }>,\n  ) {\n    const result: Record<string, { scorer: MastraScorer; sampling?: ScoringSamplingConfig; filter?: ScoringFilter }> =\n      {};\n    for (const [id, scorerObject] of Object.entries(overrideScorers)) {\n      // If the scorer is a string (scorer name), we need to get the scorer from the mastra instance\n      if (typeof scorerObject.scorer === 'string') {\n        try {\n          if (!this.#mastra) {\n            throw new MastraError({\n              id: 'AGENT_GENEREATE_SCORER_NOT_FOUND',\n              domain: ErrorDomain.AGENT,\n              category: ErrorCategory.USER,\n              text: `Mastra not found when fetching scorer. Make sure to fetch agent from mastra.getAgent()`,\n            });\n          }\n\n          const scorer = this.#mastra.getScorerById(scorerObject.scorer);\n          result[id] = { scorer, sampling: scorerObject.sampling, filter: scorerObject.filter };\n        } catch (error) {\n          this.logger.warn('Failed to get scorer', { agent: this.name, scorer: scorerObject.scorer, error });\n        }\n      } else {\n        result[id] = scorerObject;\n      }\n    }\n\n    // Only throw if scorers were provided but none could be resolved","sourceCodeStart":6555,"sourceCodeEnd":6591,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent.ts#L6555-L6591","documentation":"A MastraError (id AGENT_GENEREATE_SCORER_NOT_FOUND) thrown when resolving scorer overrides that reference scorers by string name: the agent has no Mastra instance (`this.#mastra` is undefined), so it cannot look up the named scorer in the registry. This happens when the Agent was instantiated standalone rather than fetched/registered via `mastra.getAgent()`.","triggerScenarios":"Calling `generate`/`stream` (or the scorer resolution path) with `options.scorers` containing `{ scorer: 'scorerName' }` string references while the agent instance has no `#mastra` reference — i.e., the agent was constructed directly (`new Agent({...})`) and used without registration on a Mastra instance.","commonSituations":"Tests or scripts that construct agents directly and then pass named scorers; exporting an agent from a module and using it in another app without adding it to `new Mastra({ agents: {...} })`; scorers defined but registered only on the Mastra instance, not the agent.","solutions":["Fetch the agent through the Mastra instance: `const agent = mastra.getAgent('myAgent')` instead of using the raw `new Agent(...)` instance","Register the agent on `new Mastra({ agents: { myAgent } })` before using it with scorers","Alternatively pass the actual scorer object (not a string name) in `scorers` so no registry lookup is needed"],"exampleFix":"// before\nconst agent = new Agent({ name: 'a', model, instructions });\nawait agent.generate(prompt, { scorers: { quality: { scorer: 'qualityScorer' } } });\n// after\nconst agent = mastra.getAgent('a');\nawait agent.generate(prompt, { scorers: { quality: { scorer: 'qualityScorer' } } });","handlingStrategy":"validation","validationCode":"function canUseNamedScorers(agent, scorers) {\n  const usesStringScorer = Object.values(scorers ?? {}).some(\n    (s) => typeof s?.scorer === 'string'\n  );\n  const hasMastra = typeof agent.__getMastra === 'function' ? !!agent.__getMastra() : true;\n  return !usesStringScorer || hasMastra; // otherwise pass scorer objects directly\n}","typeGuard":"function isMastraAgent(agent) {\n  return typeof agent === 'object' && agent !== null && '__getMastra' in agent;\n}","tryCatchPattern":"try {\n  return await agent.generate(prompt, { scorers });\n} catch (e) {\n  if (e?.id === 'AGENT_GENEREATE_SCORER_NOT_FOUND' && /Mastra not found/.test(e.message)) {\n    logger.warn('agent not attached to Mastra; skipping scoring');\n    return runWithoutScoring();\n  }\n  throw e;\n}","preventionTips":["Always obtain agents via mastra.getAgent() in application code","Register every agent on the Mastra instance it will be used with","Pass scorer objects instead of string names when no registry is available","Add a unit test that runs one scorer-referencing generate call in CI"],"tags":["agent","scorer","mastra-instance","configuration"],"backgroundTag":"agent-not-registered","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}