Pydantic AI
Rekall memory plus durable message history for Pydantic AI. The rekall-pydantic-ai package persists a conversation across runs and adds semantic recall on top.
Overview
Pydantic AI agents are stateless between run calls — you pass message_history in and get updated messages out. RekallMemory stores that history durably (so a conversation survives restarts) and layers semantic recall on top so the agent can pull in relevant facts beyond the literal transcript. The adapter is stdlib-only (urllib) with an injectable transport= for tests.
Installation
pip install rekall-pydantic-ai
Durable Message History
Load history before a run and save it after, keyed by a session id. The (de)serialization helpers handle Pydantic AI's ModelMessages on a best-effort basis:
from pydantic_ai import Agentfrom pydantic_ai.messages import ModelMessagesTypeAdapterfrom rekall_pydantic_ai import RekallMemorymem = RekallMemory(api_url="https://api.rekall.app", api_key="rk_...") # or http://localhost:9876agent = Agent("openai:gpt-4o")# Durable conversation historyhistory = mem.load_messages(mem.load_history("user-42")) # [] on first runresult = agent.run_sync("What did we decide last time?", message_history=history)mem.save_history("user-42", mem.dump_messages(result.all_messages()))
Backed by execution memory
save_history / load_history store a JSON-able list in Rekall's execution-memory /external store, keyed by the session id you choose.
Semantic Memory
Beyond the transcript, store and recall facts semantically. context_for returns a formatted block you can drop into an agent's system prompt:
mem.remember("the cache TTL is 3 hours")hits = mem.recall("cache ttl") # [{content, score, metadata}, ...]system = mem.context_for("cache") # formatted block for an agent's system prompt
API
| Method | What it does | Rekall endpoint |
|---|---|---|
save_history / load_history | durable message history (JSON-able list) | execution-memory /external |
dump_messages / load_messages | (de)serialize Pydantic AI ModelMessages (best-effort) | — |
remember(content, metadata) | store a memory | POST /api/v2/memories |
recall(query, limit) / context_for(query) | semantic recall (+ formatted block) | POST /api/v2/memories/search |
Authentication
Pass api_key / access_token (sent as Bearer), or headers={"x-user-id": "…"} for local dev against a header-auth server.
