Your personal memory, across sessions, agents, and devices.

What Is PydanticAI? Typed Agents and How They Remember

memU Team memU Team

PydanticAI is the agent framework from the team behind Pydantic, the validation library most Python AI code already depends on. The project writes its name as Pydantic AI, and searches spell it both ways. It reached version 1.0 on September 5, 2025 and version 2.0 on June 23, 2026. By the end you will know what the typed API buys you. You will also know which of its four state layers fits each job, from chat history to long-term memory.

What is PydanticAI, in one sentence?

PydanticAI is an open-source Python framework for LLM agents whose inputs and outputs are validated with Pydantic and whose model you swap by changing a string.

The official overview uses the tagline "How Python does AI". It lists providers including OpenAI, Anthropic, Google, Bedrock, Groq, Mistral, xAI and Ollama. The GitHub repository is MIT licensed and had about 20,900 stars on October 28, 2026. Releases come quickly: v2.63.0 shipped that same day.

The agents page shows the pattern. You declare a dependency type and an output type on the agent. Each tool takes a typed run context as its first argument, which carries those dependencies. When the model returns output that fails validation against your type, the error surfaces in Python at that step.

How does memory in Pydantic AI differ from conversation history?

Pydantic AI splits state into four layers, and its persistence page draws the same lines.

Layer What it keeps Where it lives Lasts until
Message history or Conversation (core) The messages of one conversation, plus usage and IDs for a Conversation Wherever your app stores the JSON You delete it
StepPersistence (Harness) A message snapshot at each settled tool-call boundary, plus an event log In-memory, file, SQLite, PostgreSQL or MongoDB stores Your retention policy
Durable execution (core and Harness) A journal of model requests and wrapped tool calls for a run in flight Temporal, DBOS, Prefect and other engines The run completes
Memory (Harness) A notebook of Markdown files the agent writes, starting with MEMORY.md File, SQLite or PostgreSQL stores You delete it, across any number of conversations

Only the Memory row outlives a conversation. The other three keep one conversation or run intact.

How does message history work in Pydantic AI?

Every run returns a result with two methods. The all_messages() method returns everything, including messages from earlier runs, and new_messages() returns only the current run. To continue a conversation, you pass the earlier messages into the next run through the message_history parameter. The message history docs describe that as the normal pattern.

For storage, the library exports ModelMessagesTypeAdapter to turn messages into JSON and back. For a conversation you plan to resume, the docs recommend storing the whole Conversation object instead. It also keeps token usage and the conversation ID. Plain messages drop both, along with any pending deferred tool requests.

Storage is your job. The docs say where serialized history lives "is left to your application". Server-side surfaces are stateless, so each run is rebuilt from the history the caller supplies. If you accept history from a client, the docs say to sanitize it first.

Long conversations need trimming. A history processor is a function that takes the message list and returns a new one before the model sees it. Processors run in sequence and replace the history in state, so copy the original if you need it later.

What does durable execution add?

Durable execution protects a run that is still going. The durable execution docs say the engine journals the agent's model requests and the tool calls it wraps. If the process dies, a restarted run replays the finished steps and retries the interrupted one.

Temporal, DBOS and Prefect are built in as extras of the core package. Restate and Apache Airflow ship integrations in their own packages. Pydantic AI Harness adds a few more engines, AWS Lambda among them. This is the layer to reach for when an agent runs for minutes or hours and calls tools with side effects.

How does the Pydantic AI Memory capability work?

Pydantic AI Harness is the official capability library, installed as pydantic-ai-harness. It adds more than 50 capabilities on top of the core agent. Memory is one of them. It is on 0.x versions, and the docs warn that APIs may still move between minor releases.

The Memory capability gives the agent a notebook of Markdown files. MEMORY.md holds short durable facts, and other files hold longer topic notes. The model gets four memory tools. One of them deletes files, though never MEMORY.md itself. Search is literal text matching with limits on results and files scanned. Writes use optimistic concurrency, so a stale edit fails and the newer note survives.

By default the notebook is injected into the conversation as a delimited block. A token budget caps it, with a default of 2,000 tokens, and only the first 200 lines of MEMORY.md are shown. You can turn injection off and leave the agent to use the tools alone.

In a multi-user app, resolve the namespace from your typed dependencies on each run, so the model cannot pick another user's namespace. The docs list the limits. Namespaces isolate records but are not an authorization system. Memory is model-written and untrusted, and the injection boundary is not a hard defense against prompt injection.

When should you use Pydantic AI?

Pick it when your team already models data with Pydantic and wants agents that fail loudly on bad output. The typed dependencies also make tools easy to test, because you can pass a fake dependency in a unit test. The integrated tracing goes through OpenTelemetry, with a one-line setup for Pydantic's own Logfire.

The risk is churn. The core framework has shipped 63 minor releases since 2.0 in June. Harness, where memory and step persistence live, is still on 0.x. Pin versions, and read release notes before you upgrade an agent that stores state.

How do you get started with Pydantic AI?

The core package is on PyPI as pydantic-ai. Install it with pip or uv, set the API key for your model provider, and copy the agent example from the agents page. Add a tool next, then an output type, before you touch persistence. When you need memory, add pydantic-ai-harness at a pinned version.

The bottom line

Use Pydantic AI if you want typed Python agents and are comfortable owning storage. Start with stored Conversation objects for chat continuity. Durable execution is worth adding only for long runs with side effects. When your agent must remember users across conversations, add the Harness Memory capability. Scope its namespace from your dependencies from day one.

How do you keep memory across the coding agents that build your Pydantic AI app?

Pydantic AI's Memory capability is for the agent you ship to users. The coding agents that build your app have their own memory gap. Claude Code and Codex each learn your conventions in a silo. Every new session must be told again which store backs StepPersistence and which Harness version you pinned.

memU is a memory layer for those coding agents, separate from Pydantic AI. A scheduled background task slices each host's new session logs into jobs. The agent distills them into memory and skill Markdown.

memU's MemoryService makes no LLM or chat calls. It only stores and embeds the Markdown the agent prepared, then retrieves it on request. A standing instruction in CLAUDE.md or AGENTS.md tells the agent to retrieve before it answers. All hosts share one backend, so what Codex learned about your schema is there when you open Claude Code.

The hosted version is free and syncs across devices. Get an API key from memu.so, then send your agent one message:

Read https://memu.pro/SKILL.md, follow its instructions to install and configure memU, API Key is YOUR_MEMU_API_KEY.

The self-hosted install and the support matrix are in the memU GitHub repository.

FAQ

Does Pydantic AI have built-in memory?

The core framework keeps conversation state only when you pass message history back in. Long-term memory comes from the Memory capability in the separate pydantic-ai-harness package. It stores Markdown notes in a file directory or a database.

How do I save and restore a Pydantic AI conversation?

Serialize the Conversation object with its type adapter and store the JSON in your database. To resume, pass the loaded object back as the conversation argument. For plain messages, use the messages type adapter with the message history parameter.

Is PydanticAI the same as Pydantic AI?

Yes. The project writes it as two words, Pydantic AI. The package installs as pydantic-ai. PydanticAI is a common spelling in searches and older articles.

Which models does Pydantic AI support?

The docs cover OpenAI and Anthropic plus other hosted providers. Local models work through Ollama. You switch models by changing the model string on the agent.

Is Pydantic AI free?

Yes. The framework is open source under the MIT license. Your costs are the model APIs you call and any hosted services you add.