Metadata-Version: 2.5
Name: pydantic-ai-postgres-memory
Version: 0.1.0
Summary: PostgreSQL MemoryStore for the PydanticAI harness Memory capability — the upstream transactional store, built from a connection URL with an owned asyncpg pool
Project-URL: Homepage, https://github.com/skamalj/pydantic-ai-memory
Project-URL: Repository, https://github.com/skamalj/pydantic-ai-memory.git
Project-URL: Documentation, https://skamalj.github.io/agentstate-reducer/
Author-email: Kamal <skamalj@gmail.com>
Keywords: agent-memory,long-term-memory,memory,memorystore,postgres,postgresql,pydantic-ai,pydantic-ai-harness
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: asyncpg>=0.29
Requires-Dist: pydantic-ai-memory-core>=0.1.0
Description-Content-Type: text/markdown

# pydantic-ai-postgres-memory

A **PostgreSQL** `MemoryStore` for the [PydanticAI harness](https://pydantic.dev/docs/ai/harness/memory/) `Memory` capability, built from a **connection URL**. The harness already ships a transactional `PostgresMemoryStore` that takes a caller-owned asyncpg pool; this package wraps it so it drops into `Memory(store=...)` like the other `pydantic-ai-*-memory` backends, creating and owning the pool for you.

```bash
pip install pydantic-ai-postgres-memory
```

```python
from pydantic_ai import Agent
from pydantic_ai_harness.memory import Memory
from pydantic_ai_postgres_memory import PostgresMemoryStoreFromUrl

store = PostgresMemoryStoreFromUrl("postgresql://user:pass@host:5432/db", table="agent_memory")
agent = Agent("anthropic:claude-sonnet-5", deps_type=Deps,
              capabilities=[Memory(store=store, namespace=lambda ctx: ctx.deps.user_id)])
```

## How it works

- Delegates every call to the upstream `pydantic_ai_harness.memory.PostgresMemoryStore`, so the compare-and-swap and operation-receipt semantics are exactly the reference ones: each write or delete runs in one transaction with a version sequence and an `{table}_operations` receipt table. Schema is created on first use.
- The asyncpg pool is created lazily on the running event loop and kept **per loop**, because asyncpg pools are loop-bound and agents are frequently driven from several loops (`run_sync` per call, workers, tests). Pass `pool=` to reuse a pool you own instead; `aclose()` closes the owned pool for the current loop.
- `search` is the harness's bounded lexical search over the scope's files.

Docs: <https://skamalj.github.io/agentstate-reducer/> · part of [pydantic-ai-memory](https://github.com/skamalj/pydantic-ai-memory)

## License

MIT
