# ManagedMemoryGuardMiddleware

> **Class** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/memory_guard/ManagedMemoryGuardMiddleware)

Revert agent edits to the managed onboarding-name memory block.

Guards the managed onboarding-name block in a fixed set of memory files. A
`write_file`/`edit_file` that leaves the managed block untouched passes
through; one that alters or drops it has the block restored (other edits
kept) and returns an error. A `delete` targeting a guarded file (or a parent
directory that contains one) is rejected outright before the tool runs when
the file holds a managed block or exists but cannot be read. If the restore
itself fails, an error is still returned so the failure is never silent.

## Signature

```python
ManagedMemoryGuardMiddleware(
    self,
    guarded_paths: Iterable[str | Path],
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `guarded_paths` | `Iterable[str \| Path]` | Yes | Paths whose managed onboarding-name block must be protected from agent edits. Resolved to absolute form for matching; unresolvable entries are skipped. |

## Extends

- `AgentMiddleware`

## Constructors

```python
__init__(
    self,
    guarded_paths: Iterable[str | Path],
) -> None
```

| Name | Type |
|------|------|
| `guarded_paths` | `Iterable[str \| Path]` |


## Methods

- [`wrap_tool_call()`](https://reference.langchain.com/python/deepagents-code/memory_guard/ManagedMemoryGuardMiddleware/wrap_tool_call)
- [`awrap_tool_call()`](https://reference.langchain.com/python/deepagents-code/memory_guard/ManagedMemoryGuardMiddleware/awrap_tool_call)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/7794b61a6e76230e8c7a49bdce808b3728305914/libs/code/deepagents_code/memory_guard.py#L95)