recall-pydantic-ai
Long-term memory for Pydantic AI agents, backed by Recall by Polign.
Every run starts with what the agent knows about the user in its
instructions, and the model saves new facts through a remember tool. A
correction replaces the old fact instead of piling up a second one, and the
history of the change is kept. No second model runs on the read path.
It works with both of Recall's tool sets. With the typed tools, each fact is a predicate from a closed registry with a value, for any number of users. With the text tools, the model passes what the user said in their words and the server works out the facts, for one user per collection. See Text or typed.
pip install recall-pydantic-ai
That is the whole install. pip also brings the recall binary and
polign-server for Linux, macOS and Windows, so there is no separate database
to download.
Usage
RecallMemory is a Pydantic AI
capability. Add it to an agent:
from dataclasses import dataclass
from polign_recall import Client
from pydantic_ai import Agent
from recall_pydantic_ai import RecallMemory
@dataclass
class Deps:
user_id: str
recall = Client(local_dir="./recall-data", typed=True) # one per process; the database lives here
agent = Agent(
"anthropic:claude-sonnet-5-5",
deps_type=Deps,
instructions="You help engineers with their projects.",
capabilities=[RecallMemory(recall, subject=lambda ctx: ctx.deps.user_id)],
)
agent.run_sync("I'm Alex. We deploy to Fly.io.", deps=Deps("user-42"))
# a later run, in a new process or a week later
result = agent.run_sync("Where do we deploy again?", deps=Deps("user-42"))
print(result.output) # Fly.io
What happens:
- At the start of each run,
RecallMemoryloads the user's current facts and adds them to the instructions inside a<recall_memory>block. - The user says "I'm Alex. We deploy to Fly.io." The model calls
remembertwice, withnameanddeployment_target. - Later the user says "actually it's Sam". The model calls
rememberagain, Recall replaces the old name, and the tool tells the modelUpdated name to Sam; it was Alex. - The next run's instructions say Sam. Alex is still in the record:
recall.history("user-42", "name")lists both.
Nothing is searched on each model request. A user's typed facts are a short
list, so the whole set fits in the instructions, and they stay the same for
the whole run, which keeps the provider's prompt cache valid. When a user has
more facts than limit (default 20), the run also searches for the prompt,
adds the matches to the block, and gives the model a search_memory tool.
subject is a fixed string or a function of the run context. Use a stable,
auth-derived identifier for the user, never a session or conversation id.
Text or typed
RecallMemory follows the tools the client serves.
| Typed tools | Text tools | |
|---|---|---|
| Client | Client(..., typed=True) |
Client(...) (the default) |
remember takes |
a predicate from the registry and a value | a passage, in the user's words |
| Who works out the facts | the agent's model, against the registry | the server's extraction model (extract_model) |
| Users | any number; pass subject |
one per collection; no subject |
forget takes |
a predicate, and a value or everything |
a description, such as "my editor" |
The text tools suit an agent that serves one person, such as a personal assistant or a coding agent:
recall = Client(local_dir="./recall-data", extract_model="anthropic:claude-sonnet-5-5")
agent = Agent(
"anthropic:claude-sonnet-5-5",
instructions="You help me with my projects.",
capabilities=[RecallMemory(recall)],
)
agent.run_sync("I switched my editor from Vim to Helix.")
# remember's result tells the model what the new fact replaced
The server needs an extraction model to work out the facts in the text and to
forget by description. Without one, remembered text is kept as written, the
next run still sees it, and nothing replaces anything; the tool tells the model
Kept as written. A text client given a subject is refused, so two users can
never share one memory by mistake. To serve many users with the text tools,
give each one their own collection (env={"RECALL_COLLECTION": ...}) and
client; with many users, the typed tools are the simpler choice.
Where the memory is stored
Client(local_dir="./recall-data", typed=True) keeps the database on this machine. typed=True asks for the typed tools this capability files beliefs with (recall 0.18 or later). The
first process to open the directory starts a polign-server for it in the
background, listening on localhost only, and every other process shares that
server. It keeps running after your program exits; its process id is in
recall-data/runtime.json and its log in recall-data/server.log. This is
the quickest way to try the package and is fine for a single machine.
Agents on several machines need one shared memory. Run recall serve
somewhere they can all reach, storing into S3, GCS or Azure
(Get started shows how), then connect:
recall = Client(url="https://memory.internal:8443", api_key=os.environ["RECALL_API_KEY"], typed=True) # a recall serve started with -typed
Client.from_env() does the same from RECALL_URL and RECALL_API_KEY, and
starts a local process when RECALL_URL is unset, so the same code runs on a
laptop and in production.
Create one Client per process and share it between agents and runs. Each one
is a subprocess or an HTTP session, and calls through it are serialized; the
local read path takes a few milliseconds.
Failures
Reads fail open. If Recall is slow or down when a run starts, the run goes on
without the remembered facts and a warning is logged on the
recall_pydantic_ai logger. Writes report the failure to the model as the
tool's result (The fact was not saved: ...), so it can tell the user. An
unknown predicate or a value of the wrong type asks the model to try again.
Options
| Option | Default | What it does |
|---|---|---|
client |
required | A polign_recall.Client, serving the typed or the text tools |
subject |
required with typed tools | The user, as a string or lambda ctx: ...; not taken with text tools |
limit |
20 | Facts loaded into the instructions; above it, the run searches for the prompt and offers search_memory |
who |
"the user" |
How the block and the tool descriptions refer to the person |
template |
<recall_memory>\n{context}\n</recall_memory> |
Wrapper around the block; must contain {context} |
remember_tool |
on | Give the model the remember tool. Off makes the memory read-only |
forget_tool |
off | Give the model a forget tool, so users can withdraw a fact by asking |
search_when_overflowed |
on | Search for the prompt when the user has more than limit facts |
read_timeout, write_timeout |
2 s, 10 s | Reads past the timeout fail open; writes past it tell the model the fact was not saved |
Inside a run, the capability instance the agent uses has run_subject,
beliefs (what was loaded) and matches (what the prompt search added). With
the text tools, memories and memory_matches hold the same, and text is
true.
Custom predicates
This applies to the typed tools. The remember tool's schema is built from Recall's predicate registry, so the
model only ever sees the names you allow. The built-in registry covers names,
preferences, project facts and free-form notes. To use your own, write it as
JSON and point the server at it:
{
"name": { "cardinality": "single", "value_type": "string", "description": "The name the user asks to be called" },
"plan_tier": { "cardinality": "single", "value_type": "string", "description": "The user's subscription plan" },
"open_issue": { "cardinality": "multi", "value_type": "string", "description": "A problem the user reported that is not resolved yet" }
}
recall = Client(local_dir="./recall-data", env={"RECALL_PREDICATES": "registry.json"}, typed=True)
single means a newer value replaces the old one; multi means each value is
an additional fact. value_type is string, number, or boolean, and the
tool turns the model's text into that type ("1,200" becomes 1200, "yes"
becomes true). The file replaces the built-in registry, except note, which
Recall always keeps for statements no other predicate fits.
Limits
- The text tools keep one user per collection, so a text client takes no
subject. - Durable execution (Temporal, DBOS) is not tested. The capability reads
memory in
for_run, so a worker that rebuilds the run reads it again. - Agent specs (
Agent.from_spec) cannot createRecallMemory, since it takes a live client.
Development
cd python/recall-pydantic-ai
python -m pip install -e . pytest pytest-asyncio
pytest tests/unit_tests -q # fake Recall client, scripted model
pytest tests/integration_tests -v # the recall binary and polign-server pip installed
The integration tests start a local database in a temporary directory, stop
its server when they finish, and skip when the recall binary is not
installed. Supported versions: Python 3.10 and later, pydantic-ai-slim 2.16
and later in 2.x.
Metadata
Release files for recall-pydantic-ai 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| recall_pydantic_ai-0.2.0.tar.gz | 21.4 kB | With provenance | Details for recall_pydantic_ai-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| recall_pydantic_ai-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for recall_pydantic_ai-0.2.0-py3-none-any.whl |
Total release size: 39.2 kB
Release files / recall_pydantic_ai-0.2.0.tar.gz
| Download URL | recall_pydantic_ai-0.2.0.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01ff70eda28b404178de488942ba4e8a5987e9e9b23454bbcacd64683af79e53
|
|
BLAKE2b-256 checksum How to use checksums |
158d30e4f0eaa50647f04de604c0612200b5925ed6a1830fa72e9af055af043f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / recall_pydantic_ai-0.2.0-py3-none-any.whl
| Download URL | recall_pydantic_ai-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b4a518909d2a5e94a4c1b81a60f68abeeffb148b25e6f902b8908fa9d112fe8
|
|
BLAKE2b-256 checksum How to use checksums |
a55a44cc960c7473b0df929b45ef5ebed297f2f5e65507b8c3c62115bec03fe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for recall-pydantic-ai 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for recall_pydantic_ai-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.