{"record":{"id":"a1a407f8b31b2e00","repo":"rohitg00/agentmemory","slug":"mem-context-agentmemory-agent-scope-isolated-is","errorCode":null,"errorMessage":"mem::context: 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.","messagePattern":"mem::context: 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\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/functions/context.ts","lineNumber":65,"sourceCode":"      const blocks: ContextBlock[] = [];\n\n      // Cross-agent isolation for the injected-context path. Mirrors the\n      // filter mem::search / mem::smart-search already apply so /context\n      // cannot leak another profile's sessions. Fail-closed: if isolated\n      // mode is on with no explicit agentId and env AGENT_ID unset, refuse\n      // rather than silently returning cross-agent rows.\n      const isolated = isAgentScopeIsolated();\n      const explicitAgentId =\n        typeof data.agentId === \"string\" && data.agentId.trim().length > 0\n          ? data.agentId.trim()\n          : undefined;\n      const wildcardAgent = explicitAgentId === \"*\";\n      const envAgentId = isolated ? getAgentId() : undefined;\n      const filterAgentId = wildcardAgent\n        ? undefined\n        : explicitAgentId ?? envAgentId;\n      if (isolated && !wildcardAgent && !explicitAgentId && !envAgentId) {\n        throw new Error(\n          \"mem::context: AGENTMEMORY_AGENT_SCOPE=isolated is set but no \" +\n            \"agent id is available (env AGENT_ID unset and no explicit \" +\n            \"agentId in the call). Refusing to read cross-agent rows. \" +\n            'Pass agentId: \"*\" to opt in to a wildcard read.',\n        );\n      }\n\n      const [pinnedSlots, profile, lessons] = await Promise.all([\n        isSlotsEnabled()\n          ? listPinnedSlots(kv).catch(() => [] as MemorySlot[])\n          : Promise.resolve([] as MemorySlot[]),\n        kv\n          .get<ProjectProfile>(KV.profiles, data.project)\n          .catch(() => null),\n        kv.list<Lesson>(KV.lessons).catch(() => [] as Lesson[]),\n      ]);\n\n      const slotContent = renderPinnedContext(pinnedSlots);","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/functions/context.ts#L47-L83","documentation":"When AGENTMEMORY_AGENT_SCOPE=isolated is enabled, mem::context only reads memory rows belonging to one agent. If no agent id can be resolved — no explicit agentId in the call and no AGENT_ID env var — the function refuses to fall back to a cross-agent read and throws. Pass agentId: \"*\" to explicitly opt into a wildcard read.","triggerScenarios":"Running with AGENTMEMORY_AGENT_SCOPE=isolated while calling mem::context (directly, via REST /context, or via the MCP memory_context tool) with neither agentId in the payload nor AGENT_ID set in the daemon environment.","commonSituations":"Daemon started without AGENT_ID exported (set in shell but not in the daemon's systemd/Docker env); per-agent isolation recently enabled but call sites not updated; MCP client not forwarding agentId.","solutions":["Set the AGENT_ID environment variable for the daemon process and restart it.","Pass an explicit agentId in the call payload.","Pass agentId: \"*\" if a cross-agent read is genuinely intended.","Remove AGENTMEMORY_AGENT_SCOPE=isolated if isolation is not desired."],"exampleFix":"// before\nawait trigger({ function_id: 'mem::context', payload: { query: 'auth' } });\n// after\nawait trigger({ function_id: 'mem::context', payload: { query: 'auth', agentId: process.env.AGENT_ID ?? '*' } });","handlingStrategy":"validation","validationCode":"const agentId = explicitAgentId ?? process.env.AGENT_ID ?? '*';\nif (!agentId) throw new Error('agentId required under isolated scope');","typeGuard":"function hasAgentId(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  return await trigger({ function_id: 'mem::context', payload });\n} catch (e) {\n  if (String(e.message).includes('no agent id is available')) {\n    return await trigger({ function_id: 'mem::context', payload: { ...payload, agentId: '*' } });\n  }\n  throw e;\n}","preventionTips":["Export AGENT_ID in every environment that runs the daemon (Docker, systemd).","Always pass agentId explicitly in multi-agent call sites.","Only set AGENTMEMORY_AGENT_SCOPE=isolated intentionally.","Use agentId: \"*\" deliberately and log when you do."],"tags":["multi-agent","isolation","environment-variable","validation"],"backgroundTag":"agent-scope-isolated-no-agent-id","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}