Official SDK

Pydantic AI memory

One capability gives every run recalled context and success-only capture of the user’s prompt — no history pollution.

Overview

Install pydantic-ai-memorysync and add MemorySyncCapability(user_id=...) to Agent(capabilities=[...]): recall injects through the framework’s instructions channel — never a conversation part, so message-history replay can never stack stale memory blocks — and the user’s prompt is sent to fact extraction in after_run, which fires only on success, so a failed run sends nothing (the model’s reply, tool calls and retry prompts are never sent). Identity resolves from your deps for multi-user servers. Five structured tools plus a typed search tool returning validated Pydantic models. The only memory integration built on pydantic-ai v2’s capability system.

Setup status and requirements

Supported version
pydantic-ai-memorysync 1.1.0 (PyPI)
Last setup review
2026-10-01
Permissions
A MemorySync API key with read and write scopes; the delete tool needs delete permission.
Limits
Requires pydantic-ai (or pydantic-ai-slim) 2.0+ (Python 3.10+). Python only — TypeScript agents use the Vercel AI SDK or Mastra integrations.
Open setup documentation →

Capabilities

Quick Start

from pydantic_ai import Agent
from pydantic_ai_memorysync import MemorySyncCapability
agent = Agent(
"openai:your-model",
instructions="You are a helpful assistant.",
capabilities=[MemorySyncCapability(user_id="customer-7")],
)
result = await agent.run("What should I cook tonight?")

Use Cases

Pydantic AI agents that remember users across runs and deploys

Multi-user servers resolving identity from typed deps

Structured pipelines consuming typed memory search results

Guides and related pages

Explore More

Add long-term memory to Pydantic AI

Start free with 10,000 add requests a month and no credit card. Memory is stored per end user and comes back in every later session.