rohitg00/agentmemory · error · Error
mem::context: AGENTMEMORY_AGENT_SCOPE=isolated is set but no
Error message
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.
What it means
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.
Source
Thrown at src/functions/context.ts:65
const blocks: ContextBlock[] = [];
// Cross-agent isolation for the injected-context path. Mirrors the
// filter mem::search / mem::smart-search already apply so /context
// cannot leak another profile's sessions. Fail-closed: if isolated
// mode is on with no explicit agentId and env AGENT_ID unset, refuse
// rather than silently returning cross-agent rows.
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::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.',
);
}
const [pinnedSlots, profile, lessons] = await Promise.all([
isSlotsEnabled()
? listPinnedSlots(kv).catch(() => [] as MemorySlot[])
: Promise.resolve([] as MemorySlot[]),
kv
.get<ProjectProfile>(KV.profiles, data.project)
.catch(() => null),
kv.list<Lesson>(KV.lessons).catch(() => [] as Lesson[]),
]);
const slotContent = renderPinnedContext(pinnedSlots);View on GitHub (pinned to e04ba88819)
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.
Example fix
// before
await trigger({ function_id: 'mem::context', payload: { query: 'auth' } });
// after
await trigger({ function_id: 'mem::context', payload: { query: 'auth', 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::context', payload });
} catch (e) {
if (String(e.message).includes('no agent id is available')) {
return await trigger({ function_id: 'mem::context', payload: { ...payload, agentId: '*' } });
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- mem::search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no
- Invalid dateFrom: ${filter.dateFrom}
- Invalid dateTo: ${filter.dateTo}
- Refusing to read image outside managed store: ${data.raw.ima
- mem::search: query must be a non-empty string
AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30).
Data as JSON: /api/errors/a1a407f8b31b2e00.
Report an issue: GitHub.