MemoryMiddleware(
self,
*,
backend: BACKEND_TYPES,
sources: list[str],
add_cache_control:| Name | Type | Description |
|---|---|---|
backend* | BACKEND_TYPES | Backend instance or factory function that takes runtime and returns a backend. Use a factory for StateBackend. |
sources* | list[str] | List of memory file paths to load (e.g., Display names are automatically derived from the paths. Sources are loaded in order. |
add_cache_control | bool | Default: FalseIf This creates a second prompt-cache breakpoint that pairs with
No-ops on non-Anthropic models; Bedrock and Vertex wrappers do not qualify. |
system_prompt | str | None | Default: MEMORY_SYSTEM_PROMPT |
| Name | Type |
|---|---|
| backend | BACKEND_TYPES |
| sources | list[str] |
| add_cache_control | bool |
| system_prompt | str | None |
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. See constructor for the full argument list.
System-prompt fragment template. Must contain a
{agent_memory} slot for runtime memory substitution. Pass
None to skip appending entirely (memory is still loaded
into state["memory_contents"]).