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

Terminal
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:

history.py
from pydantic_ai import Agent
from pydantic_ai.messages import ModelMessagesTypeAdapter
from rekall_pydantic_ai import RekallMemory
mem = RekallMemory(api_url="https://api.rekall.app", api_key="rk_...") # or http://localhost:9876
agent = Agent("openai:gpt-4o")
# Durable conversation history
history = mem.load_messages(mem.load_history("user-42")) # [] on first run
result = 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:

semantic.py
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

MethodWhat it doesRekall endpoint
save_history / load_historydurable message history (JSON-able list)execution-memory /external
dump_messages / load_messages(de)serialize Pydantic AI ModelMessages (best-effort)
remember(content, metadata)store a memoryPOST /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.

Next Steps

Rekall
rekall