# createMemoryMiddleware

> **Function** in `deepagents`

📖 [View in docs](https://reference.langchain.com/javascript/deepagents/middleware/createMemoryMiddleware)

Create 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

```javascript
createMemoryMiddleware(options: MemoryMiddlewareOptions): AgentMiddleware<StateSchema<__type>, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `options` | `MemoryMiddlewareOptions` | Yes | Configuration options |

## Returns

`AgentMiddleware<StateSchema<__type>, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>`

AgentMiddleware for memory loading and injection

## Examples

```typescript
const middleware = createMemoryMiddleware({
  backend: new FilesystemBackend({ rootDir: "/" }),
  sources: [
    "~/.deepagents/AGENTS.md",
    "./.deepagents/AGENTS.md",
  ],
});
```

---

[View source on GitHub](https://github.com/langchain-ai/deepagentsjs/blob/d879d1c979abc589c77489154f913db862d4d130/libs/deepagents/src/middleware/memory.ts#L285)