Skip to main content

emk - Episodic Memory Kernel

Part of Agent OS - Kernel-level governance for AI agents

PyPI License: MIT Build Status

An immutable, append-only ledger for agent experiences. Part of the Agent OS ecosystem.


Why emk?

Agents that cannot remember their past repeat the same mistakes. Traditional databases let you update or delete records—this is dangerous for agent memory. What if a bug overwrites critical learning? What if you need to audit agent decisions?

We built emk to subtract the problem of mutable memory. Instead of complex database transactions and state management, we provide a single abstraction: the immutable Episode. Once written, never changed. This constraint eliminates entire classes of bugs and enables reliable agent learning systems.

Scale by Subtraction: By removing the ability to modify history, we remove the need for complex versioning, rollback logic, and concurrency controls. The result is a memory system that scales reliably.


Installation

pip install emk

Quick Start

from emk import Episode, FileAdapter

store = FileAdapter("agent_memory.jsonl")
episode = Episode(goal="Query user data", action="SELECT * FROM users", 
                  result="200 rows", reflection="Query was fast")
store.store(episode)

That's it. Five lines. Your agent's experience is now permanently recorded.


Memory Management Features 🆕

emk now includes powerful memory management features to address the challenge: Infinite memory leads to infinite retrieval costs and confusing context.

Memory Decay & Compression (Sleep Cycle)

Automatically summarize old episodes into semantic rules:

from emk import MemoryCompressor

compressor = MemoryCompressor(store, age_threshold_days=30)
result = compressor.compress_old_episodes()
# Compress 1000 episodes → 20 semantic rules

Benefits: 50-100x storage reduction, faster retrieval, preserved knowledge without overwhelming detail.

Negative Memory (Anti-Patterns)

Explicitly track failures to avoid repeating mistakes:

# Mark failures
failed = episode.mark_as_failure(reason="Connection timeout")
store.store(failed)

# Query both successes AND failures
patterns = store.retrieve_with_anti_patterns()
print(f"What works: {len(patterns['successes'])}")
print(f"What to avoid: {len(patterns['failures'])}")

Benefits: Prune search space instantly, learn from both successes and failures, "DO NOT TOUCH" vectors.

📖 Full documentation: See docs/MEMORY_MANAGEMENT.md and examples/memory_features_demo.py


Architecture

emk sits at Layer 1 (Primitives) of the Agent OS stack. It provides the foundational storage abstraction that higher layers depend on:

  • Layer 1 (Primitives): emk stores raw episodes. caas (Context-as-a-Service) reads from emk to build working memory. cmvk (Cryptographic Message Verification Kernel) may sign episodes for audit trails.
  • Layer 2 (Infrastructure): amb (Agent Message Bus) transports messages. iatp (Inter-Agent Trust Protocol) verifies trust. These layers may log their own episodes into emk.
  • Layer 3 (Framework): agent-control-plane orchestrates agents. scak (Self-Correction and Alignment Kernel) uses emk to learn from mistakes.

emk has zero dependencies on other Agent OS components. It is the foundation, not the application.


The Ecosystem Map

emk is one component of the modular Agent OS. Here's how the pieces fit together:

Layer Component Purpose Repository
Primitives caas Context-as-a-Service (Working Memory) caas
Primitives cmvk Cryptographic Verification Kernel cmvk
Primitives emk Episodic Memory Kernel emk
Infrastructure iatp Inter-Agent Trust Protocol iatp
Infrastructure amb Agent Message Bus amb
Infrastructure atr Agent Tool Registry atr
Framework agent-control-plane Agent Orchestration and Control agent-control-plane
Framework scak Self-Correction and Alignment Kernel scak

Each component is independently useful. Together, they form a complete Agent Operating System.


Citation

If you use emk in your research or production systems, please cite:

@software{emk2024,
  author       = {Siddique, Imran},
  title        = {emk: Episodic Memory Kernel for Agent Systems},
  year         = {2024},
  publisher    = {GitHub},
  url          = {https://github.com/imran-siddique/emk},
  note         = {Part of the Agent OS ecosystem}
}

License

MIT License - see LICENSE for details.

Metadata

Release files for emk 1.0.0

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

Source distribution (sdist)

Source distribution for emk 1.0.0
File Size Uploaded
emk-1.0.0.tar.gz 28.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for emk 1.0.0
File Interpreter ABI Platform
emk-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.8 kB

Release files / emk-1.0.0.tar.gz

Download URL emk-1.0.0.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ad23e6b93c7ef6df2e55f5e3bc5d1325f33b466c6966986bd5bd611ab16c6fb4
BLAKE2b-256 checksum
How to use checksums
073c982565576d91440b4e574f1344e72e21262246bc5cfe18e8da4de989587c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / emk-1.0.0-py3-none-any.whl

Download URL emk-1.0.0-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc867ef51d51bfe30561629308bb8567407ce84784f467a08b8c82117c182b92
BLAKE2b-256 checksum
How to use checksums
87485cc991f50c77f726a877eda6fbeeb99f1b73c676742a1a26aa180f314f87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.0.0 This release

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