In short.
The Step Persistence guide teaches Python developers how to save and continue Pydantic AI agent conversations, but applications must manage recovery and decide whether repeating tool actions is safe. Its StepPersistence capability combines message-history snapshots, an append-only event trail and a tool-effect ledger across memory, file, SQLite, MongoDB and PostgreSQL stores. The page provides substantial implementation guidance, including retention and upgrade hazards, but establishes no independently assessed reliability, performance or costs.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage includes the complete selected page at [https://pydantic.dev/docs/ai/harness/step-persistence/index.md], including backend requirements, retention behavior, media handling, conversation support, deprecation and compatibility notices, and the API reference. Linked pages, source files, issue reports and release notes are excluded. No code was executed; documented behavior, maintainer CI claims, recovery guarantees and performance were not independently assessed.
The overview
Identity
This is the Step Persistence documentation page for Pydantic AI Harness at [https://pydantic.dev/docs/ai/harness/step-persistence/index.md]. It documents the StepPersistence capability and the pydantic_ai_harness.step_persistence module, including storage, recovery helpers and related conversation support.
The resource is a developer guide with API reference material and illustrative Python examples. Its central feature is saving agent messages at settled boundaries so another Agent.run call can continue or branch from that history.
Assessment
The guide is useful when an application needs inspectable agent history and control over when to continue an investigation. It explains both the convenient path, loading the latest complete checkpoint, and the difficult case, determining what an interrupted external action actually did.
Its strongest practical distinction is between preserving messages and recovering execution. StepPersistence does not restart a worker or automatically finish an interrupted step. A complete checkpoint means recorded tool calls have matching results; it does not mean later external changes were undone or that replay is safe.
Users
The primary audience is Python developers already using Pydantic AI, especially those building multi-turn assistants, orchestrators that delegate work, or agents whose investigations must remain accessible after a process exits. Beginners receive examples, but need familiarity with asynchronous Python, agent configuration and persistent storage.
Teams choosing among local files, SQLite and database services get concrete operational caveats. Applications requiring unattended recovery, workspace restoration or guarantees against repeated external actions need additional mechanisms beyond this capability.
Capabilities
StepPersistence records run, model-request and tool-call events; saves message snapshots; and tracks tool calls as started, completed or failed. continue_run and fork_run return saved messages for a subsequent Agent.run call. Default reads select complete snapshots, while interrupted snapshots require an explicit opt-in.
The five built-in stores are InMemoryStepStore, FileStepStore, SqliteStepStore, MongoStepStore and PostgresStepStore. Persistent backends can externalize binary content and large text through media storage. Optional capture_frontier checkpoints preserve accepted requests and proposed tool calls earlier in execution.
Separate SQLite conversation support stores accepted conversation history and between-run edits, with revision-conflict detection, search, archiving and naming metadata. SnapshotSavedEvent supplies notifications after checkpoint writes, but committed storage remains authoritative.
Using it
Requirements
Implementation needs a configured Pydantic AI Agent, Pydantic AI Harness and an appropriate StepStore. The page does not establish a minimum Python version or an exact compatible package-release combination. Model access and credentials depend on the chosen agent configuration.
In-memory storage is process-local. File and SQLite stores need suitable local storage. MongoDB support uses the mongodb extra, documented as installing pymongo>=4.17.0, and requires index-creation privileges on first write.
PostgreSQL requires an application-managed asyncpg-compatible pool and schema-creation privileges on first use, including reads. The application must install its driver and close the pool. The separate SqliteConversationStore uses local process checks and must not be shared between hosts.
Mechanism
The capability saves a complete checkpoint after a settled tool-call batch, incorporating the tool returns before the next model request. Normal completion can save a final checkpoint, and handled run failures can save live failure history. A hard process kill cannot rely on failure hooks; useful checkpoints must already have been written.
Recovery loads messages and supplies them to Agent.run through message_history. By default, continue_run skips interrupted checkpoints and raises LookupError if no suitable checkpoint exists. inspect_recovery exposes checkpoint and tool-effect information without deciding whether replay is safe.
A run_id identifies one Agent.run invocation, conversation_id groups multiple turns, and parent_run_id records delegation lineage. In-process nested delegation can infer the parent through a ContextVar; cross-process delegation needs explicit linkage. Persistence idempotency keys suppress duplicate store writes during durable replay, not duplicate actions in external systems.
Setup
Choose a store and attach StepPersistence(store=store, agent_name='code_librarian') through the Agent capabilities argument. The page demonstrates InMemoryStepStore for simple examples and FileStepStore('runs', max_snapshots_per_run=8) for persistent files with bounded checkpoint retention.
Use conversation_id on Agent.run to group turns. Let each call receive its own run_id: reusing a fixed explicit run_id across separate calls raises ValueError. An agent_name changes the derived persistence identifier, so lookups must use the corresponding stored run identity.
For MongoDB, the documented installation command is pip install "pydantic-ai-harness[mongodb]". For PostgreSQL, construct the store with a live pool during application startup. Review database permissions and existing schemas first: PostgreSQL creates missing objects but does not migrate an incompatible existing layout.
Example
The guide illustrates a code-librarian agent answering an initial investigation question with conversation_id='libr-conv'. A later turn finds the most recent run using store.list_runs(conversation_id='libr-conv'), loads its messages with continue_run, and passes those messages into a new agent call with a follow-up question.
For a crash involving a tool that changes an issue label, the documented approach is to inspect unresolved tool effects before continuing. annotate_tool_effect can record an application idempotency key and a description of the intended change. Those annotations help reconciliation; they do not enforce deduplication.
These are documented usage examples. No code was executed, and neither the continuation example nor the crash-recovery behavior was independently assessed.
Assessment & evidence
Limitations
Snapshots do not restore capability state outside messages, graph-node state, retry counters, workspace files or in-flight streaming responses. Automatic execution recovery and automatic deduplication of external actions are not implemented.
A started tool with no terminal record has an unknown outcome after a crash. A failed tool may already have changed external state. Checkpoints are saved per settled batch rather than per tool, so a hard kill during parallel execution can leave a completed ledger entry without its result in a saved checkpoint.
Retention can preserve more than the configured snapshot count to keep the newest complete recovery point. Pruning can remove pre-compaction history while leaving events, media and some deduplicated messages stored. MongoDB media offloading is per value, so a message containing many small parts can still exceed its 16 MiB document limit.
Reasoning
The documented design fits applications that want explicit recovery decisions. Messages provide a new agent call with context, events explain execution boundaries, and the tool ledger records which external actions need investigation. Each supplies different information; none alone establishes that repeating an action is safe.
A practical consequence is that tools with external effects need application-level idempotency or reconciliation. Continuing from an older complete checkpoint may repeat work performed after that checkpoint. Likewise, a stored idempotency key describes an intended operation unless the external action actually uses it to prevent duplication.
The separate conversation head matters for multi-turn interfaces because it includes accepted prompts and between-run edits. Concatenating overlapping run snapshots cannot reliably reconstruct that accepted conversation.
Alternatives
Pydantic AI already accepts message_history for carrying context into another run. Applications that already manage history may use that mechanism directly; StepPersistence adds checkpoint storage, run discovery, events and tool-effect bookkeeping.
For automatic replay after restart and retry of an interrupted call, the page points to durable execution engines and discusses DBOS and Temporal. StepPersistence can accompany a durability capability so execution recovery and inspectable history coexist. The linked engine documentation is outside the selected evidence, so their setup and guarantees were not assessed.
DynamoDB, Redis and GCS are not built-in persistence backends. The documented extension path is implementing the StepStore or MediaStore protocol. No comparison with other agent frameworks or checkpointing libraries is provided.
Evidence
The evidence is the complete selected documentation page at [https://pydantic.dev/docs/ai/harness/step-persistence/index.md], including its examples, backend descriptions, warnings and API reference. Its supplied source revision is sha256:b52c3065f5bec27e1c33bcd55d3ea11bd841f49c71b4076bdcb41cb0b2aa6b28.
The page states that maintainer CI exercises MongoDB backends against MongoDB 9.0 and PostgreSQL backends against PostgreSQL 17. These are source claims, not independently observed test results. No commands, examples, crash scenarios or database operations were executed.
Linked repository contents, issue discussions, durability guides, media documentation and release notes are excluded. Runtime correctness, performance, concurrency behavior and compatibility with a particular installed release remain unassessed.
Access & freshness
Costs
The page provides no library pricing, model rates, hosting prices or measured operating costs. Total cost is unknown and depends on model use, checkpoint volume, database or object storage, and recovery behavior.
File snapshots repeat full message history. SQLite, MongoDB and PostgreSQL store individual messages once, but storage still grows. Snapshot retention is unbounded by default; events are not pruned, and externalized media is not garbage-collected. MongoDB and PostgreSQL also retain messages after their referencing snapshots are pruned, so limiting snapshot count does not bound total storage.
The page identifies other resource costs: building MongoDB indexes on collections that already hold data costs time and I/O on the first write, URL-backed media can require downloads, and MongoDB and PostgreSQL media operations hold whole blobs in process memory. It supplies no measurements for these overheads.
Rights
The page links a source directory at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/step_persistence/], but supplies no license text or explicit usage and redistribution grant. Commercial-use, modification and redistribution terms for the library and documentation are not established by this evidence.
Persisted conversations and media can retain user prompts, tool results and external content. Rights to store or share that material depend on its origin and are not established here. The documented SQLite conversation store does not encrypt contents, and deleting a conversation is explicitly not secure erasure.
Freshness
The supplied page was captured on 2026-11-15 at 14:19:01.470 UTC. It does not establish its publication date, last modification date or exact package version. It warns that Pydantic AI Harness APIs can change between minor releases while on 0.x.
Upgrade guidance is operationally significant. Changed tool-failure recording can break replay of older DBOS or Temporal runs; the page advises finishing affected runs or using deployment versioning. It specifically says DBOS application_version must be set explicitly because a library upgrade does not change the computed value.
Media formats and newer SQLite snapshot storage have upgrade-only compatibility constraints, so downgrading readers can fail. A separate deprecation notice covers pydantic_ai_harness.step_persistence.naming; the page states that the conversation store is unaffected.
Actions
Choose whether the application needs continuation from saved messages, automatic execution recovery, or both. Select a persistent backend for recovery across process restarts, then confirm its privileges, lifecycle responsibilities and schema compatibility.
Define recovery rules for each tool that changes external state. Record meaningful effect metadata, inspect unresolved effects, and verify external outcomes before allowing repeated actions. Keep interrupted snapshots off the normal recovery path unless the application explicitly handles pending calls.
Set retention according to the history that must remain recoverable, including pre-compaction content. Account separately for events, media and retained database messages. Before depending on the design, perform application-specific crash and replay exercises, review upgrade compatibility, and confirm license terms; those results and terms are currently unknown.
