Expand description
Persistent per-agent memory backed by MEMORY.md files on the local filesystem.
Each sub-agent with a MemoryScope gets an isolated directory on first spawn.
The first 200 lines of MEMORY.md are injected into the system prompt so the agent
can recall information across sessions.
Security guarantees:
- Directory paths are validated against
AGENT_NAME_REto prevent path traversal. MEMORY.mdis canonicalized and boundary-checked before reading (symlink escape guard).- Files larger than 256 KiB or containing null bytes are rejected.
<agent-memory>tags in file content are escaped to prevent prompt injection.
Functionsยง
- ensure_
memory_ dir - Ensure the memory directory exists, creating it if necessary.
- escape_
memory_ content - Escape
<agent-memory>and</agent-memory>tags from memory content. - load_
memory_ content - Reads
MEMORY.mdfrom the given directory and returns the first 200 lines. - resolve_
memory_ dir - Resolve the memory directory path for a given scope and agent name.