rohitg00/agentmemory · error · Error

mem::search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no

Error message

mem::search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no agent id is available (env AGENT_ID unset and no explicit agentId in the call). Refusing to read cross-agent rows. Pass agentId: "*" to opt in to a wildcard read.

What it means

With AGENTMEMORY_AGENT_SCOPE=isolated, mem::search restricts results to a single agent. If no agent id can be resolved (no explicit agentId in the call, no AGENT_ID env var, and no wildcard), the function throws rather than silently reading across agents. agentId: "*" explicitly opts into wildcard reads.

Source

Thrown at src/functions/search.ts:426

      // with filterAgentId=undefined is the same leak this fix is
      // supposed to close.
      const isolated = isAgentScopeIsolated();
      const explicitAgentId =
        typeof data.agentId === "string" && data.agentId.trim().length > 0
          ? data.agentId.trim()
          : undefined;
      const wildcardAgent = explicitAgentId === "*";
      const envAgentId = isolated ? getAgentId() : undefined;
      const filterAgentId = wildcardAgent
        ? undefined
        : explicitAgentId ?? envAgentId;
      if (
        isolated &&
        !wildcardAgent &&
        !explicitAgentId &&
        !envAgentId
      ) {
        throw new Error(
          "mem::search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no " +
            "agent id is available (env AGENT_ID unset and no explicit " +
            "agentId in the call). Refusing to read cross-agent rows. " +
            'Pass agentId: "*" to opt in to a wildcard read.',
        );
      }
      const format = typeof data.format === 'string' ? data.format : 'full'
      if (!['full', 'compact', 'narrative'].includes(format)) {
        throw new Error("mem::search: format must be one of 'full', 'compact', or 'narrative'")
      }
      let tokenBudget: number | undefined
      if (data.token_budget !== undefined) {
        if (!Number.isInteger(data.token_budget) || data.token_budget < 1) {
          throw new Error('mem::search: token_budget must be a positive integer')
        }
        tokenBudget = data.token_budget
      }

View on GitHub (pinned to e04ba88819)

Solutions

  1. Export AGENT_ID in the daemon's environment and restart the daemon.
  2. Include an explicit agentId in the search payload.
  3. Pass agentId: "*" for an intentional cross-agent search.
  4. Disable AGENTMEMORY_AGENT_SCOPE=isolated if per-agent isolation is not required.

Example fix

// before
await trigger({ function_id: 'mem::search', payload: { query: q } });
// after
await trigger({ function_id: 'mem::search', payload: { query: q, agentId: process.env.AGENT_ID ?? '*' } });
Defensive patterns

Strategy: validation

Validate before calling

const agentId = explicitAgentId ?? process.env.AGENT_ID ?? '*';
if (!agentId) throw new Error('agentId required under isolated scope');

Type guard

function hasAgentId(v: unknown): v is string {
  return typeof v === 'string' && v.length > 0;
}

Try / catch

try {
  return await trigger({ function_id: 'mem::search', payload });
} catch (e) {
  if (String(e.message).includes('no agent id is available')) {
    return await trigger({ function_id: 'mem::search', payload: { ...payload, agentId: '*' } });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling mem::search via MCP/REST with AGENTMEMORY_AGENT_SCOPE=isolated set in the daemon environment while AGENT_ID is unset and the payload carries no agentId.

Common situations: Isolation mode enabled but the daemon launched without AGENT_ID (Docker/systemd env not updated); MCP tool calls that don't forward agentId; multi-agent setups where a helper agent was never assigned an id.

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/c7aab231849e9168. Report an issue: GitHub.