mastra-ai/mastra · error · HTTPException

Observational Memory is not enabled for this agent

Error message

Observational Memory is not enabled for this agent

What it means

Thrown when the resolved agent exists but its Observational Memory config is absent or has `enabled: false`. The OM history endpoint requires an agent explicitly configured with OM, so it rejects the request with 400.

Source

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

      if (await isGatewayAgentAsync(agent)) {
        const gwClient = getGatewayClient();
        if (gwClient && resourceId && threadId) {
          const [recordResult, historyResult] = await Promise.all([
            gwClient.getObservationRecord(threadId, resourceId),
            gwClient.getObservationHistory(threadId, { resourceId, limit: historyLimit, from, to, offset }),
          ]);
          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' });
      }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Enable Observational Memory on the agent's Memory instance (e.g. `new Memory({ options: { observationalMemory: { enabled: true, ... } } })`).
  2. Verify requestContext isn't overriding/disabling the OM config for this request.
  3. Only call OM history endpoints for agents that actually have OM configured.
  4. Check thread-level OM settings that may disable OM for the specific threadId.

Example fix

// before
const memory = new Memory({ options: {} }); // OM off -> 400
// after
const memory = new Memory({
  options: { observationalMemory: { enabled: true } },
});
Defensive patterns

Strategy: validation

Validate before calling

const agent = mastra.getAgent(agentId);
const om = agent?.getModelList?.() ?? null; // placeholder guard
const omConfig = /* from memory options */ (agent as any)?.__omConfig;
if (!omConfig?.enabled) throw new Error(`OM is not enabled for agent '${agentId}'; enable observationalMemory in its Memory options`);

Type guard

function hasOmEnabled(memory: Memory | undefined): boolean {
  return !!memory?.getOptions?.()?.observationalMemory?.enabled;
}

Try / catch

try {
  const rec = await fetchOmHistory(agentId);
} catch (e) {
  if (isHttpError(e, 400) && /Observational Memory/.test(e.message)) {
    // disable OM UI features for this agent instead of calling the endpoint
  }
  throw e;
}

Prevention

When it happens

Trigger: Requesting OM history for an agent whose Memory/Memory options don't include `observationalMemory: { enabled: true }` (or equivalent config resolved by getOMConfigFromAgent), or whose thread/resource has no OM config at all.

Common situations: Forgetting to enable OM in agent memory options after upgrading; OM enabled globally but disabled for this specific agent/thread; calling OM endpoints for regular memory agents; config read from requestContext overriding the default.

Related errors


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