Labsco
DexopT logo

AHME MCP

β˜… 2

from DexopT

Asynchronous Hierarchical Memory Engine

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeNeeds API keys
<div align="center">

AHME

Asynchronous Hierarchical Memory Engine

AHME Banner

Give your AI coding assistant a long-term memory β€” fully local, zero cloud, zero cost.

Python MCP Ollama License Tests

</div>

AHME is a local sidecar daemon that sits quietly beside your AI coding assistant. As you work, it compresses your conversation history into a dense Master Memory Block using a local Ollama model β€” no cloud, no tokens wasted, no context lost.

It integrates with any AI tool that supports MCP (Model Context Protocol): Antigravity, Claude Code, Kilo Code, Cursor, Windsurf, Cline/Roo, and more.


✨ How it works

Your AI conversation
        β”‚
        β–Ό  ingest_context
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   SQLite Queue    β”‚  ← persistent, survives restarts
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚  when CPU is idle
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Ollama Compressorβ”‚  ← local model (qwen2:1.5b, gemma3:1b, phi3…)
β”‚  (structured JSON)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚  recursive tree merge
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Master Memory Blockβ”‚ ← dense, token-efficient summary
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”œβ”€β”€ .ahme_memory.md   (file β€” for any tool that reads files)
         └── get_master_memory (MCP tool β€” for integrated tools)

Context-window replacement pattern: calling get_master_memory returns the compressed summary, clears the old data, and re-seeds the engine with the summary β€” so every new conversation starts from a dense checkpoint, not a blank slate.


πŸ”Œ Connect to your AI tool

AHME exposes three MCP tools: ingest_context, get_master_memory, and clear_context.

Option A β€” MCP (recommended)

Add AHME to your tool's MCP config. The exact file location varies by tool:

ToolConfig location
Claude Code--mcp-config .mcp.json flag, or ~/.claude/mcp.json
Kilo CodeVS Code settings.json β†’ "kilocode.mcp.servers"
CursorSettings β†’ MCP β†’ paste JSON
Windsurf~/.windsurf/mcp.json
Cline / RooMCP Servers sidebar β†’ Edit JSON
Antigravity~/.gemini/antigravity/mcp_config.json

Config snippet (works everywhere):

{
  "mcpServers": {
    "ahme": {
      "command": "python",
      "args": ["-m", "ahme.mcp_server"],
      "env": { "PYTHONPATH": "/absolute/path/to/ahme" }
    }
  }
}

A ready-made .mcp.json is included in the repo root β€” just copy it to where your tool expects it.

Option B β€” File watch (zero config)

After any compression, AHME writes .ahme_memory.md in the project directory. Reference it in any prompt:

@[.ahme_memory.md] use this as your long-term context before answering

Or set up persistent injection with .agents/instructions.md (Antigravity):

Before starting any task, read @[.ahme_memory.md] and treat it as background context.

πŸ›  MCP Tools Reference

ToolInputBehaviour
ingest_contexttext: stringPartitions text into chunks and queues them for background compression
get_master_memoryreset?: bool (default true)Returns the compressed summary; if reset=true, clears the DB and re-seeds with the summary
clear_contextβ€”Wipes all queued data with no return value

Typical usage pattern

1. [After each conversation turn]
   β†’ call ingest_context with the latest messages

2. [When approaching context limit, or starting a new session]
   β†’ call get_master_memory
   β†’ inject the result into your system prompt
   β†’ the engine resets and starts accumulating again from this checkpoint

🐍 Python API

If you'd rather control AHME directly from Python:

import asyncio
from ahme.api import AHME

engine = AHME("config.toml")

# Push text into the queue
engine.ingest("The user asked about Python async patterns. We discussed...")

# Run the daemon (this blocks; use asyncio.create_task for non-blocking)
asyncio.run(engine.run())

# Read the compressed memory
print(engine.master_memory)

# Stop the daemon
engine.stop()

πŸ“ Project Structure

ahme/
β”œβ”€β”€ ahme/
β”‚   β”œβ”€β”€ __init__.py          # Package marker & version
β”‚   β”œβ”€β”€ config.py            # Typed TOML config loader
β”‚   β”œβ”€β”€ db.py                # SQLite queue β€” enqueue, dequeue, clear, retry
β”‚   β”œβ”€β”€ partitioner.py       # Token-accurate overlapping chunker (tiktoken)
β”‚   β”œβ”€β”€ monitor.py           # CPU + lock-file idle detector (psutil)
β”‚   β”œβ”€β”€ compressor.py        # Ollama async caller β†’ structured JSON summaries
β”‚   β”œβ”€β”€ merger.py            # Recursive batch-reduce tree β†’ Master Memory Block
β”‚   β”œβ”€β”€ daemon.py            # Main event loop + graceful shutdown + file bridge
β”‚   β”œβ”€β”€ api.py               # Clean public Python API
β”‚   └── mcp_server.py        # MCP server β€” stdio & SSE transports
β”œβ”€β”€ tests/                   # 19 tests, all passing
β”œβ”€β”€ .mcp.json                # Ready-to-use MCP config
β”œβ”€β”€ config.example.toml      # Template config β€” copy to config.toml
β”œβ”€β”€ pyproject.toml           # pip-installable package
└── README.md

πŸ§ͺ Testing

pip install -e ".[dev]"
python -m pytest tests/ -v

Expected output: 19 passed β€” all tests use mocks and never require a live Ollama instance.


πŸ”‘ Key Design Decisions

DecisionRationale
SQLite over RedisZero external dependencies, single-file persistence, survives crashes
tiktoken for chunkingReal BPE token counting prevents prompt overflow
150-token overlapPreserves context at chunk boundaries
CPU + lock-file gatingAHME never competes with your active AI session for GPU/CPU
Recursive tree mergeScales compression with conversation length β€” O(log n) passes
JSON-only system promptEnforces structured output from Ollama for reliable parsing
__file__-relative pathsConfig and DB are always found regardless of working directory

🀝 Contributing

Contributions welcome! Please open an issue before submitting large PRs.


πŸ“„ License

MIT β€” do whatever you like.


<div align="center"> <sub>Built with Python Β· Ollama Β· SQLite Β· MCP</sub> </div>