CH 05 · Context Engineering and Memory · 16/18
Read as one pageReal code: OpenClaw surfaces memory per session
filterBootstrapFilesForSession decides which workspace files this session's prompt includes. A private chat keeps the workspace-root MEMORY.md. A group or channel drops that root file and can keep a nested MEMORY.md. A helper's prompt keeps only AGENTS.md, and a cron run keeps four names. A leaf helper can still call memory_search and memory_get.
const SUBAGENT_BOOTSTRAP_ALLOWLIST = new Set([DEFAULT_AGENTS_FILENAME]); // [1]
const CRON_BOOTSTRAP_ALLOWLIST = new Set([ // [2]
DEFAULT_AGENTS_FILENAME,
DEFAULT_SOUL_FILENAME,
DEFAULT_IDENTITY_FILENAME,
DEFAULT_USER_FILENAME,
]);
// ... (29 lines: remove the workspace-root MEMORY.md from shared sessions)
export function filterBootstrapFilesForSession(
files: WorkspaceBootstrapFile[], // [3]
session?: string | BootstrapSessionContext,
): WorkspaceBootstrapFile[] {
const { sessionKey, chatType, workspaceDir }: BootstrapSessionContext =
typeof session === "string" ? { sessionKey: session } : (session ?? {});
const isSubagent = isSubagentSessionKey(sessionKey);
const isCron = isCronSessionKey(sessionKey);
const effectiveChatType = chatType ?? deriveSessionChatTypeFromKey(sessionKey);
const isNonPrivate =
isSubagent || isCron || effectiveChatType === "group" || effectiveChatType === "channel"; // [4]
const privacyFilteredFiles = isNonPrivate
? filterRootMemoryBootstrapFiles(files, workspaceDir)
: files;
if (isSubagent) {
return privacyFilteredFiles.filter((file) => SUBAGENT_BOOTSTRAP_ALLOWLIST.has(file.name));
}
if (isCron) {
return privacyFilteredFiles.filter((file) => CRON_BOOTSTRAP_ALLOWLIST.has(file.name)); // [5]
}
return privacyFilteredFiles;
}
Source: openclaw/openclaw, src/agents/workspace.ts (MIT)
What to notice
- [1]
DEFAULT_AGENTS_FILENAMEis"AGENTS.md". A helper session's prompt is reduced to that one file. - [2] A cron run keeps
AGENTS.md,SOUL.md,IDENTITY.md, andUSER.md.MEMORY.mdandBOOTSTRAP.mdare not on the list. - [3] A
WorkspaceBootstrapFileis a name, a path, the text, and amissingflag. The second argument is a session key, or an object that can set the chat type. An explicit chat type overrides the key. - [4] A helper, a cron run, a group, or a channel first drops the workspace-root
MEMORY.md. A private chat skips that cut. - [5] The allowlists run after that cut and match on
file.name. A group keeps the other files, includingUSER.md. The root memory file is already gone before the cron list is applied.
Pasting MEMORY.md into every prompt puts those notes in a shared room and crowds a helper. The filter leaves the root file in the private session's prompt and out of the others. Searching memory is a separate path: the leaf-helper tool policy still allows it.
Read it yourself: open the cron test under filterBootstrapFilesForSession in src/agents/workspace-bootstrap.test-utils.ts. It keeps those four names. Then open src/agents/agent-tools.policy.test.ts and confirm a leaf helper may still call memory_search and memory_get.
Finished this idea?
Your learning progress stays in this browser.