{"record":{"id":"d3c580beb14ccd14","repo":"mastra-ai/mastra","slug":"subconscious-learn-requires-the-main-agent-to-reso","errorCode":null,"errorMessage":"Subconscious learn requires the main agent to resolve its model.","messagePattern":"Subconscious learn requires the main agent to resolve its model\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/learn.ts","lineNumber":235,"sourceCode":"}\n\nasync function createLearnerAgent(\n  memory: Memory,\n  learnerMemory: Memory,\n  context: ReflectionCommittedContext,\n  scope: KnowledgeScope,\n  pendingRecords: KnowledgeRecord[],\n  config: ResolvedSubconsciousAgent,\n  subconscious: ResolvedSubconsciousConfig,\n  omModel?: ObservationalMemoryModel,\n): Promise<Agent> {\n  const model = await resolveSubconsciousAgentModel({\n    config,\n    omModel,\n    mainAgent: context.mainAgent,\n    requestContext: context.requestContext,\n  });\n  if (!model) throw new Error('Subconscious learn requires the main agent to resolve its model.');\n  const store = await memory.storage.getStore('knowledge');\n  if (!store) throw new Error('Subconscious learn requires a configured knowledge storage domain.');\n  const state: LearnerState = {};\n  return new Agent({\n    id: `subconscious-learn-${context.parentThreadId}`,\n    name: 'Subconscious Learn',\n    instructions: [DEFAULT_INSTRUCTIONS, config.instructions?.trim()].filter(Boolean).join('\\n\\n'),\n    model,\n    memory: learnerMemory,\n    tools: {\n      ...createKnowledgeTools(memory, scope),\n      ...createKnowledgeWriteTools(memory, {\n        scope,\n        sourceThreadId: context.parentThreadId,\n        defaultScope: subconscious.defaultScope,\n        maxScope: subconscious.maxScope,\n      }),\n      knowledge_record_skill: createLearnerRecordSkillTool({","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/learn.ts#L217-L253","documentation":"The subconscious learn agent derives its model from the main agent (via resolveSubconsciousAgentModel with the main agent, OM model config, and request context). If that resolution returns no model, the library throws rather than constructing a learner Agent with an undefined model. The subconscious feature intentionally rides on the main agent's model configuration instead of requiring its own.","triggerScenarios":"createLearnerAgent is invoked but context.mainAgent is undefined/null or its model cannot be resolved (no model configured on the main agent), and no OM-level model override is set.","commonSituations":"Registering observational memory's subconscious on a thread/agent context where the main agent reference is not passed through; main agent configured without a model and relying on runtime injection that is absent in the background learn path; OM config lacking `model` while the main agent can't resolve one in this context.","solutions":["Configure a model on the main agent so resolution succeeds","Set an explicit model in the observational-memory (subconscious) config as an override","Ensure context.mainAgent and context.requestContext are propagated to the learn step","Log/inspect resolveSubconsciousAgentModel inputs at startup to catch the missing model early"],"exampleFix":"// before\nnew Agent({ name: 'main', instructions: '...' }); // no model\n// Error: Subconscious learn requires the main agent to resolve its model.\n// after\nnew Agent({ name: 'main', instructions: '...', model: 'openai/gpt-4o' });\n// or override in OM config: { subconscious: { model: 'openai/gpt-4o-mini' } }","handlingStrategy":"validation","validationCode":"if (!context.mainAgent) throw new Error('Pass the main agent into the subconscious context so its model can be resolved.');\nconst model = await resolveSubconsciousAgentModel({ config, omModel, mainAgent: context.mainAgent, requestContext: context.requestContext });\nif (!model) throw new Error('Main agent model could not be resolved; set it on the agent or in OM config.');","typeGuard":"function resolvesModel(ctx) {\n  return !!ctx && !!ctx.mainAgent && typeof ctx.mainAgent.getModel === 'function';\n}","tryCatchPattern":"try {\n  const agent = await createLearnerAgent(memory, context, config);\n} catch (err) {\n  if (err.message.includes('resolve its model')) {\n    // configure a model on the main agent or set the OM model override\n  } else throw err;\n}","preventionTips":["Always give the main agent an explicit model","Set an explicit model override in the subconscious config for background runs","Propagate mainAgent and requestContext into background learn invocations","Add a boot-time check that the learner's model resolves"],"tags":["configuration","model-resolution","observational-memory"],"backgroundTag":"model-not-resolved","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}