rohitg00/agentmemory · error · Error

mem::smart-search: AGENTMEMORY_AGENT_SCOPE=isolated is set b

Error message

mem::smart-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

When AGENTMEMORY_AGENT_SCOPE=isolated, smart-search refuses to read rows belonging to other agents unless it can positively resolve a single agent id. If the env var AGENT_ID is unset and the call carries no explicit agentId, the function throws rather than silently scanning cross-agent data. Passing agentId: "*" is the explicit opt-in to a wildcard cross-agent read.

Source

Thrown at src/functions/smart-search.ts:124

      // filterAgentId fall through to `undefined` would be the same
      // cross-agent leak this filter is meant to prevent.
      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::smart-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.',
        );
      }

      if (data.expandIds && data.expandIds.length > 0) {
        const raw = data.expandIds.slice(0, 20);
        const items = raw.map((entry) => {
          if (typeof entry === "string") return { obsId: entry, sessionId: undefined as string | undefined };
          if (entry && typeof entry === "object" && typeof (entry as any).obsId === "string") {
            return { obsId: (entry as any).obsId, sessionId: (entry as any).sessionId as string | undefined };
          }
          return null;
        }).filter((item): item is NonNullable<typeof item> => item !== null);

        const expanded: Array<{

View on GitHub (pinned to e04ba88819)

Solutions

  1. Set the AGENT_ID environment variable in the process that hosts the SDK connection.
  2. Pass an explicit agentId in the call payload: sdk.trigger({ function_id: 'mem::smart-search', payload: { query, agentId: 'my-agent' } }).
  3. If a cross-agent read is truly intended, pass agentId: "*" explicitly to acknowledge it.
  4. Remove AGENTMEMORY_AGENT_SCOPE=isolated if isolation was not the intent.

Example fix

// before
await sdk.trigger({ function_id: "mem::smart-search", payload: { query } });
// after
await sdk.trigger({ function_id: "mem::smart-search", payload: { query, agentId: process.env.AGENT_ID ?? "my-agent" } });
// or, deliberate wildcard:
await sdk.trigger({ function_id: "mem::smart-search", payload: { query, agentId: "*" } });
Defensive patterns

Strategy: validation

Validate before calling

const isolated = process.env.AGENTMEMORY_AGENT_SCOPE === "isolated";
if (isolated && !payload.agentId && !process.env.AGENT_ID) {
  throw new Error("isolated scope needs AGENT_ID env or explicit agentId in payload");
}

Type guard

function hasAgentScope(p: { agentId?: string }): p is typeof p & { agentId: string } {
  return typeof p.agentId === "string" && p.agentId.length > 0;
}

Try / catch

try {
  return await sdk.trigger({ function_id: "mem::smart-search", payload });
} catch (e) {
  if (String(e.message).includes("no agent id is available")) {
    return await sdk.trigger({ function_id: "mem::smart-search", payload: { ...payload, agentId: process.env.AGENT_ID ?? "*" } });
  }
  throw e;
}

Prevention

When it happens

Trigger: Running with AGENTMEMORY_AGENT_SCOPE=isolated while AGENT_ID is not exported in the process environment, and calling sdk.trigger({ function_id: 'mem::smart-search', payload: { query } }) without an agentId field in the payload.

Common situations: Developers set the isolation flag in a .env or deployment config but forget to set AGENT_ID; local test harnesses spawn functions without the daemon's env; scripts call the REST API without forwarding an agentId header/field.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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