Skip to content

[Feature]: Integrate Headroom as an optional context compression layer to reduce token consumption by 60-95% #5063

Description

@K1-lihongrong

Summary

Integrate Headroom — a local-first, reversible context compression layer — as an optional plugin/proxy in QwenPaw. Headroom compresses tool outputs, conversation history, RAG chunks, and file contents before they reach the LLM, achieving 60–95% token reduction with no accuracy degradation on standard benchmarks.

Component(s) Affected

  • Core / Backend (app, agents, config, providers, utils, local_models)
  • Console (frontend web UI)
  • Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
  • Skills
  • CLI
  • Documentation (website)
  • Tests
  • CI/CD
  • Scripts / Deploy

Problem / Motivation

QwenPaw agents routinely handle large contexts that drive up token consumption and API costs:

  1. Tool outputsbrowser_use snapshots, shell command results, file reads can each be thousands of tokens
  2. Conversation history — long-running sessions accumulate massive history that must be re-sent each turn
  3. Multi-agent collaboration — context is duplicated across agent boundaries
  4. Heartbeat polling — each heartbeat re-reads files like HEARTBEAT.md, MEMORY.md, TODO.md

Headroom is purpose-built for exactly this class of problems. It runs entirely locally, supports reversible compression (originals are never lost — the LLM can retrieve them on demand via CCR), and has been validated on real agent workloads:

Workload Before After Savings
Code search (100 results) 17,765 1,408 92%
SRE incident debugging 65,694 5,118 92%
GitHub issue triage 54,174 14,761 73%
Codebase exploration 78,502 41,254 47%

Accuracy preserved on GSM8K (±0.000), TruthfulQA (+0.030), SQuAD v2 (97% at 19% compression), BFCL (97% at 32% compression).

Proposed Solution

I propose a phased integration approach:

Phase 1: Proxy mode (minimal code changes)

Headroom's headroom proxy --port 8787 mode acts as a drop-in OpenAI-compatible proxy. QwenPaw could:

  1. Add a config option headroom.enabled = true/false and headroom.port = 8787 in config.toml
  2. When enabled, route all LLM API calls through http://localhost:8787/v1/... instead of the provider directly
  3. Headroom handles compression/decompression transparently — zero changes to QwenPaw's message pipeline

This is the quickest path to value and can be implemented in a day.

Phase 2: Library mode (deeper integration)

Use from headroom import compress inline for specific high-volume contexts:

  • Tool output compression: compress browser_use snapshots and large shell outputs before adding them to the message history
  • Conversation history windowing: apply Headroom's IntelligentContext / RollingWindow to maintain a compressed summary of older turns
  • File content compression: compress file reads (MEMORY.md, TODO.md, skill docs) before sending to the LLM

Phase 3: Cross-agent memory & failure learning

  • Shared memory: Headroom's SharedContext provides compressed context passing across multi-agent workflows — natural fit for QwenPaw's multi-agent architecture
  • headroom learn: mines failed sessions and writes corrections to AGENTS.md / MEMORY.md — directly maps to QwenPaw's existing memory system

Phase 4: MCP integration

Headroom exposes MCP tools (headroom_compress, headroom_retrieve, headroom_stats). QwenPaw's MCP-compatible agents could use these directly.

Alternatives Considered

  1. Provider-native compaction (Anthropic/OpenAI built-in prompt caching) — passive, no control over what gets cached, doesn't work for tool outputs
  2. Manual prompt engineering — fragile, agent-specific, doesn't scale
  3. RTK (rtk-ai/rtk) — CLI output rewriting only, no conversation/JSON/file compression
  4. lean-ctx — similar scope to RTK, no reversible compression or cross-agent memory
  5. Custom compression — would require building and maintaining our own compression pipeline, which is exactly what Headroom already does well

Headroom is the most comprehensive option: it covers all content types, runs locally, is reversible, and has proven accuracy on benchmarks.

Additional Context

Headroom is already trending on GitHub and has an active community. It's a natural complement to QwenPaw's mission of being a powerful multi-agent platform — adding context compression would make QwenPaw significantly more cost-effective for heavy users.

Willing to Contribute

  • I am willing to open a PR for this feature (after discussion).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions