Skip to main content

pydantic-ai-dynamodb-memory

An Amazon DynamoDB MemoryStore for the PydanticAI harness Memory capability — the per-user Markdown notebook the harness injects before every model call and lets the model write through write_memory, on a shared, durable table.

pip install pydantic-ai-dynamodb-memory
from dataclasses import dataclass
from pydantic_ai import Agent
from pydantic_ai_harness.memory import Memory
from pydantic_ai_dynamodb_memory import DynamoDBMemoryStore

@dataclass
class Deps:
    user_id: str

store = DynamoDBMemoryStore(table_name="agent-memory")          # table auto-created (PAY_PER_REQUEST)
agent = Agent("anthropic:claude-sonnet-5", deps_type=Deps,
              capabilities=[Memory(store=store, namespace=lambda ctx: ctx.deps.user_id)])

agent.run_sync("I moved to Hanoi and hate early flights.", deps=Deps("kamal"))   # model calls write_memory
agent.run_sync("Book me something to Bangkok.", deps=Deps("kamal"))              # MEMORY.md injected first

How it works

  • One table, pk = f#<path> for memory files (content, version, operation_id) and o#<operation id> for operation receipts. Auto-created; pass create_table=False to manage it yourself.
  • Compare-and-swap is a DynamoDB conditional write: create requires attribute_not_exists(pk), replace and delete require version = :expected. A stale version raises the harness MemoryConflictError, never an overwrite.
  • Operation receipts (MemoryOperation) are reserved with a conditional put, completed after the mutation, and dropped if the mutation fails, so durable-execution replays return the original result and a reused id with different arguments raises MemoryOperationConflictError.
  • search is the harness's bounded lexical search over the scope's files (SearchableMemoryStore); list_paths is a prefix scan, sized for notebook volumes.
  • Async protocol methods run the boto3 calls in a worker thread.

Writing to memory from outside the model, e.g. from the agentstate-reducer on_prune hook: await append_memory(store, f"{user_id}/main/facts.md", text) from pydantic-ai-memory-core does a CAS-safe append with retries.

Permissions: DescribeTable, CreateTable, GetItem, PutItem, UpdateItem, DeleteItem, Scan.

Docs: https://skamalj.github.io/agentstate-reducer/ · part of pydantic-ai-memory

License

MIT

Metadata

Release files for pydantic-ai-dynamodb-memory 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-dynamodb-memory 0.1.0
File Size Uploaded
pydantic_ai_dynamodb_memory-0.1.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-dynamodb-memory 0.1.0
File Interpreter ABI Platform
pydantic_ai_dynamodb_memory-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / pydantic_ai_dynamodb_memory-0.1.0.tar.gz

Download URL pydantic_ai_dynamodb_memory-0.1.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
be81488a148defda0e35ad9832a5acaaad4445fa3cc7567cbab08db17a0777da
BLAKE2b-256 checksum
How to use checksums
a3335f20aad29327928a34291247654a3ef30e2a839bebde54e048e475c3e822
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_dynamodb_memory-0.1.0-py3-none-any.whl

Download URL pydantic_ai_dynamodb_memory-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0551cca20c1cc8493f96b6883360bb700eaa263af88e0c64a943bb302b533507
BLAKE2b-256 checksum
How to use checksums
d6d9c65325e3f3a1699c293f1830a7d35e7e8906f42a141c97e26f388124e5ab
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 history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page