Files
headroom/examples/README.md
T
alan blount e67b3c8a29 feat(vertex): add Gemini 3.8 Flash agent benchmark suite (#3371)
## Summary

Adds a reproducible, end-to-end multi-turn agent benchmark suite for
**Gemini 3.8 Flash** on Google Cloud Vertex AI (Gemini Enterprise Agent
Platform) under `examples/vertex_gemini_benchmark/`.

Compares **Direct Vertex AI** vs **Headroom-proxied Vertex AI** across 4
realistic production agent scenarios:
1. **SRE Incident Root Cause Analysis**: 350+ Kubernetes & microservice
logs + Prometheus metrics (identifying connection pool exhaustion,
cluster endpoint, port, and cascading circuit-breaker trips).
2. **Codebase Security Audit & PR Review**: Multi-file code search
results + git diff (identifying insecure `alg: none` and `bypass_auth`
JWT backdoors).
3. **Enterprise BigQuery Analytics**: 500 tabular transaction rows
(computing summaries and isolating fraudulent accounts and high-spend
outliers).
4. **Multi-Turn RAG & System Architecture Synthesis**: 25 dense
technical chunks regarding agent context management contracts.

### Live Benchmark Results (Gemini 3.8 Flash on Vertex AI `global`)

```text
==================================================================================
 📊 FINAL BENCHMARK SUMMARY: GEMINI-3.8-FLASH ON VERTEX AI
==================================================================================
Scenario                           | Baseline Prompt | Headroom Prompt |  Reduction
----------------------------------------------------------------------------------
SRE Incident Root Cause Analysis   |          51,775 |          13,842 |      73.3%
Codebase Security Audit & PR Review |           6,821 |           4,632 |      32.1%
Enterprise BigQuery Analytics & Outlier Detection |          49,020 |           6,120 |      87.5%
Multi-Turn RAG & Architecture Synthesis |           4,071 |           1,437 |      64.7%
----------------------------------------------------------------------------------
TOTAL / AGGREGATE                  |         111,687 |          26,031 |      76.7%

Metric                             |        Baseline |        Headroom | Delta / Impact
----------------------------------------------------------------------------------
Total Prompt Tokens                |         111,687 |          26,031 | -        76.7%
Total All Tokens                   |         116,639 |          29,168 | -        75.0%
Total Cost ($ USD)                 | $       0.09410 | $       0.02849 | -        69.7%
Avg Latency (ms)                   |          8921ms |          5748ms |        +3173ms
Ground Truth Accuracy (Absolute)   |         100.0% |         100.0% | 100.0% Retained
==================================================================================
```

## Real Behavior Proof

• **Environment**: Linux, Python 3.11, live Google Cloud project
(`alanblount-demo`) with Vertex AI enabled, Application Default
Credentials (`gcloud auth application-default login`).
• **Exact command / steps**: `GCP_PROJECT_ID=alanblount-demo python
examples/vertex_gemini_benchmark/benchmark.py --model gemini-3.8-flash`
• **Observed result**: Headroom proxy started cleanly, executed all 4
multi-turn scenarios on `gemini-3.8-flash`, verified ground truth error
causes and anomalies, recorded a **76.7% prompt token reduction** and
**69.7% cost savings**, exported `results.json`, and shut down cleanly.
• **Not tested**: Windows.

## Runtime Rollout Safety

• **Rollout-managed feature(s)**: None; self-contained benchmark suite
under `examples/`.
• **Minimum rollout channel**: standard release.
• **Stable/default behavior changed**: None; purely adds benchmark
tooling and documentation under `examples/`.
• **Kill switch / disable path**: N/A.
• **Unsafe override required**: None.
• **Qualification impact**: None.
• **Rollback path**: Revert PR.

## Review Readiness

[✓] I have performed a self-review
[✓] This PR is ready for human review

## Checklist

[✓] My code follows the project's style guidelines
[✓] I have performed a self-review of my code
[✓] I have commented my code, particularly in hard-to-understand areas
[✓] I have made corresponding changes to the documentation
[✓] My changes generate no new warnings
[✓] I did not edit `CHANGELOG.md` — it is generated by release-please
from my Conventional Commit PR title (a CI guard enforces this)

## Additional Notes

• Companion to PR #2640 (which adds in-band Vertex diagnostic hints and
fixes).
2026-09-06 11:32:19 +08:00

5.0 KiB

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

tabular_compression_demo.py

Tabular + spreadsheet compression on generated sample data (no API key needed). Shows where CSV/markdown tables and .xlsx workbooks compress and where compact, all-unique data correctly passes through:

python examples/tabular_compression_demo.py            # run all scenarios
python examples/tabular_compression_demo.py --write DIR # also save the sample files

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

vertex_gemini_benchmark/

Gemini 3.8 Flash on Google Cloud Vertex AI (Gemini Enterprise Agent Platform) benchmark:

# Ensure Google Cloud ADC is active
gcloud auth application-default login
export GCP_PROJECT_ID="your-project-id"

# Run comparative benchmark (Direct vs Headroom Proxied)
python examples/vertex_gemini_benchmark/benchmark.py --model gemini-3.8-flash

See vertex_gemini_benchmark/README.md for full benchmark scenarios and methodology.

strands_bedrock_demo.py

AWS Strands Agents + Bedrock integration demo. Showcases two Headroom integration patterns:

  1. HeadroomHookProvider - Compresses tool outputs in real-time
  2. HeadroomStrandsModel - Optimizes entire conversation context
# Configure AWS credentials
export AWS_ACCESS_KEY_ID='your-access-key'
export AWS_SECRET_ACCESS_KEY='your-secret-key'
export AWS_DEFAULT_REGION='us-west-2'  # Optional, defaults to us-west-2

# Or use AWS profile
export AWS_PROFILE='your-profile-name'

# Run the full demo (both integration patterns)
python examples/strands_bedrock_demo.py

# Run only the hook provider demo
python examples/strands_bedrock_demo.py --hook

# Run only the model wrapper demo
python examples/strands_bedrock_demo.py --model

# Specify a different AWS region
python examples/strands_bedrock_demo.py --region us-east-1

The demo uses Claude 3 Haiku via Bedrock for cost efficiency. It creates agents with 4 tools that return verbose JSON output (search results, logs, database records, metrics) and displays compression statistics with visual comparisons.

Requirements:

  • AWS account with Bedrock enabled
  • Claude 3 Haiku model access in your region
  • pip install strands-agents headroom-ai[strands]

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
strands_bedrock_demo 60-85% Strands + Bedrock with verbose tools
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-...'

AWS Credentials Errors (for Strands demo)

Ensure AWS credentials are configured:

# Option 1: Environment variables
export AWS_ACCESS_KEY_ID='your-access-key'
export AWS_SECRET_ACCESS_KEY='your-secret-key'

# Option 2: AWS profile
export AWS_PROFILE='your-profile-name'

# Option 3: AWS credentials file (~/.aws/credentials)

Also ensure Bedrock and the Claude 3 Haiku model are enabled in your AWS account.