From cd5ea2ea1d50b68290f368d2d9e61ff9b4f428ec Mon Sep 17 00:00:00 2001 From: chopratejas Date: Tue, 20 Jan 2026 00:44:55 -0800 Subject: [PATCH] Add architecture diagrams to README and docs --- README.md | 59 +++++++++++++++++++++++++++++++++++++++----- docs/ARCHITECTURE.md | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a5d62f060..dac9ddd58 100644 --- a/README.md +++ b/README.md @@ -122,14 +122,61 @@ Run it yourself: `python examples/multi_tool_agent_test.py` ## How It Works -Headroom doesn't summarize or truncate blindly. It uses **statistical analysis**: +> Headroom optimizes LLM context *before* it hits the provider — +> without changing your agent logic or tools. -1. **Detects redundancy** - Repeated fields like `"language": "typescript"` across 100 items -2. **Keeps what matters** - First items, last items, query-relevant matches, anomalies -3. **Preserves errors** - Never drops items containing "error", "exception", "failed" -4. **Maintains schema** - Output JSON structure stays identical +```mermaid +flowchart LR + User["Your App"] + Entry["Headroom"] + Transform["Context
Optimization"] + LLM["LLM Provider"] + Response["Response"] -The compression is **reversible** via CCR (Compress-Cache-Retrieve). If the LLM needs more data, it can request the original. + User --> Entry --> Transform --> LLM --> Response +``` + +### Inside Headroom + +```mermaid +flowchart TB + +subgraph Pipeline["Transform Pipeline"] + CA["Cache Aligner
Stabilizes dynamic tokens"] + SC["Smart Crusher
Removes redundant tool output"] + CM["Context Manager
Fits token budget"] + CA --> SC --> CM +end + +subgraph CCR["CCR: Compress-Cache-Retrieve"] + Store[("Compressed
Store")] + Tool["Retrieve Tool"] + Tool <--> Store +end + +LLM["LLM Provider"] + +CM --> LLM +SC -. "Stores originals" .-> Store +LLM -. "Requests full context
if needed" .-> Tool +``` + +> Headroom never throws data away. +> It compresses aggressively and retrieves precisely. + +### What actually happens + +1. **Headroom intercepts context** — Tool outputs, logs, search results, and intermediate agent steps. + +2. **Dynamic content is stabilized** — Timestamps, UUIDs, request IDs are normalized so prompts cache cleanly. + +3. **Low-signal content is removed** — Repetitive or redundant data is crushed, not truncated. + +4. **Original data is preserved** — Full content is stored separately and retrieved *only if the LLM asks*. + +5. **Provider caches finally work** — Headroom aligns prompts so OpenAI, Anthropic, and Google caches actually hit. + +For deep technical details, see [Architecture Documentation](docs/ARCHITECTURE.md). --- diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 117d61aa7..938021c98 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1,5 +1,51 @@ # Headroom SDK: A Complete Explanation +## Architecture Overview + +```mermaid +flowchart TB + subgraph Entry["Entry Points"] + Proxy["Proxy Mode
Zero code changes"] + SDK["SDK Mode
HeadroomClient"] + Integrations["Integrations
LangChain / Agno"] + end + + subgraph Pipeline["Transform Pipeline"] + direction TB + + CA["Cache Aligner
━━━━━━━━━━━━━━━
Extracts dynamic content
(dates, UUIDs, tokens)
Stable prefix for caching"] + + SC["Smart Crusher
━━━━━━━━━━━━━━━
Analyzes tool outputs
Keeps: first, last, errors, outliers
70-95% reduction"] + + CM["Context Manager
━━━━━━━━━━━━━━━
Enforces token limits
Scores by recency and relevance
Fits context window"] + + CA --> SC --> CM + end + + subgraph Cache["Provider Cache Optimization"] + direction LR + Anthropic["Anthropic
cache_control blocks
90% savings"] + OpenAI["OpenAI
Prefix alignment
50% savings"] + Google["Google
CachedContent API
75% savings"] + end + + subgraph CCR["CCR: Compress-Cache-Retrieve"] + Store[("Compression
Store")] + Tool["Retrieve Tool
LLM requests original"] + Store <--> Tool + end + + LLM["LLM API
OpenAI / Anthropic / Google"] + + Entry --> Pipeline + Pipeline --> Cache + Cache --> LLM + SC -.->|"Stores original"| Store + LLM -.->|"If needed"| Tool +``` + +--- + ## What Problem Does Headroom Solve? When you use AI models like GPT-4 or Claude, you pay for **tokens** - the pieces of text you send (input) and receive (output). The problem is: