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:
Protocol for pluggable memory backends (single, unified).
Backends can store files in different locations (state, filesystem, database, etc.) and provide a uniform interface for file operations.
All file data is represented as dicts with the following structure: { "content": list[str], # Lines of text content "created_at": str, # ISO format timestamp "modified_at": str, # ISO format timestamp }
State schema for MemoryMiddleware.
State update for MemoryMiddleware.
Middleware for loading agent memory from AGENTS.md files.
Loads memory content from configured sources and injects into the system prompt.
Supports multiple sources that are combined together.