Skip to main content

Module memory

Module memory 

Source
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_RE to prevent path traversal.
  • MEMORY.md is 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.md from the given directory and returns the first 200 lines.
resolve_memory_dir
Resolve the memory directory path for a given scope and agent name.