Skip to content
Back to skills

2634 Memory Ec76aa09

ASecurity

Persistent memory gives agents a `MEMORY.md` file stored in the backend that survives across sessions. Memory is auto-loaded into the system prompt and writable via tools.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
developmentjavascripttypescriptpythonjavasqlcode-reviewbackend

Works with

  • claude code

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2634-memory_ec76aa09 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2634 Memory Ec76aa09?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2634 Memory Ec76aa09
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2634-memory-ec76aa09/badge)](https://www.skillsdirectory.com/skills/tools-only-2634-memory-ec76aa09)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Persistent Memory

Persistent memory gives agents a `MEMORY.md` file stored in the backend that survives across sessions. Memory is auto-loaded into the system prompt and writable via tools.

## Quick Start

```python
from pydantic_deep import create_deep_agent

agent = create_deep_agent(include_memory=True)
```

The agent gets three memory tools:

| Tool | Description |
|------|-------------|
| `read_memory` | Read full memory content |
| `write_memory` | Append new content to memory |
| `update_memory` | Find and replace text in memory |

Memory is also automatically injected into the system prompt (first 200 lines) so the agent sees it without needing to call `read_memory`.

## Configuration

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `include_memory` | `bool` | `False` | Enable persistent memory |
| `memory_dir` | `str` | `"/.deep/memory"` | Base directory for memory files |

### Storage Layout

Each agent gets its own memory file:

```
/.deep/memory/
  main/MEMORY.md          # Main agent's memory
  code-reviewer/MEMORY.md # Subagent's memory
  test-writer/MEMORY.md   # Another subagent's memory
```

## How It Works

### System Prompt Injection

When memory exists, the [`AgentMemoryToolset`][pydantic_deep.toolsets.memory.AgentMemoryToolset] injects it into the system prompt via `get_instructions()`:

```
## Agent Memory (main)

- User prefers TypeScript over JavaScript
- Project uses PostgreSQL with Prisma ORM
- Always run `npm test` before committing
```

Only the first 200 lines are included to stay within token budget. If truncated, a marker is added:

```
... [50 more lines in memory] ...
```

### Writing Memory

The agent appends to memory when it learns something worth remembering:

```
Agent: I notice you always prefer functional programming patterns.
       Let me save this to memory.
       [calls write_memory("- User prefers functional patterns over OOP")]
```

### Updating Memory

The agent can find-and-replace text to correct or update entries:

```
Agent: The project switched from MySQL to PostgreSQL.
       [calls update_memory("Uses MySQL", "Uses PostgreSQL")]
```

## Subagent Memory

When `include_memory=True`, all subagents automatically get their own memory files. Each subagent writes to `{memory_dir}/{subagent_name}/MEMORY.md`.

### Disabling Memory for Specific Subagents

Use `extra={"memory": False}` in the subagent config:

```python
from pydantic_deep import SubAgentConfig

subagents = [
    SubAgentConfig(
        name="code-reviewer",
        description="Reviews code",
        instructions="...",
        # Memory enabled by default
    ),
    SubAgentConfig(
        name="ephemeral-worker",
        description="One-off tasks",
        instructions="...",
        extra={"memory": False},  # No memory for this subagent
    ),
]

agent = create_deep_agent(
    include_memory=True,
    subagents=subagents,
)
```

### Custom Max Lines per Subagent

```python
SubAgentConfig(
    name="code-reviewer",
    description="Reviews code",
    instructions="...",
    extra={"memory_max_lines": 50},  # Only inject 50 lines
)
```

!!! warning "Multi-User Applications"
    Memory writes to the backend at `{memory_dir}/{agent_name}/MEMORY.md`. If multiple users
    share the same backend instance, they share the same memory files. For multi-user apps,
    give each user a separate backend instance. See [Multi-User Guide](multi-user.md).

## Standalone Usage

Use `AgentMemoryToolset` directly for custom setups:

```python
from pydantic_deep.toolsets.memory import AgentMemoryToolset

memory_toolset = AgentMemoryToolset(
    agent_name="my-agent",
    memory_dir="/.custom/memory",
    max_lines=100,
)
```

## Components

| Component | Description |
|-----------|-------------|
| [`AgentMemoryToolset`][pydantic_deep.toolsets.memory.AgentMemoryToolset] | Toolset with memory tools and system prompt injection |
| [`MemoryFile`][pydantic_deep.toolsets.memory.MemoryFile] | Loaded memory file (agent_name, path, content) |
| [`load_memory`][pydantic_deep.toolsets.memory.load_memory] | Load memory from backend |
| [`format_memory_prompt`][pydantic_deep.toolsets.memory.format_memory_prompt] | Format memory for system prompt |
| [`get_memory_path`][pydantic_deep.toolsets.memory.get_memory_path] | Compute memory file path |

## Next Steps

- [Context Files](context-files.md) — Project context (DEEP.md, AGENTS.md)
- [Hooks](hooks.md) — Claude Code-style lifecycle hooks
- [Checkpointing](checkpointing.md) — Save and rewind conversation state

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.