Skip to content

Memory API

Persistent agent memory is the pydantic-ai-harness Memory capability over a FileStore in the run's workspace. Enable it via include_memory=True (default) on create_deep_agent, which builds it with build_memory_capability. See Memory for the conceptual overview.

pydantic-deep's own memory API - AgentMemoryToolset, MemoryCapability, MemoryFile, load_memory, format_memory_prompt - is deprecated: it still imports, with a DeprecationWarning, and nothing uses it.

build_memory_capability

pydantic_deep.features.memory.store.build_memory_capability(*, agent_name, store=None, memory_dir=DEFAULT_MEMORY_DIR, namespace='', max_lines=None, max_tokens=None, max_memory_size=None, pin_marker=None)

The Memory capability one agent remembers with.

Shared by the main agent and every subagent, so their wiring cannot drift.

Parameters:

Name Type Description Default
agent_name str

The agent's own segment in the store; sanitized for the harness.

required
store FileStore | None

The store to remember in. Agents writing to one directory should share one: its copies share a lock, which keeps the receipts beside the notebooks consistent. A new FileStore(memory_dir) when None.

None
memory_dir str

Directory in the run's workspace, when store is not given.

DEFAULT_MEMORY_DIR
namespace MemoryNamespace

A per-tenant segment above the agent's, fixed or resolved per run. The model never sees or chooses it.

''
max_lines int | None

Most MEMORY.md lines injected; the harness default when None.

None
max_tokens int | None

Approximate ceiling on the injected section; likewise.

None
max_memory_size int | None

Largest memory file, in characters, the tools will read or change; the harness default (65,536) when None.

None
pin_marker str | None

Accepted only to warn - the harness has no pinned section.

None

Raises:

Type Description
ValueError

A fixed namespace the harness would refuse.

MemoryNamespace

pydantic_deep.features.memory.store.MemoryNamespace = str | Callable[[RunContext[Any]], str] module-attribute

A fixed namespace, or one resolved from each run's context - a user id, say.

get_memory_path

pydantic_deep.features.memory.service.get_memory_path(memory_dir, agent_name)

Compute the memory file path for an agent.

Parameters:

Name Type Description Default
memory_dir str

Base directory for memory files.

required
agent_name str

Agent name (e.g., "main", "code-reviewer").

required

Returns:

Type Description
str

Full path like ".deep/memory/main/MEMORY.md".