mastra-ai/mastra · error · HTTPException

Memory is not configured for this agent

Error message

Memory is not configured for this agent

What it means

Thrown after OM is confirmed enabled when `agent.getMemory()` returns null/undefined — i.e., the agent has no Memory instance attached, so there is no storage to read OM records/history from. The endpoint requires an agent-level Memory configuration.

Source

Thrown at packages/server/src/server/handlers/memory.ts:696

          return {
            record: recordResult.record ? toLocalOMRecord(recordResult.record) : null,
            history: historyResult.records?.length > 0 ? historyResult.records.map(toLocalOMRecord) : undefined,
          };
        }
        // No threadId or resourceId yet (e.g. /chat/new) — return empty
        return { record: null, history: undefined };
      }

      const omConfig = await getOMConfigFromAgent(agent, requestContext);
      if (!omConfig?.enabled) {
        throw new HTTPException(400, { message: 'Observational Memory is not enabled for this agent' });
      }

      // Get storage from the agent's memory (not mastra.getStorage())
      // This ensures we use the same storage the agent uses for OM
      const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
      if (!memory) {
        throw new HTTPException(400, { message: 'Memory is not configured for this agent' });
      }

      let memoryStore: MemoryStorage | undefined;
      try {
        memoryStore = await memory.storage.getStore('memory');
      } catch {
        throw new HTTPException(400, { message: 'Memory storage is not initialized' });
      }
      if (!memoryStore) {
        throw new HTTPException(400, { message: 'Memory storage is not initialized' });
      }

      // Determine the resourceId to use
      const effectiveResourceId = resourceId;
      if (!effectiveResourceId) {
        throw new HTTPException(400, { message: 'resourceId is required for observational memory lookup' });
      }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Attach a Memory instance to the agent: `new Agent({ ..., memory })`.
  2. If the agent shouldn't have memory, remove the OM history calls for it.
  3. Verify the resolved agentId is the one you intended (not a similarly-named memory-less agent).
  4. Check DI/conditional code that may skip setting memory in this environment.

Example fix

// before
new Agent({ name: 'helper', instructions }) // no memory -> 400
// after
new Agent({ name: 'helper', instructions, memory });
Defensive patterns

Strategy: type-guard

Validate before calling

const agent = mastra.getAgent(agentId);
const memory = await agent?.getMemory?.();
if (!memory) throw new Error(`Agent '${agentId}' has no Memory attached; required for OM history`);

Type guard

function hasMemory(a: Agent | undefined): a is Agent & { getMemory(): Promise<Memory> } {
  return !!a && typeof (a as any).getMemory === 'function';
}

Try / catch

try {
  const history = await fetchOmHistory(agentId);
} catch (e) {
  if (isHttpError(e, 400) && /Memory is not configured/.test(e.message)) {
    // attach memory to the agent or stop requesting OM history for it
  }
  throw e;
}

Prevention

When it happens

Trigger: OM history route where the agent was created without a `memory` option (or with memory explicitly null), yet an OM history request is made for it.

Common situations: Agents built purely for tool-less workflows without Memory; constructor refactor accidentally dropping the `memory` option; passing an agent id that resolves to a different, memory-less agent.

Related errors


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