Metadata-Version: 2.5
Name: pydantic-ai-cosmosdb-memory
Version: 0.1.0
Summary: Azure Cosmos DB MemoryStore for the PydanticAI harness Memory capability — CAS versions via ETags and idempotent operation receipts
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,azure,cosmosdb,long-term-memory,memory,memorystore,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: azure-cosmos>=4.7
Requires-Dist: pydantic-ai-memory-core>=0.1.0
Description-Content-Type: text/markdown

# pydantic-ai-cosmosdb-memory

An **Azure Cosmos DB (NoSQL)** `MemoryStore` for the [PydanticAI harness](https://pydantic.dev/docs/ai/harness/memory/) `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 container.

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

```python
from pydantic_ai import Agent
from pydantic_ai_harness.memory import Memory
from pydantic_ai_cosmosdb_memory import CosmosDBMemoryStore

store = CosmosDBMemoryStore(endpoint="https://<acct>.documents.azure.com:443/", key="<key>",
                            database_name="agents", container_name="memory")
agent = Agent("anthropic:claude-sonnet-5", deps_type=Deps,
              capabilities=[Memory(store=store, namespace=lambda ctx: ctx.deps.user_id)])
```

## How it works

- One container partitioned by `/id`: a document per memory file (`kind: "file"`, `path`, `content`, `version`, `operation_id`) and per operation receipt (`kind: "op"`). Database and container are auto-created under key-based auth.
- **Compare-and-swap**: create uses `create_item` (fails if the id exists); replace and delete re-read the document, check the harness `version`, then write with `If-Match` on the Cosmos ETag, so a concurrent change between read and write is rejected. A stale version raises `MemoryConflictError`.
- **Operation receipts** are reserved with `create_item`, completed after the mutation, dropped if it fails — durable-execution replays return the original result; a reused id with different arguments raises `MemoryOperationConflictError`.
- `search` is the harness's bounded lexical search (`SearchableMemoryStore`); `list_paths` is a `STARTSWITH` query on `path`.

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

## License

MIT
