Skip to main content

Keel

ci PyPI docs

Stop rebuilding the pipeline for every agent.

Docs: angelkurten.github.io/keel · Why: We built four agents and four copies of our customer context

Keel is a context layer for AI agents inside vertical SaaS products. Domain events from your product go in; a bitemporal context graph per end-customer comes out; every agent you build reads and writes it through the same five MCP tools.

You describe your vertical once, in a cartridge (ontology, event catalog, semantic rules, memory policies). Keel's core knows nothing about your domain. Your second agent connects in a day instead of weeks, because there is no second pipeline to write.

Status: 0.24.1, alpha. Container: ghcr.io/angelkurten/keel. The five tools over MCP and an HTTP JSON API (/v1), Postgres, webhook, Kafka and SQS adapters, semantic search, consolidation, an agent registry and SDKs for TypeScript, Python, Go and PHP, on the in-memory store, SQLite (--db keel.db, stdlib, no server to run) or MySQL (--db mysql://...).

Terminal demo: validate the stream against the cartridge, ingest, ask for a tire's context with the rule's verdict, run an agent with no LLM

The problem

Every new agent in a SaaS product repeats the same work: extract the customer's data, normalize it, decide what "critical" means, keep its own memory, expose its own tools to the model. Four agents, four copies of the customer's context, four definitions of "critical", four memories that never talk.

Existing memory layers (Zep, Mem0, AgentCore Memory, Neo4j's MKG) ingest text and documents and model memory per user or per agent. None of them start from domain events, and none model the tenant of the tenant: the end-customer of a B2B SaaS.

How Keel is different

  1. Cartridges. A vertical is declared in YAML plus a few ten-line handlers. The core stays generic. Write a cartridge for fleets, clinics, logistics, or your own product.
  2. Events in, not documents. Keel ingests structured facts with time (Postgres tables, webhooks, Kafka, SQS). Ingestion is deterministic and cheap. The graph is exact because it is born from events, not inferred from text.
  3. Every fact carries its provenance. Source, valid_from, valid_to, recorded_at, and who corrected it. Audit-ready by construction.
  4. Tenant of the tenant. One subgraph per end-customer, with its own permissions and expiry.

Five tools, any agent

context(subject, as_of?, depth?, as_known_at?, task?, detail?, exclude?, only?)
  -> what is true now, at as_of, or as known at a past moment; rules and their verdicts;
     depth=1 adds the neighbors; detail="concise" for about a third of the tokens; only=[...] just those predicates
history(subject?, since?, until?, predicate?, scope?, as_known_at?, task?, changed_since?, limit?)
  -> what was true and when we learned it; without a subject, what changed since a watermark
search(text?, kind?, rule?, limit?, after?, mode?, min_score?, related_to?, via?, detail?, depth?, per_kind?, exclude?, as_of?, where?)
  -> text or semantic search, or every entity of a kind / where a rule fires, paged;
     related_to (and via) keeps only one subject's neighbors; detail="concise" puts each result's facts in it;
     per_kind=n the best of every kind: the context for a task in one call
     where={name: value} by an attribute's or a fact's value; each result says what matched (matched, snippet);
     kind may be a list of kinds
annotate(subject, predicate, value, scope?, evidence?, by?, task?, key?, status?)
  -> an agent (or a person) writes what it learned; key makes retries safe; status="proposed" waits for review
related(subject, relation?, as_of?, depth?)
  -> neighbors by relation type, up to three hops

search(mode="semantic") finds subjects by meaning: ids in the query first, then a dense and a lexical leg fused, then an optional reranker. Where vectors live and which model makes them are adapters you choose: in memory, Chroma, Weaviate, any OpenAI-compatible embeddings endpoint, or your own vector database and model (how, example).

Expose them over MCP (keel serve) and point any agent framework at them. Declare agents: in the cartridge and keel serve --agent <id> binds a server to one of them: what it may read and write is enforced by the layer, not by the agent.

Quick start

uv sync --extra dev
uv run keel validate examples/fleet --events examples/fleet/events.jsonl
uv run keel ingest examples/fleet examples/fleet/events.jsonl
uv run keel context examples/fleet examples/fleet/events.jsonl unit:MXK-4821

Then write your own cartridge: see docs/first-cartridge.md (20 minutes). Settings (database, secret, embeddings keys) go in a .env: copy .env.example (reference).

In your own product it is a library: uv add keel-context (or pip install keel-context); the import is import keel. From another language, generate a typed client from your cartridge: keel sdk typescript|python|go|php examples/fleet -o <file>, with a small runtime per language (see docs/sdks.md).

Connect a real event stream

Point an MCP client at the five tools:

uv sync --extra mcp
uv run keel serve examples/fleet --tenant acme-logistics --events examples/fleet/events.jsonl

With Claude Code, one command registers it and the agent sees exactly five tools:

claude mcp add keel -- uv run --directory $PWD keel serve examples/fleet --tenant acme-logistics --events examples/fleet/events.jsonl

Codex CLI (OpenAI) works the same way from ~/.codex/config.toml; the four read tools are annotated read-only, so it runs them without prompting. Both clients answered the same questions through the same five tools: see connect. A backend, or many tenants from one process, use the same five as a JSON API: keel serve --transport http (/v1/context, /v1/events, ... with OpenAPI; tenant and agent per request).

Poll an outbox table in your Postgres (a cursor file makes restarts resume, not re-ingest):

import psycopg
from keel.adapters.postgres import PostgresTableAdapter

adapter = PostgresTableAdapter(lambda: psycopg.connect(DSN), table="keel_events", cursor_path=".keel/cursor")
ingestor = Ingestor(cartridge, SqliteStore("keel.db"))  # durable; MemoryStore() for a throwaway graph
ingestor.ingest(adapter.follow(interval=5))

Or consume a bus: KafkaAdapter.connect(...) and SqsAdapter.connect(...) in keel.adapters.bus (--extra kafka, --extra sqs), at-least-once, acknowledged only after the batch is committed. Or receive envelopes over HTTP (uv sync --extra webhook):

from keel.adapters.webhook import build_app

app = build_app(ingestor, token="shared-secret")  # POST /events, Authorization: Bearer <token>

The table shape and the envelope fields are in keel/adapters/postgres.py and keel/envelope.py. keel export <tenant> --db keel.db writes one tenant's whole audit trail as JSONL, closed facts and provenance included.

Architecture

  your SaaS (Postgres)   webhooks   Kafka / SQS
            \               |            /
             v              v           v
   +-------------------------------------------------+      +------------------+
   |  event envelope: tenant, type, subject, time     |      |  cartridge       |
   |  ingestor + handler registry                     | <--- |  ontology        |
   |  bitemporal context graph, one subgraph/tenant   |      |  event catalog   |
   |  memory scopes: global / tenant / task / agent   |      |  handlers        |
   |  five MCP tools                                   |      |  semantic rules  |
   +-------------------------------------------------+      |  memory policies |
            |              |             |                   +------------------+
         agent A        agent B       agent N (no pipeline)

Design rules the core enforces:

  • Events are the truth. An append-only log; the graph is derived and can be replayed. What agents and people wrote is kept across a replay.
  • Pointers, not copies. The graph holds references to your rows, the semantics, and earned memory. Never a copy of your tables.
  • Explicit time. Facts close, they are not overwritten.
  • Scopes, not a flat store. global > tenant > task > agent. Nothing is promoted to a wider scope by accident. Agent memory is read only by the agent that wrote it; task memory tied to a task id only by calls that pass that task (context(task=), history(task=)); global memory lives in a reserved partition every tenant reads and no event writes.

Repository layout

keel/            core: envelope, handlers, store, scopes, cartridge loader, ingest, tools, cli
cartridges/      your own cartridges (empty here)
examples/        fleet (reference), crm, finance and clinics: four domains, one core, no core change between them;
                 each a cartridge, its events and its test; fleet also has a minimal agent and a multi-agent workflow
sdk/             SDK runtimes: typescript, go, php (the Python client ships in keel)
evals/           the semantic-search eval bench
docs/            site sources (mkdocs.yml at the root): first-cartridge, connect, sdks, SPEC
tests/

Roadmap

A summary; the full plan, with what each release shipped, is in ROADMAP.md.

Shipped:

  • Event envelope, handler registry, deterministic ingest with dedupe by event id and replay
  • Bitemporal store: in memory, SQLite and MySQL, behind a store protocol with a conformance suite
  • Memory scopes with TTL, evidence policy, expiry and consolidation into durable facts (keel expire, keel consolidate)
  • The five tools over MCP (stdio and HTTP) and a JSON API, with an agent registry (people included)
  • Adapters: Postgres outbox, webhook, Kafka, SQS
  • Rules that compose, follow relations and measure durations
  • Transaction time (as_known_at), changes since a watermark, task ids, idempotent writes, proposals, conflicts, traces
  • SDKs generated from the cartridge: TypeScript, Python, Go, PHP
  • Bulk ingest (a million events in under a minute and a half on MySQL)
  • Semantic search: hybrid, ids first, rerankers, pluggable vector index and embedder, with an eval bench

Open:

  • Real agent queries from pilots in the semantic-search eval bench
  • Postgres CDC adapter
  • Cartridge catalog, hosted Keel, enterprise features (2027)

License

Apache 2.0. The event envelope, the cartridge format and the five tools are the standard; they will always be free.

Metadata

Release files for keel-context 0.24.1

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

Source distribution (sdist)

Source distribution for keel-context 0.24.1
File Size Uploaded
keel_context-0.24.1.tar.gz 1.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for keel-context 0.24.1
File Interpreter ABI Platform
keel_context-0.24.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / keel_context-0.24.1.tar.gz

Download URL keel_context-0.24.1.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
836fe4706c537dfee1fcd33fee898f5a7393438639695eb9c0b77451a4240df0
BLAKE2b-256 checksum
How to use checksums
c5bf7b56714503a3d9bb31fb588dfdd3d84c4056541f0b924d0a9f84531279aa
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 Oct 18, 2026.

Transparency log

Release files / keel_context-0.24.1-py3-none-any.whl

Download URL keel_context-0.24.1-py3-none-any.whl
Size 125.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2728be12054457440e32d9894f9c4bda415600efe929d2c56ded6e50ffb4a1c7
BLAKE2b-256 checksum
How to use checksums
ae12f6dbf00462324a28b8783cc0b413a29d8c0a93d96545311d1d662d061c5e
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 Oct 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.27.1

2 release files

0.27.0

2 release files

0.26.0

2 release files

0.25.0

2 release files

0.24.2

2 release files

This release

0.24.1 This release

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.0

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.4

2 release files

0.16.3

2 release files

0.16.2

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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