mastra-ai/mastra · error · MastraError
AGENT_GENEREATE_SCORER_NOT_FOUND
AGENT_GENEREATE_SCORER_NOT_FOUND
Error message
Mastra not found when fetching scorer. Make sure to fetch agent from mastra.getAgent()
What it means
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()`.
Source
Thrown at packages/core/src/agent/agent.ts:6573
}
/**
* Resolves scorer name references to actual scorer instances from Mastra.
* @internal
*/
private resolveOverrideScorerReferences(
overrideScorers:
| MastraScorers
| Record<string, { scorer: MastraScorer['name']; sampling?: ScoringSamplingConfig; filter?: ScoringFilter }>,
) {
const result: Record<string, { scorer: MastraScorer; sampling?: ScoringSamplingConfig; filter?: ScoringFilter }> =
{};
for (const [id, scorerObject] of Object.entries(overrideScorers)) {
// If the scorer is a string (scorer name), we need to get the scorer from the mastra instance
if (typeof scorerObject.scorer === 'string') {
try {
if (!this.#mastra) {
throw new MastraError({
id: 'AGENT_GENEREATE_SCORER_NOT_FOUND',
domain: ErrorDomain.AGENT,
category: ErrorCategory.USER,
text: `Mastra not found when fetching scorer. Make sure to fetch agent from mastra.getAgent()`,
});
}
const scorer = this.#mastra.getScorerById(scorerObject.scorer);
result[id] = { scorer, sampling: scorerObject.sampling, filter: scorerObject.filter };
} catch (error) {
this.logger.warn('Failed to get scorer', { agent: this.name, scorer: scorerObject.scorer, error });
}
} else {
result[id] = scorerObject;
}
}
// Only throw if scorers were provided but none could be resolvedView on GitHub (pinned to 75dd419e61)
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
Example fix
// before
const agent = new Agent({ name: 'a', model, instructions });
await agent.generate(prompt, { scorers: { quality: { scorer: 'qualityScorer' } } });
// after
const agent = mastra.getAgent('a');
await agent.generate(prompt, { scorers: { quality: { scorer: 'qualityScorer' } } }); Defensive patterns
Strategy: validation
Validate before calling
function canUseNamedScorers(agent, scorers) {
const usesStringScorer = Object.values(scorers ?? {}).some(
(s) => typeof s?.scorer === 'string'
);
const hasMastra = typeof agent.__getMastra === 'function' ? !!agent.__getMastra() : true;
return !usesStringScorer || hasMastra; // otherwise pass scorer objects directly
} Type guard
function isMastraAgent(agent) {
return typeof agent === 'object' && agent !== null && '__getMastra' in agent;
} Try / catch
try {
return await agent.generate(prompt, { scorers });
} catch (e) {
if (e?.id === 'AGENT_GENEREATE_SCORER_NOT_FOUND' && /Mastra not found/.test(e.message)) {
logger.warn('agent not attached to Mastra; skipping scoring');
return runWithoutScoring();
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AGENT_LIST_SUSPENDED_RUNS_NO_STORAGE
- sendNotificationSignal requires a notifications storage doma
- AGENT_DURABLE_METHOD_NOT_AVAILABLE
- sendStateSignal requires Mastra memory
- Mode ${mode.id} requires a defaultModelId when no backing ag
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/73a80cb803ea1c15.
Report an issue: GitHub.