{"record":{"id":"4fe62cfd9aa42db5","repo":"mastra-ai/mastra","slug":"cannot-set-both-model-and-reflection-model-us","errorCode":null,"errorMessage":"Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.","messagePattern":"Cannot set both `model` and `reflection\\.model`\\. Use `model` to set both agents, or set each individually\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/observational-memory.ts","lineNumber":475,"sourceCode":"      }\n    }\n  }\n\n  constructor(config: ObservationalMemoryConfig) {\n    if (!coreFeatures.has('request-response-id-rotation')) {\n      throw new Error(\n        'Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version.',\n      );\n    }\n\n    // Validate that top-level model is not used together with sub-config models\n    if (config.model && config.observation?.model) {\n      throw new Error(\n        'Cannot set both `model` and `observation.model`. Use `model` to set both agents, or set each individually.',\n      );\n    }\n    if (config.model && config.reflection?.model) {\n      throw new Error(\n        'Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.',\n      );\n    }\n\n    this.shouldObscureThreadIds = config.obscureThreadIds || false;\n    this.storage = config.storage;\n    this.scope = config.scope ?? 'thread';\n    this.retrieval = Boolean(config.retrieval);\n    this.retrievalScope = typeof config.retrieval === 'object' ? (config.retrieval.scope ?? 'resource') : 'resource';\n    this.retrievalInstructions = typeof config.retrieval === 'object' ? config.retrieval.instructions : undefined;\n    this.retrievalSearch = typeof config.retrieval === 'object' && Boolean(config.retrieval.vector);\n    this.onIndexObservations = config.onIndexObservations;\n    this.hooks = config.hooks;\n    this.hookExecution = config.hookExecution ?? 'non-blocking';\n    this.mastra = config.mastra;\n    this.memory = config.memory;\n    this.curationCadence = config.curationCadence;\n","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/observational-memory.ts#L457-L493","documentation":"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.","triggerScenarios":"new ObservationalMemory({ model: m1, reflection: { model: m2, ... } }) — top-level model present alongside reflection.model.","commonSituations":"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.","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"],"exampleFix":"// before\nnew ObservationalMemory({ model: gpt4o, reflection: { model: claude } })\n// after\nnew ObservationalMemory({ observation: { model: gpt4o }, reflection: { model: claude } })","handlingStrategy":"validation","validationCode":"if (config.model && config.reflection?.model) {\n  throw new Error('Set either top-level model or reflection.model, not both');\n}","typeGuard":"function hasConsistentModelConfig(c: ObservationalMemoryConfig): boolean {\n  return !(c.model && (c.observation?.model || c.reflection?.model));\n}","tryCatchPattern":"try {\n  const mem = new ObservationalMemory(config);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Cannot set both `model` and `reflection.model`')) {\n    delete config.reflection.model; // let top-level model apply\n  } else throw err;\n}","preventionTips":["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"],"tags":["config","validation","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}