# MemoryMiddleware

> **Class** in `deepagents`

📖 [View in docs](https://reference.langchain.com/python/deepagents/middleware/memory/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.

## Signature

```python
MemoryMiddleware(
    self,
    *,
    backend: BACKEND_TYPES,
    sources: list[str],
    add_cache_control: bool = False,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `backend` | `BACKEND_TYPES` | Yes | Backend instance or factory function for file operations. |
| `sources` | `list[str]` | Yes | List of `MemorySource` configurations specifying paths and names. |

## Extends

- `AgentMiddleware[MemoryState, ContextT, ResponseT]`

## Constructors

```python
__init__(
    self,
    *,
    backend: BACKEND_TYPES,
    sources: list[str],
    add_cache_control: bool = False,
) -> None
```

| Name | Type |
|------|------|
| `backend` | `BACKEND_TYPES` |
| `sources` | `list[str]` |
| `add_cache_control` | `bool` |


## Properties

- `state_schema`
- `sources`

## Methods

- [`before_agent()`](https://reference.langchain.com/python/deepagents/middleware/memory/MemoryMiddleware/before_agent)
- [`abefore_agent()`](https://reference.langchain.com/python/deepagents/middleware/memory/MemoryMiddleware/abefore_agent)
- [`modify_request()`](https://reference.langchain.com/python/deepagents/middleware/memory/MemoryMiddleware/modify_request)
- [`wrap_model_call()`](https://reference.langchain.com/python/deepagents/middleware/memory/MemoryMiddleware/wrap_model_call)
- [`awrap_model_call()`](https://reference.langchain.com/python/deepagents/middleware/memory/MemoryMiddleware/awrap_model_call)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/1ae053f347679e58562d2b81eb6d6e6e9bbf0b07/libs/deepagents/deepagents/middleware/memory.py#L161)