mastra-ai/mastra · error
Cannot set both `model` and `observation.model`. Use `model`
Error message
Cannot set both `model` and `observation.model`. Use `model` to set both agents, or set each individually.
What it means
ObservationalMemory lets you set one top-level model for both the observation and reflection agents, or configure each sub-agent individually. Setting the top-level model together with observation.model is ambiguous and rejected at construction.
Source
Thrown at packages/memory/src/processors/observational-memory/observational-memory.ts:470
// Release the lock
releaseLock!();
// Clean up if this is still our lock
if (this.locks.get(key) === lockPromise) {
this.locks.delete(key);
}
}
}
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;View on GitHub (pinned to 75dd419e61)
Solutions
- Remove the top-level model and set model on observation and reflection individually, OR
- Remove observation.model and rely on the top-level model for both agents
- If configs are merged programmatically, strip the top-level model when any sub-config model is present
Example fix
// before
new ObservationalMemory({ model: gpt4o, observation: { model: claude } })
// after (per-agent)
new ObservationalMemory({ observation: { model: claude }, reflection: { model: gpt4o } })
// or (shared)
new ObservationalMemory({ model: gpt4o, observation: {} }) Defensive patterns
Strategy: validation
Validate before calling
if (config.model && config.observation?.model) {
throw new Error('Set either top-level model or observation.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 `observation.model`')) {
delete config.observation.model; // let top-level model apply
} else throw err;
} Prevention
- Pick one style per project: either a single shared model or per-agent models
- When merging config objects, remove the top-level model key if any sub-config model exists
- Type your config with a discriminated union so model and per-agent models can't coexist
When it happens
Trigger: new ObservationalMemory({ model: m1, observation: { model: m2, ... } }) — both a top-level model and an observation.model in the same config.
Common situations: Merging a shared-config object (with top-level model) with a per-agent config that also specifies observation.model; incremental config refactor that left the old top-level model in place after adding sub-config models.
Related errors
- Cannot set both `model` and `reflection.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/b4d454d387a43093.
Report an issue: GitHub.