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 single source of truth for the HTTP contract: the Scope/ScopeLevel identity and the recall/write/forget request and response schemas. Carries no engine or web-framework dependency, so both the service and the client import the same definitions.
  • 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. Owner scoping is applied inside the vector query so recall never crosses tenants.
  • ShortTermStore — a scope-keyed 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 medium-term digest rather than truncating them. 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 scope 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 names whose memory an operation touches and maps onto a Mem0 owner identifier:

Scope level Mem0 owner key
private agent_id (this agent)
user user_id (a principal)
session run_id (one run)
shared a reserved shared owner id on agent_id

shared resolves to a reserved owner id rather than an empty filter because Mem0 rejects an owner-less search. This module ships only the correct translation; fail-closed enforcement is a later phase.

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaos_memory-0.6.0.tar.gz (255.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kaos_memory-0.6.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file kaos_memory-0.6.0.tar.gz.

File metadata

  • Download URL: kaos_memory-0.6.0.tar.gz
  • Upload date:
  • Size: 255.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kaos_memory-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d83a124a978b08c0f6f322aae415bb726f51ad49b641eb7635898b4b267b9973
MD5 41a7764cb5503e0d9a3056ca00b42122
BLAKE2b-256 0638570f261a697b0da2619b2e2129ffcc36d2b3077aec0b570cd7e1e238fd29

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_memory-0.6.0.tar.gz:

Publisher: release.yaml on axsaucedo/kaos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_memory-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: kaos_memory-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kaos_memory-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae9d5f952d0d676b58dcc94b1a08a5095f8965581840d9cf2fd0f9a8c903192b
MD5 bd38bc742ca0541bb80cee989a1d0a31
BLAKE2b-256 a3e3c7009a966b509afeecfc633c6298c238a854f99771c5a17a99c3c81ea574

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_memory-0.6.0-py3-none-any.whl:

Publisher: release.yaml on axsaucedo/kaos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

This release

0.6.0 This release

2 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