{"record":{"id":"b4d454d387a43093","repo":"mastra-ai/mastra","slug":"cannot-set-both-model-and-observation-model-u","errorCode":null,"errorMessage":"Cannot set both `model` and `observation.model`. Use `model` to set both agents, or set each individually.","messagePattern":"Cannot set both `model` and `observation\\.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":470,"sourceCode":"      // Release the lock\n      releaseLock!();\n      // Clean up if this is still our lock\n      if (this.locks.get(key) === lockPromise) {\n        this.locks.delete(key);\n      }\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;","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/observational-memory.ts#L452-L488","documentation":"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.","triggerScenarios":"new ObservationalMemory({ model: m1, observation: { model: m2, ... } }) — both a top-level model and an observation.model in the same config.","commonSituations":"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.","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"],"exampleFix":"// before\nnew ObservationalMemory({ model: gpt4o, observation: { model: claude } })\n// after (per-agent)\nnew ObservationalMemory({ observation: { model: claude }, reflection: { model: gpt4o } })\n// or (shared)\nnew ObservationalMemory({ model: gpt4o, observation: {} })","handlingStrategy":"validation","validationCode":"if (config.model && config.observation?.model) {\n  throw new Error('Set either top-level model or observation.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 `observation.model`')) {\n    delete config.observation.model; // let top-level model apply\n  } else throw err;\n}","preventionTips":["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"],"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"}