Middleware for loading agent memory/context from AGENTS.md files.
This module implements support for the AGENTS.md specification (https://agents.md/), loading memory/context from configurable sources and injecting into the system prompt.
AGENTS.md files provide project-specific context and instructions to help AI agents work effectively. Unlike skills (which are on-demand workflows), memory is always loaded and provides persistent context.
from deepagents import MemoryMiddleware
from deepagents.backends.filesystem import FilesystemBackend
# Security: FilesystemBackend allows reading/writing from the entire filesystem.
# Either ensure the agent is running within a sandbox OR add human-in-the-loop (HIL)
# approval to file operations.
backend = FilesystemBackend(root_dir="/")
middleware = MemoryMiddleware(
backend=backend,
sources=[
"~/.deepagents/AGENTS.md",
"./.deepagents/AGENTS.md",
],
)
agent = create_deep_agent(middleware=[middleware])
Sources are simply paths to AGENTS.md files that are loaded in order and combined. Multiple sources are concatenated in order, with all content included. Later sources appear after earlier ones in the combined prompt.
AGENTS.md files are standard Markdown with no required structure. Common sections include: