In short.
Pydantic AI's persistence guide helps Python developers retain conversational agent state, but production storage and crash recovery require separate implementation choices. Its central distinction is between storing a Conversation for the next request, recording tool-boundary snapshots, maintaining knowledge across conversations and recovering interrupted execution. The examples explain useful APIs and tradeoffs, while installation requirements, release compatibility, prices and production performance remain unknown.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage includes the complete documentation page at [https://pydantic.dev/docs/ai/core-concepts/persistence/index.md], including its examples, cautions and introductory documentation-index and query-parameter notices. The index and all linked pages are excluded. Related capabilities are described only to the extent explained on this page. No code was executed; backend integration, crash recovery, concurrency behavior, security guarantees, performance and actual charges remain untested or unknown.
The overview
identity
This is the Persistence page in the Pydantic AI documentation at [https://pydantic.dev/docs/ai/core-concepts/persistence/index.md]. It is a technical guide to retaining agent state across requests and process restarts.
The page covers core conversation storage and describes related Pydantic AI Harness capabilities. It is documentation rather than a standalone storage service or a complete database implementation.
assessment
The guide is useful when a team needs to decide what an agent should remember and where that state belongs. It explains why ordinary chat continuity can use stored conversation state, while knowledge across conversations and recovery during a failed run need other mechanisms.
Its strongest practical contribution is identifying state that message history alone misses, particularly cumulative usage and pending deferred tool requests. It provides implementation patterns, but does not establish production reliability, deployment effort or performance through measured results.
users
The main audience is Python developers building Pydantic AI chat assistants, support systems or other agents whose conversations span multiple requests. Beginners get a useful explanation of the different meanings of memory; the examples assume familiarity with Python and application storage.
Experienced developers will find details relevant to concurrent saves, tenant separation, conversation branches, message identifiers and frontend protocol conversion. Teams seeking a complete deployment tutorial will need additional material.
capabilities
ConversationTypeAdapter serializes and restores a Conversation containing messages, cumulative usage, its identifier and pending deferred tool requests. Passing that object into a later run preserves more state than passing messages alone.
ConversationStore adds incremental message storage, revision-based conflict detection, ownership scopes, listing, branching and forks that share earlier history. Stored messages receive entry identifiers that applications can associate with ratings or billing records.
The page also describes StepPersistence for event logs and tool-boundary snapshots, ConversationSearch for recalling stored turns, and Memory for notes that survive beyond an individual conversation.
Using it
requirements
The examples require Python, Pydantic AI and a working model configuration. Persistent application use also requires storage: either a database schema managed by the application, a ConversationStore implementation or an appropriate Harness backend.
InMemoryConversationStore is intended for tests and examples. A database-backed ConversationStore requires subclassing its interface; the page says the framework implements higher-level behavior over five storage primitives. Minimum Python and package versions, installation commands and hardware requirements are not specified.
Application decisions include tenancy, retention and ownership. The page describes scope-based filtering, but does not supply a complete authentication or authorization design.
mechanism
Basic persistence works by saving result.conversation and supplying the restored object as conversation= on the next run. Its cumulative usage allows a conversation-wide UsageLimits budget; restoring only messages resets that accounting.
ConversationStore uses a revision to detect competing writes and new_message_index to identify messages that need appending. A conflict raises ConversationConflict instead of silently overwriting another save. Loading only recent messages can reduce the history supplied to a run while the store retains the full history.
StepPersistence records snapshots at settled tool-call boundaries, but those snapshots omit usage and pending deferred requests. Memory instead maintains a namespace-keyed notebook and inserts a bounded excerpt into requests. Neither mechanism replaces durable execution for recovering a run interrupted during execution.
setup
For simple storage, create an agent, run it, serialize result.conversation with ConversationTypeAdapter.dump_json and save the bytes under the conversation identifier. Restore them with validate_json before continuing the conversation.
For ConversationStore, load or create the conversation, pass it into the agent and save the result. Supply the same ownership scope consistently when saving and accessing records, and handle revision conflicts by reloading and retrying.
StepPersistence is presented as an alternative that packages persistence calls as an agent capability, with in-memory, file, SQLite, PostgreSQL and MongoDB backends. The page does not provide a complete backend deployment or configuration procedure.
example
The first example asks an agent for a joke, serializes its Conversation, restores it and asks for an explanation. The documented cumulative request count after the second run is 2, illustrating that usage travels with the conversation. This is example output supplied by the documentation, not an independently measured result.
A second example wraps load, agent.run and save in an asynchronous chat function using the identifier support-42. Its InMemoryConversationStore demonstrates the interaction pattern; persistent storage requires a different implementation.
Assessment & evidence
limitations
Serialization preserves application metadata but can change values without a native JSON representation: tuples reload as lists, datetimes as ISO strings and bytes as base64 strings. Applications should account for those type changes.
Frontend message formats can omit information needed by later model requests. The page recommends storing Pydantic AI's representation, converting at the UI boundary and sanitizing browser-supplied history before using it.
Snapshots cannot rewind into a partially completed step. A tool call interrupted by a crash has an unknown outcome, and even a call that raised an exception may have affected an external system. Agent-written memory can also contain mistakes or planted content; inserting it as user-role content is not a hard prompt-injection boundary.
Stored ConversationStore histories continue growing. Loading fewer messages does not itself implement retention. Storage limits, latency, throughput and production security effectiveness are not established.
reasoning
The appropriate mechanism follows the state that must survive. A complete Conversation is sufficient for continuing an ordinary chat while retaining usage and deferred requests. ConversationStore becomes useful when append-based writes, competing updates or editable histories matter.
Checkpoint logs and long-term memory serve different purposes. Logs preserve what happened during runs; a notebook carries selected knowledge across threads. Durable execution addresses interrupted execution, so adding it solely to retain a chat thread introduces a mechanism the basic storage need does not require.
These conclusions follow the page's API descriptions and examples. No comparative benchmark establishes one approach as universally faster, cheaper or more reliable.
alternatives
The page presents several alternatives within Pydantic AI: a serialized Conversation for simple application-controlled storage; ConversationStore for incremental histories and conflict handling; StepPersistence for logs and checkpoints; and Memory for knowledge across conversations.
Provider-managed state is another option. The page names OpenAI Responses conversation identifiers, while noting provider dependence, continued billing for earlier input tokens and unavailability for organizations with Zero Data Retention enabled.
No competing agent framework is compared. Backend-specific operational differences cannot be assessed from the linked references alone.
evidence
The evidence is the complete Persistence documentation page at [https://pydantic.dev/docs/ai/core-concepts/persistence/index.md]. It supplies API descriptions, Python examples, storage tradeoffs and security cautions.
Its claims are documentation evidence rather than independent operational measurements. Linked API references, backend guides and security explanations are outside this report's scope. No code was executed, and runtime correctness, recovery behavior and tenant isolation were not tested.
Access & freshness
costs
The page provides no monetary prices, subscription requirements or implementation estimates. Model charges and storage costs remain unknown. Usage counters help track requests and enforce limits, but do not establish a monetary budget without applicable prices.
The storage approach affects workload: rewriting the entire conversation makes each write grow with its history, while incremental storage appends new messages. The page also states that OpenAI still bills earlier input tokens in a provider-managed conversation chain; sending less history from the application does not establish lower token charges.
rights
The page contains no license text or explicit redistribution grant for its documentation or code examples. Applicable reuse, modification and redistribution rights are unknown from this page. It also does not establish the license terms of the wider Pydantic AI project or related services.
freshness
The page was captured on 14 November 2026 at 22:20:42.270 UTC. It does not identify a package release or publication/update date, so compatibility with a particular installed Pydantic AI version remains unknown.
The page states that older serialized conversations remain readable when Pydantic AI adds a message part. That compatibility claim does not establish that every API described here exists in every release.
actions
First identify whether the application needs chat continuity, run checkpoints, knowledge across threads or recovery during execution. For chat continuity, preserve the complete Conversation, including usage and deferred requests. Choose ConversationStore when incremental writes, branches or competing saves are requirements.
Before production use, confirm API availability in the intended release and verify the chosen backend's persistence, conflict handling, ownership scopes and restoration of paused conversations. Define retention and sanitize client-supplied histories.
If using checkpoints or memory, plan how to reconcile uncertain tool effects and handle untrusted remembered content. Confirm applicable license terms and provider prices separately; this page does not establish them.
