mastra-ai/mastra · error
Cannot set both `model` and `reflection.model`. Use `model`
Error message
Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.
What it means
Same ambiguity rule as for observation.model: the top-level model cannot be combined with reflection.model. The constructor rejects the config so it's clear which model the reflection agent uses.
Source
Thrown at packages/memory/src/processors/observational-memory/observational-memory.ts:475
}
}
}
constructor(config: ObservationalMemoryConfig) {
if (!coreFeatures.has('request-response-id-rotation')) {
throw new Error(
'Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version.',
);
}
// Validate that top-level model is not used together with sub-config models
if (config.model && config.observation?.model) {
throw new Error(
'Cannot set both `model` and `observation.model`. Use `model` to set both agents, or set each individually.',
);
}
if (config.model && config.reflection?.model) {
throw new Error(
'Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.',
);
}
this.shouldObscureThreadIds = config.obscureThreadIds || false;
this.storage = config.storage;
this.scope = config.scope ?? 'thread';
this.retrieval = Boolean(config.retrieval);
this.retrievalScope = typeof config.retrieval === 'object' ? (config.retrieval.scope ?? 'resource') : 'resource';
this.retrievalInstructions = typeof config.retrieval === 'object' ? config.retrieval.instructions : undefined;
this.retrievalSearch = typeof config.retrieval === 'object' && Boolean(config.retrieval.vector);
this.onIndexObservations = config.onIndexObservations;
this.hooks = config.hooks;
this.hookExecution = config.hookExecution ?? 'non-blocking';
this.mastra = config.mastra;
this.memory = config.memory;
this.curationCadence = config.curationCadence;
View on GitHub (pinned to 75dd419e61)
Solutions
- Remove the top-level model and specify observation.model and reflection.model individually, OR
- Remove reflection.model so the top-level model applies to both agents
- When merging configs, delete the top-level model key if a sub-config model exists
Example fix
// before
new ObservationalMemory({ model: gpt4o, reflection: { model: claude } })
// after
new ObservationalMemory({ observation: { model: gpt4o }, reflection: { model: claude } }) Defensive patterns
Strategy: validation
Validate before calling
if (config.model && config.reflection?.model) {
throw new Error('Set either top-level model or reflection.model, not both');
} Type guard
function hasConsistentModelConfig(c: ObservationalMemoryConfig): boolean {
return !(c.model && (c.observation?.model || c.reflection?.model));
} Try / catch
try {
const mem = new ObservationalMemory(config);
} catch (err) {
if (err instanceof Error && err.message.includes('Cannot set both `model` and `reflection.model`')) {
delete config.reflection.model; // let top-level model apply
} else throw err;
} Prevention
- Same rule as observation.model: one model style per config
- Add a shared config lint/validator covering both observation.model and reflection.model conflicts
- Use a discriminated union type: SharedModelConfig | PerAgentModelConfig
When it happens
Trigger: new ObservationalMemory({ model: m1, reflection: { model: m2, ... } }) — top-level model present alongside reflection.model.
Common situations: Setting a default model at top level then customizing only reflection via sub-config; merging base and override config objects where both end up specifying reflection models.
Related errors
- Cannot set both `model` and `observation.model`. Use `model`
- Cookie password must be at least 32 characters. Set WORKOS_C
- Factory rule version is required.
- ${label} must be an object.
- Factory rules must be an object.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/4fe62cfd9aa42db5.
Report an issue: GitHub.