mastra-ai/mastra · error

Subconscious learn requires the main agent to resolve its mo

Error message

Subconscious learn requires the main agent to resolve its model.

What it means

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.

Source

Thrown at packages/memory/src/processors/observational-memory/subconscious/learn.ts:235

}

async function createLearnerAgent(
  memory: Memory,
  learnerMemory: Memory,
  context: ReflectionCommittedContext,
  scope: KnowledgeScope,
  pendingRecords: KnowledgeRecord[],
  config: ResolvedSubconsciousAgent,
  subconscious: ResolvedSubconsciousConfig,
  omModel?: ObservationalMemoryModel,
): Promise<Agent> {
  const model = await resolveSubconsciousAgentModel({
    config,
    omModel,
    mainAgent: context.mainAgent,
    requestContext: context.requestContext,
  });
  if (!model) throw new Error('Subconscious learn requires the main agent to resolve its model.');
  const store = await memory.storage.getStore('knowledge');
  if (!store) throw new Error('Subconscious learn requires a configured knowledge storage domain.');
  const state: LearnerState = {};
  return new Agent({
    id: `subconscious-learn-${context.parentThreadId}`,
    name: 'Subconscious Learn',
    instructions: [DEFAULT_INSTRUCTIONS, config.instructions?.trim()].filter(Boolean).join('\n\n'),
    model,
    memory: learnerMemory,
    tools: {
      ...createKnowledgeTools(memory, scope),
      ...createKnowledgeWriteTools(memory, {
        scope,
        sourceThreadId: context.parentThreadId,
        defaultScope: subconscious.defaultScope,
        maxScope: subconscious.maxScope,
      }),
      knowledge_record_skill: createLearnerRecordSkillTool({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Configure a model on the main agent so resolution succeeds
  2. Set an explicit model in the observational-memory (subconscious) config as an override
  3. Ensure context.mainAgent and context.requestContext are propagated to the learn step
  4. Log/inspect resolveSubconsciousAgentModel inputs at startup to catch the missing model early

Example fix

// before
new Agent({ name: 'main', instructions: '...' }); // no model
// Error: Subconscious learn requires the main agent to resolve its model.
// after
new Agent({ name: 'main', instructions: '...', model: 'openai/gpt-4o' });
// or override in OM config: { subconscious: { model: 'openai/gpt-4o-mini' } }
Defensive patterns

Strategy: validation

Validate before calling

if (!context.mainAgent) throw new Error('Pass the main agent into the subconscious context so its model can be resolved.');
const model = await resolveSubconsciousAgentModel({ config, omModel, mainAgent: context.mainAgent, requestContext: context.requestContext });
if (!model) throw new Error('Main agent model could not be resolved; set it on the agent or in OM config.');

Type guard

function resolvesModel(ctx) {
  return !!ctx && !!ctx.mainAgent && typeof ctx.mainAgent.getModel === 'function';
}

Try / catch

try {
  const agent = await createLearnerAgent(memory, context, config);
} catch (err) {
  if (err.message.includes('resolve its model')) {
    // configure a model on the main agent or set the OM model override
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/d3c580beb14ccd14. Report an issue: GitHub.