pydantic-ai-memory-core
Shared core for building PydanticAI harness MemoryStore backends. The harness Memory capability injects a per-user Markdown notebook (MEMORY.md plus topic files) before every model call and lets the model write to it through write_memory; the store underneath must provide compare-and-swap versions and idempotent operation receipts. KVMemoryStore implements that whole protocol — read / get_operation / write / delete / list_paths and the optional SearchableMemoryStore.search — so a backend supplies only conditional primitives:
from pydantic_ai_memory_core import KVMemoryStore
class MyStore(KVMemoryStore):
def _get_file(self, path): ... # -> {"content","version","operation_id"} | None
def _create_file(self, path, content, version, operation_id): ... # -> bool, only if absent
def _replace_file(self, path, content, version, operation_id, expected_version): ... # -> bool, only if version matches
def _delete_file(self, path, expected_version): ... # -> bool
def _list_paths(self, prefix, limit): ... # sorted
def _get_receipt(self, op_id): ... # -> {"fingerprint","version","existed","completed"} | None
def _reserve_receipt(self, op_id, fingerprint): ... # -> bool, only if absent
def _complete_receipt(self, op_id, version, existed): ...
def _drop_receipt(self, op_id): ...
Each conditional primitive must be atomic in the backend (conditional write, ETag match or transaction); the core turns them into the harness contract. Use it with an agent:
from pydantic_ai import Agent
from pydantic_ai_harness.memory import Memory
agent = Agent("anthropic:claude-sonnet-5", deps_type=Deps,
capabilities=[Memory(store=MyStore(...), namespace=lambda ctx: ctx.deps.user_id)])
append_memory(store, path, text) is a CAS-safe append with retries for writing to memory from outside the model, for example from the agentstate-reducer on_prune hook.
pydantic_ai_memory_core.contract is an importable test suite every provider runs, including an end-to-end pass through the real Memory capability on a PydanticAI Agent with a scripted model (no LLM). pydantic_ai_memory_core.testing.InMemoryKVMemoryStore is the reference backend.
Concrete backends: pydantic-ai-dynamodb-memory, pydantic-ai-cosmosdb-memory, pydantic-ai-firestore-memory, pydantic-ai-postgres-memory.
Docs: https://skamalj.github.io/agentstate-reducer/
License
MIT
Metadata
Release files for pydantic-ai-memory-core 0.1.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 | |
|---|---|---|---|
| pydantic_ai_memory_core-0.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_ai_memory_core-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.7 kB
Release files / pydantic_ai_memory_core-0.1.0.tar.gz
| Download URL | pydantic_ai_memory_core-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cc7fd0f697aebe2d7aad5b8cc73d5c0b866b3bcba0fc9c3c4ec41e10519749e
|
|
BLAKE2b-256 checksum How to use checksums |
d3c58c00eed3b90417264ad18c74754b84fc54a96fe4a2bb29d6d294479f5158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pydantic_ai_memory_core-0.1.0-py3-none-any.whl
| Download URL | pydantic_ai_memory_core-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd8ace7950fc9ba80d1383a2193014b51643ac02cfbc89efae424a0ac49f846f
|
|
BLAKE2b-256 checksum How to use checksums |
2538b717315b84d9ac9ecc80d9f9286a8109dc3f8efaa28679b0ebd0e0dd4721
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|