PPA Compression
Partition a long message, summarise each chunk in isolation, then aggregate. Macro-fallacy-resistant by construction.
ceng distills the strongest context-engineering research of the past two years into four production-shaped Python primitives — compression, self-consistency checks, evolving playbooks, and portable OKF bundles. One pip install. No framework lock-in.
1 from ceng import ppa_compress
3 small = ppa_compress(
4 messages, # longest user message
5 budget_tokens=2000,
6 llm="gpt-4o-mini",
7 cache_dir=".ceng/cache",
8 )
10 # 260k tokens → 2.1k golden summary
11 print(small.tokens) # 2103 Pipeline
Built on the research you can cite
Why ceng
The strongest context-engineering papers of the last two years converged on the same insight: a good prompt is only as good as the context it stands on. ceng packages that insight into primitives you can reason about.
Finite context is the precious resource. Every ceng strategy starts from the U-shape retention curve — keep what models actually use, compact the rest.
Each primitive is pinned to a specific paper, with recommended hyperparameters and verbatim prompts where the authors shipped them.
Every entry point is a plain synchronous function. No agents, no orchestration, no lock-in — call it from any stack you already run.
Two runtime dependencies. Third-party SDKs load lazily, and transient failures recover with exponential backoff plus jitter.
Context retention · U-shape
compact_messagesKept verbatim
System prompt, opening turns, and the latest context — untouched.
Distilled away
The middle strip collapsed in a single backend call, with provenance.
The primitives
Every function is synchronous, return-typed, and cache-aware. Compose them, or call one — they stand alone and disappear into your codebase.
Partition a long message, summarise each chunk in isolation, then aggregate. Macro-fallacy-resistant by construction.
Ask at the population level and per leaf of a binary tree, then compare. Catch macro fallacies before they ship.
ACE's Generator → Reflector → Curator loop with the paper's recommended hyperparameters baked in as defaults.
Portable, on-disk context bundles with just-in-time retrieval. index.md + combined.md by default — nothing more.
Preserve primacy and recency, summarise the middle in one call. The system role is never dropped or altered.
Filesystem-backed external memory with atomic writes, LRU compaction, and pinned notes. No database, no daemon.
All entry points are synchronous — no async, no streaming, no hidden agents to reason about.
In practice
No builder objects. No context managers. Just named functions with sensible defaults and typed returns.
from ceng import ppa_compress
messages = [
{"role": "system", "content": "You are a careful analyst."},
{"role": "user", "content": "<very long context…>"},
]
small = ppa_compress(
messages,
budget_tokens=2000, # whatever fits the ceiling
llm="gpt-4o-mini", # any litellm model id
cache_dir=".ceng/cache",
) 260k tokens in, a golden summary out — leaves summarised in isolation, combined without macro fallacies.
from ceng import ppa_check
verdict = ppa_check(
question="What fraction of users prefer feature X?",
population="All of our users",
tree=[
{"description": "EU users", "prior": 0.3, "children": [
{"description": "German users", "prior": 0.5},
{"description": "French users", "prior": 0.5},
]},
{"description": "US users", "prior": 0.7},
],
llm="gpt-4o-mini",
)
print(verdict.self_consistent) # False ⇒ macro fallacy Population-level and per-leaf answers are compared automatically. A mismatch is your early warning.
from ceng.playbook import empty_playbook
from ceng.playbook.evolver import Evolver
ev = Evolver(llm="gpt-4o-mini", cache_dir=".ceng/cache")
playbook, stats = ev.run(
playbook=empty_playbook(),
queries=train_samples, # {"question", "ground_truth"}
evaluator=lambda q, a, s: "correct" if a == s["ground_truth"] else "wrong",
max_iterations=5,
)
# Generator → Reflector → Curator with ADD / UPDATE / MERGE / DELETE Paper defaults out of the box: 5 reflector rounds, 0.90 dedup, 80k-token playbook budget.
from ceng.compact import compact_messages
small, prov = compact_messages(
long_chat_history,
preserve_first=2, # keep system + first user
preserve_last=4, # keep the most recent turns
summarise_middle=True, # one backend call for the strip
llm="gpt-4o-mini",
)
print(prov.summarised_count) # provenance for your logs The system role is never dropped or altered — a ValueError guards it at the boundary.
0
research-grade primitives
compress · check · evolve · store
0 +
tests, fixture-driven
no live LLMs in the suite
0
backends, one interface
litellm · openai · vllm
0
runtime dependencies
litellm + pyyaml, nothing else
Citations, not vibes
No hand-waving. Each function traces to a specific publication — with the authors' own prompts and recommended hyperparameters where they shipped them.
Wolf, Kleine Buening, Krause, Mendler-Dünner · 2026
Macro-fallacy-resistant summarisation — partitioned, summarised in isolation, aggregated.
ppa_compress · ppa_check
Zhang, Hu, Upasani et al. · 2026
Evolving itemised playbooks, updated by a Generator → Reflector → Curator loop.
ceng.playbook.Evolver — verbatim prompts, paper defaults
Hua, Ye, Fu et al. · 2025
Memory as a first-class engineering concern, not an afterthought.
Philosophy that drives compaction + notes defaults
Anthropic Engineering
Finite context as a precious resource — just-in-time retrieval over eager context stuffing.
OKF index-only default · U-shape compaction
McVeety & Hormati · Google Cloud
A portable, self-describing on-disk bundle for knowledge — relational and shareable.
ceng.okf reader / writer · bundle builders
Get started
Python 3.10 – 3.12. One import, typed returns, silent-by-default logging. Apache-2.0, so ship it anywhere.
$ pip install ceng
litellm + pyyaml — the base install
$ pip install ceng[tokenize]
adds exact tiktoken counting
$ pip install ceng[openai]
raw openai.OpenAI client, leaner
$ pip install ceng[vllm]
in-process vLLM on your GPU
import ceng ceng.set_backend("litellm") # openai · vllm also built in from ceng import ppa_compress small = ppa_compress( messages, budget_tokens=2000, llm="gpt-4o-mini", # or any model you can name cache_dir=".ceng/cache", ) print(f"{len(messages)} messages → {budget_tokens}-token summary")
Enough reading
Whatever you build — agents, RAG, evals, long-running chats — ceng gives you the researched primitives to make your tokens count.
Apache-2.0 · no telemetry · no hidden agents