Skip to main content

Context Engineering Multi-Agent Framework - A pluggable, modular framework for building AI agent systems

Project description

CEMAF

Context Engineering Multi-Agent Framework

Open Source Project Status: Alpha Discord Python License Tests Coverage Ruff MyPy Stars Issues

Open source context engineering infrastructure that solves the hard problems in AI agent systems. CEMAF can be used standalone or plugged into existing frameworks like LangGraph, AutoGen, and CrewAI.


Table of Contents


Overview

CEMAF is a protocol-first framework designed for context engineering in multi-agent AI systems. It provides:

  • Token budgeting and automatic context optimization
  • Deterministic run recording and replay capabilities
  • Full provenance tracking for every context change
  • Memory management with strict scoping and TTL
  • Zero-config defaults with environment-based customization

Philosophy: Own the hard infrastructure problems while remaining framework-agnostic.


The Hard Problems We Solve

Problem What Happens CEMAF Solution
Context Growth Token limits blow up Token budgeting + automatic summarization
Reliability Non-deterministic behavior Patch-based provenance tracking
Cost Wasteful token usage Smart context compilation
Reproducibility Can't replay/debug runs Run recording + deterministic replay
Memory Leaks State bleeds between scopes Strict memory boundaries with TTL

Installation

# Core installation (minimal dependencies)
pip install cemaf

# With optional integrations
pip install "cemaf[openai]"        # OpenAI + tiktoken
pip install "cemaf[anthropic]"    # Anthropic
pip install "cemaf[tiktoken]"     # Accurate token counting only
pip install "cemaf[all]"          # All optional dependencies

# Development installation
git clone https://github.com/drchinca/cemaf.git
cd cemaf
pip install -e ".[dev]"

Requirements: Python 3.14+


Quick Start

from cemaf.context import Context, ContextPatch
from cemaf.observability import InMemoryRunLogger
from cemaf.replay import Replayer

# Create context with provenance tracking
ctx = Context()
patch = ContextPatch.from_tool("search", "results", {"items": [...]})
ctx = ctx.apply(patch)

# Record runs for replay
logger = InMemoryRunLogger()
logger.start_run("run-123", initial_context=ctx)
logger.record_patch(patch)
record = logger.end_run(final_context=ctx)

# Replay deterministically
replayer = Replayer(record)
result = await replayer.replay()
assert result.final_context == record.final_context  # Deterministic!

See the Quick Start Guide for more detailed examples.


Integration Modes

Mode A: CEMAF Orchestrates

CEMAF owns execution, external frameworks are "engines":

from cemaf.orchestration import DAGExecutor
from cemaf.observability import InMemoryRunLogger

executor = DAGExecutor(
    node_executor=LangGraphNodeExecutor(langgraph_app),
    run_logger=InMemoryRunLogger(),
)
result = await executor.run(dag, context)

# Replay later for debugging
replayer = Replayer(run_logger.get_record("run-123"))
await replayer.replay()

Mode B: CEMAF as Library

External frameworks orchestrate, CEMAF provides infrastructure:

from cemaf.context import Context, ContextPatch
from cemaf.observability import InMemoryRunLogger

@langgraph_node
def my_node(state):
    ctx = Context.from_dict(state)

    # Track provenance of every change
    patch = ContextPatch.from_tool("search", "results", search_results)
    ctx = ctx.apply(patch)
    run_logger.record_patch(patch)

    # Compile within budget
    compiled = compiler.compile(ctx, budget)
    return compiled.to_dict()

See the Integration Guide for detailed patterns.


Key Features

  • 📍 Context Patches: Track every context change with full provenance
  • 🔄 Deterministic Replay: Record and replay runs for debugging
  • 💾 Token Budgeting: Stay within limits with smart compilation
  • ⏱️ TTL & Cleanup: Memory items expire automatically
  • 🔒 Memory Boundaries: Strict scoping prevents state leaks
  • ⚡ Cancellation: Cooperative cancellation with timeouts
  • 🔧 Protocol-Based: Plug into any framework
  • ⚙️ Configuration-Driven: Zero-config defaults with .env customization

Documentation

Full Documentation →

Core Guides:

Module References:


Configuration

CEMAF is designed for zero-config startup with production-ready defaults. Customize via environment variables:

# Copy example configuration
cp .env.example .env

# Configure your setup
CEMAF_LLM_PROVIDER=openai
CEMAF_LLM_API_KEY=your-key
CEMAF_CACHE_BACKEND=redis
CEMAF_CACHE_MAX_SIZE=10000

Use factory functions for automatic configuration loading:

from cemaf.llm import create_llm_client_from_config
from cemaf.cache import create_cache_from_config

# Automatically loads from .env or environment
client = create_llm_client_from_config()
cache = create_cache_from_config()

See the Configuration Guide for all available settings.


Testing

# Run all tests
pytest tests/

# Unit tests only
pytest tests/unit/

# Skip slow tests
pytest tests/ -m "not slow"

# With coverage
pytest tests/ --cov=cemaf

# Pre-commit checks
pre-commit run --all-files

Project Stats: 814 tests | 100% passing | TDD from day one


Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development setup:

# Fork and clone the repo
git clone https://github.com/YOUR_USERNAME/cemaf.git
cd cemaf

# Install dependencies with uv
uv venv
uv sync

# Install pre-commit hooks
uv run pre-commit install

See HOW_TO_USE.md for detailed usage examples.


Getting Help

We're here to help! Here are the best ways to get support:

Documentation

Community

Contributing

Want to contribute? Check out our Contributing Guide to get started!

We're in Alpha and actively seeking feedback!


License

This project is licensed under the MIT License - see the LICENSE file for details.


Authors

Hikuri Bado Chinca (@drchinca) Email: chincadr@gmail.com

Copyright (c) 2026 | Published on 1.1.2026 🎉


Links

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

cemaf-0.1.0.tar.gz (334.2 kB view details)

Uploaded Source

Built Distribution

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

cemaf-0.1.0-py3-none-any.whl (273.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cemaf-0.1.0.tar.gz
  • Upload date:
  • Size: 334.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for cemaf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 84838096c0065f1ecc5042cb5a3ea70ba0b1c3afd7a430161c24726232d0341c
MD5 94fa6c6a81ead0ba2a5ec3796d52a8bb
BLAKE2b-256 6ce68d13ca3be53352115ed9a489ee587b8f3659c0e15c82918edd8dbc9b85c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cemaf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 273.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for cemaf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f241df4962865ccc92dacacdbadd89347b19ef914444e567b36cf23869e3f49
MD5 1aa805e6df2b242ede72b7f3381a40a0
BLAKE2b-256 4589753508c4a5ced9c282133fe2330b62a2961ab567a777cdeed34c6ca58ca6

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