Skip to main content

KAOS Memory

kaos-memory is the production-grade agent memory library for KAOS: one package that owns the wire contract, the tiered storage engine and HTTP service, the service client, and an optional Pydantic AI integration. It is packaged so consumers only pull what they use.

Install Modules Dependencies
kaos-memory (core) kaos_memory.contract, kaos_memory.client Pydantic + httpx only
kaos-memory[service] kaos_memory.app, kaos_memory.stores, kaos_memory.config + Mem0, Chroma/pgvector, tiktoken, FastAPI
kaos-memory[pydantic-ai] kaos_memory.pydantic_ai + Pydantic AI
  • kaos_memory.contract — the HTTP contract: Scope selects reads/erasure, while level-less Attribution carries write identities.
  • kaos_memory.clientMemoryServiceClient, the framework-agnostic best-effort HTTP client for the service (recall degrades to empty; write/forget are fail-soft unless failure_mode="strict").
  • kaos_memory.pydantic_ai — direct Pydantic AI integration: message/turn adapters (pydantic_message_to_turns, reconstruct_message_history), server-side scope derivation (scope_from_deps), and the opt-in memory toolset (MemoryTools, build_memory_toolset).

The service ([service] extra) composes two atomic, independently-testable stores:

  • LongTermStore — wraps Mem0 as a library and exposes scope-mapped write / recall / delete / delete_scope. It is the only importer of mem0. Writes preserve compound user/agent attribution plus session/group metadata, and scope filters are applied inside vector queries so recall never crosses the selected boundary.
  • ShortTermStore — a per-session relational short-term buffer bounding a verbatim recency window by a token budget, with an opt-in fold that compacts evicted turns into a versioned per-session medium-term digest rather than truncating them. Every key combines the store group and session id, never the writing agent or principal, so the same run is addressable through any entitled recall scope while concurrent sessions never interleave raw turns. Folding is amortised by high/low water marks (evict down to the low mark on crossing the high mark), the digest is kept as append-only versions under a retention cap, and each fold's evicted batch is returned so callers can cascade it to long-term extraction. On Postgres the window is an UNLOGGED table and folds are serialised per session by an advisory lock so replicas cannot double-fold.

Both bind their models to a resolved OpenAI-compatible endpoint (a KAOS ModelAPI) via a single ModelConfig, and run in one of two storage modes:

Mode Vector store Short-term table Topology
local embedded Chroma SQLite single container on one PVC
external pgvector Postgres stateless, shared Postgres

Scope model

A Scope selects long-term read visibility and erasure. An Attribution write carries every verified contributor (user_id and real agent_id) plus session/group metadata, with no scope level. The service authoritatively enforces KAOS_MEMORY_REQUIRE_PRINCIPAL and KAOS_MEMORY_REQUIRE_AGENT_IDENTITY; runtime checks are defence in depth.

Scope level Long-term read filter
agent agent_id = <real agent identity> and, when present, user_id = <principal>
user user_id = <principal>; includes everything that user contributed through any agent/session
session kaos_run = <session id> and, when present, user_id = <principal>
store user_id = "*", kaos_group = <active collection name>; admin plane only

The wildcard is the pinned Mem0 2.0.10 convention required for custom-metadata filters. The internal kaos_group value is the configured collection name because one MemoryStore is the physical boundary; there is no synthetic agent sentinel. User/agent erasure uses native entity deletion, while session/store erasure filters custom attribution and deletes matching ids when Mem0 lacks a filtered-delete surface.

Short- and medium-term keys have the form kaos_group:<store group>|run:<session id> (or just run:<session id> without a configured group). A principal-bound read must match the session's attribution; a mismatch returns empty. A separate attribution index preserves user-, agent-, and store-level erasure without putting those identities into the session key.

Recall and list requests select tiers with include: ["short_term", "medium_term", "long_term"]. Responses contain only requested tier objects: long_term.{facts,block}, medium_term.summary, and short_term.window, plus top-level degraded.

Development

make build            # install with dev extras into the active venv
make test             # run the unit tests
make lint             # black --check + ty type check
make format           # black

Running the pgvector / Postgres tests

The external-mode tests are gated behind the pgvector marker and a DSN env var. Start a local container and point the tests at it:

docker run -d --name kaos-pgv \
  -e POSTGRES_PASSWORD=pw -e POSTGRES_DB=memdb \
  -p 55432:5432 pgvector/pgvector:pg16

export KAOS_TEST_PGVECTOR_DSN=postgresql://postgres:pw@localhost:55432/memdb
pytest tests/ -v

Without the DSN set, the pgvector-marked tests are skipped and the local Chroma/SQLite tests run on their own.

Layout

Module Purpose
config.py typed storage, model and short-term tier configuration
stores.py the whole storage layer: the Scope value object and Mem0 owner mapping, token counting, the OpenAI-compatible model client, the relational short-term store, and the Mem0-backed long-term adapter

The HTTP service, the agent-runtime client, and the operator wiring that resolves this configuration from a MemoryStore resource are built in subsequent phases.

Release files for kaos-memory 0.7.7

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

Source distribution (sdist)

Source distribution for kaos-memory 0.7.7
File Size Uploaded
kaos_memory-0.7.7.tar.gz 266.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kaos-memory 0.7.7
File Interpreter ABI Platform
kaos_memory-0.7.7-py3-none-any.whl Python 3 none any Details

Total release size: 305.1 kB

Release files / kaos_memory-0.7.7.tar.gz

Download URL kaos_memory-0.7.7.tar.gz
Size 266.8 kB
Tags Source
SHA-256 checksum
How to use checksums
46a3eff864fc535ccf8f9187553a9e08854ab3a043e135297ca47bc63a6aedc4
BLAKE2b-256 checksum
How to use checksums
df549ca967f12238501929bc06ae9b455d8b813dd5ef51f0cba69545fa8d6ca1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 19, 2026.

Transparency log

Release files / kaos_memory-0.7.7-py3-none-any.whl

Download URL kaos_memory-0.7.7-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d52aefd2f2ee486d7171becdaad647ea76d6b0f94883e83eeb85f1a21f24a4d
BLAKE2b-256 checksum
How to use checksums
5844c086a80f8d5357ce1940dd10406c575d81bacd3c7dbaa9df536550555ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 19, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.7.7 This release

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

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