Skip to main content

AI Agent Memory Framework — structured memory layers for LLM-based agents

Project description


🧠 Kryth

AI Agent Memory Framework — Structured memory layers for LLM-based agents


PyPI Version PyPI Downloads MIT License Python 3.10+ Ruff PRs Welcome


🚀 Quick Start✨ Features🏗️ Architecture📦 Installation🤝 Contributing



💡 Why Kryth?

LLM-based agents need memory — but not just any memory. They need structured, token-efficient, deduplicated memory that fits inside a context window. Kryth gives you:

Without Kryth With Kryth
❌ Bloated, unstructured context ✅ Token-capped retrieval (~800 tokens)
❌ Duplicate reads and redundant commands ✅ Smart duplicate detection & summarization
❌ Runaway memory growth ✅ Automatic compression with configurable limits
❌ Ad-hoc memory management ✅ Clean, modular controller architecture

🚀 Quick Start

from kryth import WriteController, RetrievalController, compute_state_hash

# Compute a unique state hash for your project
state_hash = compute_state_hash(cwd="/path/to/project")

# Route knowledge from tool calls into memory
write_ctrl = WriteController()
write_ctrl.on_tool_result(
    tool_name="read_file",
    args={"path": "main.py"},
    result="file contents...",
    error=False,
    session_id=1,
    memory_manager=memory_manager,  # Your MemoryManager instance
    turn=3,
)

# Retrieve only the most relevant memories for LLM context
retrieval_ctrl = RetrievalController()
context_block = retrieval_ctrl.build_prompt_block(
    memory_manager=memory_manager,
    session_id=1,
    user_input="What does the auth module do?",
)

💡 Tip: Kryth is designed to integrate with your existing MemoryManager. See the full documentation for setup details.


✨ Features

🧩 Modular Architecture

Each memory concern — writing, retrieval, deduplication, compression — is isolated in its own controller. Mix and match what you need.

📏 Token-Aware Retrieval

Context injection is always capped at ~800 tokens, ensuring your LLM stays focused and never exceeds context limits.

🎯 Relevance Ranking

Memories are scored and ranked by importance × query relevance, so only the most pertinent information makes it into the prompt.

🔍 Smart Duplicate Detection

Detects duplicate file reads and command executions — then returns a summary instead of hard-blocking. Never repeat work.

🧹 Automatic Compression

Prevents unbounded memory growth with configurable limits per memory layer. Set it and forget it.

🔐 State Hashing

Robust duplicate command detection using git diff, file hashes, and environment variables. Know when state has genuinely changed.


🏗️ Architecture

Kryth organizes memory into a clean, layered architecture:

flowchart TB
    subgraph Input["📥 Inputs"]
        TC[Tool Calls]
        UI[User Input]
    end

    subgraph Controllers["🎮 Controllers"]
        WC[WriteController]
        RD[DuplicateDetector]
        RC[RetrievalController]
        CC[CompressionController]
    end

    subgraph Memory["💾 Memory Layers"]
        RM[RepoMemory<br/>File contents, symbols]
        EM[ExecutionMemory<br/>Command history]
        EPM[EpisodicMemory<br/>Edits, decisions]
        WM[WorkingMemory<br/>Objective, blockers]
        LTM[LongTermMemory<br/>Summarized insights]
    end

    TC --> WC
    WC --> RM
    WC --> EM
    WC --> EPM
    WC --> WM
    WC --> RD
    RD -.->|Soft dedup| TC

    UI --> RC
    RC --> RM
    RC --> EM
    RC --> EPM
    RC --> WM
    RC -.->|Optional| LTM

    CC --> EPM
    CC --> LTM
    CC --> EM

Memory Layers

Layer Purpose Written By
RepoMemory File contents, structure, symbols read_file
ExecutionMemory Command history and results run_command
EpisodicMemory Edits, decisions, findings edit_file, write_file
WorkingMemory Current objective and blockers set_objective
LongTermMemory Summarized insights Compression

Retrieval Priority

The RetrievalController builds context blocks in strict priority order, ensuring the most critical information is always included:

🥇  Current objective (always included)
🥈  Working memory findings + blockers
🥉  Top repo memory hits (ranked by importance × relevance)
    Recent command execution results
    Critical episodic findings
    Long-term memory summaries (optional)

📦 Installation

Stable release (recommended):

pip install kryth

Development version:

git clone https://github.com/navadeep0508/KRYTH-OS.git
cd kryth
pip install -e ".[dev]"

🧪 Development

# Set up environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

# Code quality
ruff check src/
mypy src/

🗺️ Roadmap

  • Core memory controllers (Write, Retrieve, Deduplicate, Compress)
  • Token-capped context retrieval
  • Integration with popular agent frameworks (LangChain, CrewAI)
  • Persistent storage backends (SQLite, PostgreSQL, Redis)
  • Async-first API
  • Interactive memory dashboard

🤝 Contributing

Contributions are what make the open source community such an amazing place! Any contributions you make are greatly appreciated.


📄 License

Distributed under the MIT License. See LICENSE for more information.


Made with ❤️ by navadeep0508

GitHubPyPIChangelogCode of Conduct

Project details


Download files

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

Source Distribution

kryth-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

kryth-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file kryth-0.1.0.tar.gz.

File metadata

  • Download URL: kryth-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for kryth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 897bf2707c31587f363621ff063ca12f3d895fff304f0f150f8c4ec59f992ac8
MD5 f687f94df72b40c729c2704e96d3a8f9
BLAKE2b-256 7f5472ea539e16fc25b8b02242bd2e537f8c34ef1db93308388c34c6eda4b2e4

See more details on using hashes here.

File details

Details for the file kryth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kryth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for kryth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a38d02c0def5d0d614b258723e1bad513af90a53a7060ba1c7491e8d50c99569
MD5 f005989625fcd11017177b79371bfc8a
BLAKE2b-256 4e8fe114dff21ecf4e33fbf57176a3c2c71af46524786bc5688baf63c74c535c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page