headroom/examples
chopratejas 8766d83f68 Rewrite README with verified before/after examples
- Replace marketing claims with actual API test results
- Add needle-in-haystack test: critical error at position 67/100
- Show real JSON compression: 100 entries → 6 entries (93.9% reduction)
- Verified with Claude Sonnet: 87.6% fewer tokens, 4/4 correct answers
- Add example scripts for reproducing the tests
2026-01-19 08:19:37 -08:00
..
langchain_demo Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
mcp_demo Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
anthropic_example.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
basic_usage.py Publish headroom-ai v0.2.0 to PyPI with DevEx fixes 2026-01-10 14:51:08 -08:00
capture_before_after_json.py Rewrite README with verified before/after examples 2026-01-19 08:19:37 -08:00
ccr_demo.py v0.2.2: Add CCR Response Handler, Context Tracker, and restructure docs 2026-01-14 13:03:41 -08:00
fast_memory_e2e.py Add persistent memory system with zero-latency inline extraction 2026-01-14 21:32:09 -08:00
inline_memory_demo.py Add persistent memory system with zero-latency inline extraction 2026-01-14 21:32:09 -08:00
langchain_before_after.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
memory_e2e_test.py Add persistent memory system with zero-latency inline extraction 2026-01-14 21:32:09 -08:00
memory_latency_benchmark.py Add persistent memory system with zero-latency inline extraction 2026-01-14 21:32:09 -08:00
needle_in_haystack_test.py Rewrite README with verified before/after examples 2026-01-19 08:19:37 -08:00
README.md Prepare for OSS release v0.2.0 2026-01-07 11:36:44 -08:00
real_before_after_test.py Rewrite README with verified before/after examples 2026-01-19 08:19:37 -08:00
real_world_eval.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
real_world_openai_eval.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
show_actual_compression.py Rewrite README with verified before/after examples 2026-01-19 08:19:37 -08:00
smart_vs_naive_eval.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
streaming_example.py Initial commit: Headroom SDK - LLM context optimization toolkit 2026-01-06 23:16:58 -08:00

Headroom Examples

This directory contains examples demonstrating Headroom's capabilities.

Quick Start Examples

basic_usage.py

Basic integration with OpenAI client:

export OPENAI_API_KEY='your-key'
python examples/basic_usage.py

anthropic_example.py

Integration with Anthropic Claude:

export ANTHROPIC_API_KEY='your-key'
python examples/anthropic_example.py

streaming_example.py

Streaming responses with optimization:

export OPENAI_API_KEY='your-key'
python examples/streaming_example.py

Evaluation Examples

smart_vs_naive_eval.py

Compare SmartCrusher against naive truncation:

export OPENAI_API_KEY='your-key'
python examples/smart_vs_naive_eval.py

real_world_eval.py

Comprehensive evaluation with Anthropic models:

export ANTHROPIC_API_KEY='your-key'
python examples/real_world_eval.py

real_world_openai_eval.py

Comprehensive evaluation with OpenAI models:

export OPENAI_API_KEY='your-key'
python examples/real_world_openai_eval.py

Demo Directories

langchain_demo/

Full LangChain agent integration demo:

# No API key needed for compression demo
PYTHONPATH=. python -m examples.langchain_demo.show_compression

# Full comparison (requires API key)
export OPENAI_API_KEY='your-key'
PYTHONPATH=. python -m examples.langchain_demo.run_comparison

See langchain_demo/README.md for details.

mcp_demo/

MCP (Model Context Protocol) integration demo:

export OPENAI_API_KEY='your-key'
PYTHONPATH=. python -m examples.mcp_demo.run_agent_eval

Running Examples

All examples can be run from the repository root:

# Install dependencies
pip install -e ".[dev]"

# Run any example
python examples/<example_name>.py

Expected Results

Example Token Savings Notes
basic_usage 50-70% Simple tool output compression
langchain_demo 70-85% Real agent with multiple tools
mcp_demo 60-80% MCP tool outputs
real_world_eval 50-90% Varies by scenario

Troubleshooting

ModuleNotFoundError: No module named 'headroom'

Run from the repository root with PYTHONPATH:

PYTHONPATH=. python examples/basic_usage.py

Or install in development mode:

pip install -e .

API Key Errors

Ensure your API keys are set:

export OPENAI_API_KEY='sk-...'
export ANTHROPIC_API_KEY='sk-ant-...'