Learning resourcesReviewed · Pydantic

Pydantic AI Harness Memory guide

The Pydantic AI Harness Memory guide shows Python agent developers how to keep notes between runs, but those notes are untrusted and storage permissions need careful setup. It covers bounded prompt snapshots, searchable Markdown notebooks, concurrency controls and file or database storage.

Researched 25 Nov 2026

In short.

The Pydantic AI Harness Memory guide explains reusable agent notebooks for Python developers, but saved notes can carry false claims or hostile instructions and namespaces alone do not enforce access control. It documents notebook tools, bounded prompt snapshots, storage backends, concurrent updates and durable execution. It provides concrete integration guidance, including important file-access and scanning exceptions. No code was executed; runtime reliability, performance, costs and licensing are not established.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is the complete captured page at [https://pydantic.dev/docs/ai/harness/memory/index.md], including notebook tools, injection timing and limits, FileSystem reader substitution, storage and concurrency, namespaces, metadata, multiple memories, search, configuration, agent specifications, durable execution, security, scanning and the included API reference. The documentation-index and query-parameter notices are present but do not establish feature behavior. Linked pages and repository files are excluded. No code was executed; runtime correctness, isolation, scanner effectiveness, compatibility, performance, costs and licensing remain unassessed or unknown.

The overview

Identity

This is the Memory feature guide and API reference for Pydantic AI Harness at [https://pydantic.dev/docs/ai/harness/memory/index.md]. It teaches developers to add the Memory capability to a Pydantic AI agent; the page itself is documentation.

The documented design gives an agent a Markdown notebook, with MEMORY.md for short notes and additional files for longer topics. Memory supplies tools and can automatically include a bounded notebook snapshot in model context.

Assessment

Based on the documented design, this guide fits developers already building with Pydantic AI who want explicit, editable notes across agent runs. Its useful detail includes what happens when storage fails, when snapshots appear, how writes conflict and where user isolation can break down.

It does not establish that remembered information improves answer quality or that a particular deployment is reliable. The feature also needs integration work: developers must choose storage, manage permissions and decide which remembered content may enter prompts.

Users

Python developers adding persistent preferences, project notes or task knowledge to agents are the clearest audience. Beginners get a notebook model and short configuration examples, but need familiarity with Python and agent configuration. Experienced developers get store protocols, transactional requirements, namespace rules and workflow-replay details.

Multi-user services are addressed directly through application-resolved namespaces and optional write metadata. Teams needing built-in semantic retrieval should account for the fact that bundled search is literal text search; a custom backend can implement semantic search.

Capabilities

The documented tools append notes or replace one unique text passage, read a bounded file prefix, delete files other than the protected main notebook, and search notebook files. Automatic prompt inclusion can be disabled while keeping the tools available.

Storage options include process-local memory, Markdown files, SQLite, PostgreSQL and Pixeltable. Supported capabilities also include current-write metadata on selected stores, multiple notebooks on one agent, optional content scanning, telemetry and integration with Temporal, Prefect and DBOS.

Default injection is limited to approximately 2,000 tokens shared by guidance, notebook content and filenames, with a separate 200-line cap. Default per-file reads and edits are bounded at 65,536 characters. Search defaults are 10 matches, 4,000 combined filename-and-snippet characters and 1,000 files for a fallback scan.

Using it

Requirements

The examples use a Python application with Pydantic AI, pydantic_ai_harness and a configured model. FileMemoryStore needs the run's workspace unless it has a workspace of its own. Read-only workspace permissions hide write and delete tools; an independently configured store workspace follows its own permissions.

PostgreSQL needs an application-managed driver and connection pool. Initial schema setup needs broader database permissions than ordinary operation. A caller-owned SQLite connection must use check_same_thread=False, be dedicated to the store and be idle before each operation.

The page does not establish a general minimum Python version or a complete package installation procedure. Its Pixeltable integration specifically requires the pixeltable extra and Python 3.11 to 3.14.

Mechanism

Memory normally adds a snapshot alongside the user's prompt on the first request of a run, when memory differs from the latest applicable snapshot. Stored notes are user-role data, separate from trusted usage guidance. Later requests carry the same snapshot in conversation history. Changes made during a run become eligible for a new snapshot with the next user prompt.

Writes use compare-and-swap: an edit based on an outdated version conflicts instead of overwriting a newer edit. Operation identifiers prevent a replayed mutation from being applied twice. Custom stores must enforce version checks and replay protection atomically.

When compaction removes the current run's snapshot, Memory restores that same snapshot without rereading storage. Temporal and Prefect journal snapshot loading, while DBOS also records memory tools as steps. Callable namespace and store resolvers must be deterministic and avoid backend I/O for Temporal and Prefect. Workflow durability does not make an in-memory store persistent.

Setup

The local-file example adds LocalWorkspace('.') and Memory(FileMemoryStore('.agent-memory')) to an Agent's capabilities. Memory is imported from pydantic_ai_harness and FileMemoryStore from pydantic_ai_harness.memory. The notebook limits can then be configured on Memory.

For multiple users, application code resolves a namespace from validated dependencies. A store workspace of its own keeps memory outside the agent's general workspace file access. Separate notebooks on one agent need distinct capability IDs, separate storage scopes when appropriate, tool-name prefixes and distinguishing headings.

For agent specifications, register Memory through custom_capability_types. Serializable backend choices are memory, file and sqlite; callable namespaces and live PostgreSQL pools require Python configuration. Set injection_errors='raise' if a run must stop when automatic memory loading fails; the default skips injection for store failures.

Example

An illustrative application is an assistant that remembers a user's preferred response format and keeps longer project notes separately. Application code validates the user and resolves their namespace. The agent can write the short preference to MEMORY.md and project details to another file.

On a later run with a user prompt, changed memory can appear in the bounded snapshot; longer notes remain available through reading or search. This illustrates the documented mechanism, not an observed execution. Storing a preference does not establish that it is correct, current or genuinely supplied by that user.

Assessment & evidence

Limitations

Delimited memory remains untrusted model-written content, not a hard prompt-injection boundary. The optional ArtifactScanner uses pattern matching, can miss paraphrased attacks and can flag quoted attacks. It is disabled by default. Reads through FileSystem or other tools bypass Memory's scanning.

Namespaces control which records the capability addresses; they are not authorization. General workspace file tools can read other namespaces under the memory directory. FileSystem can also replace read_memory even when its own access patterns prevent opening the files. The documented remedy for these arrangements is a separate store workspace.

FileMemoryStore supports one writer per directory, not coordination between independent instances or processes. It retains only 1,024 mutation receipts; a corrupt receipt journal restarts replay protection after a warning. Case-insensitive filesystems can merge differently cased namespaces, and Windows trailing-dot behavior creates another collision risk.

Bounded snapshots and searches can omit relevant content, and edits refuse files larger than max_memory_size. Disabling injection leaves earlier snapshots in history. Telemetry's unsalted scope hashes hide literal identities but allow guessed identities to be confirmed.

Design trade-offs

The documented design suggests a practical trade-off between bounded context and automatic recall. A short main notebook limits what enters each snapshot, while longer files remain available on demand. Relevant information outside those bounds still needs to be retrieved by the agent.

Concurrency controls protect updates, not factual accuracy. Write metadata can identify the writer of the current version on InMemoryMemoryStore, SqliteMemoryStore and PostgresMemoryStore, but it does not verify a remembered claim or preserve a complete authorship history. A write without metadata clears the current metadata.

Storage choice changes the reliability boundary. A shared FileMemoryStore instance serializes its own operations; database-backed stores provide transactional coordination for the concurrency arrangements described by the page. Those documented guarantees still need validation in the intended deployment.

Alternatives

Within this feature, InMemoryMemoryStore lasts only for the process lifetime. FileMemoryStore keeps editable Markdown files with one writer per directory. SQLite offers durable single-host storage, PostgreSQL offers durable shared storage, and Pixeltable keeps memory in a shared catalog.

An alternative to automatic prompt inclusion is inject_memory=False, retaining tools for on-demand retrieval. The guide recommends application-controlled retrieval when less-trusted writers require stronger isolation. A custom searchable store can supply indexed or semantic retrieval while preserving namespace boundaries and result limits.

The page does not compare other agent frameworks or memory products, so their relative quality, cost and interoperability are not assessed.

Evidence

The evidence is the complete Memory documentation page at [https://pydantic.dev/docs/ai/harness/memory/index.md], captured on 25 November 2026 at 07:13:01.930 UTC. It contains explanations, configuration examples, backend contracts and API descriptions.

The document snapshot has SHA-256 329378a6b91ea9da55763da3425c2e225b43573ec2cf2e1f481731db2ff551aa. This identifies the captured document, not a software release. Linked documentation and repository contents were outside scope. No code was executed, and the page provides no independent benchmark or deployment results.

Access & freshness

Costs

The page gives no access price, package fee, model pricing or hosting rates. Total cost is unknown. It also provides no measured latency, throughput or cost comparison between backends.

Snapshots occupy model context and remain in history for later requests. The documentation describes prompt-prefix caching behavior but supplies no measured billing savings. Storage, database hosting and retained operation receipts can add operational costs; the 2,000-token injection default is a context limit, not a total usage estimate.

Rights

The supplied page does not state the software or documentation licence. Commercial-use and redistribution permissions are therefore unknown from this evidence. Its link to source code does not itself establish those permissions.

The page does not establish ownership or retention terms for user notes. It advises against storing secrets without suitable backend controls and retention policies. Deleting stored content also does not establish removal of earlier snapshots already present in conversation history.

Freshness

The captured page warns that Pydantic AI Harness is on 0.x releases and that minor releases may change APIs, with deprecation warnings and migration guidance. It does not identify an exact package release or a last-update date.

Compatibility with a particular installed version is unassessed. The page also describes migration-sensitive database behavior: older PostgreSQL tables do not automatically receive the newer path index, while added metadata columns are created on first use.

Next steps

Before adoption, identify the intended harness release and check its matching API documentation. Choose storage according to persistence and concurrent-writer needs, define namespace normalization and identity validation, and decide whether automatic memory inclusion is appropriate.

Evaluate workspace isolation, conflicting updates, replayed operations, unavailable storage, oversized files and retrieval of notes outside the snapshot. If scanning is enabled, include file-tool bypasses in that evaluation. These are suggested checks, not completed tests.

Plan backups and retention for notes, conversation history and mutation receipts. FileMemoryStore backups need its .memory-operations.json journal alongside the Markdown files to retain recent replay protection. Confirm licensing and estimate model, storage and hosting costs separately.

Evidence for this report

selected-page.txtselected · checked 2026-11-25