Spaces:
Build error
Build error
Commit History
-
style: ruff format parser.py, content_router.py, smart_crusher.py
Pre-existing formatting issues caught by CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>257873b -
fix: harden edge cases, expand tool exclusions, and fix mypy errors
- Fix division-by-zero in OpenAI cache, BM25 scorer, BLEU metrics, and smart_crusher - Add null safety for SQLite memory store JSON fields - Add thread safety lock for CCR retrieval counter - Add timeout/error handling for CCR stream collection - Safer error logging and JSON serialization fallback in proxy server - Return explicit zero stats on compression failure instead of None defaults - Guard against missing "messages" key in ASGI and LiteLLM integrations - Add aclose() for proper httpx client cleanup in ASGI middleware - Expand DEFAULT_EXCLUDE_TOOLS to include Grep, Write, Edit - Revert protect_recent_reads_fraction to 0.0 (protect all excluded-tool outputs) - Fix whitespace waste detection to use tokenizer for both original and normalized - Fix top-waste-requests sorting by tokens_saved instead of tokens_before - Fix TOCTOU race in semantic cache _touch() method - Fix mypy errors: type annotations for ASGI receive/send and proxy error loggingc8388c1
-
fix: Handle Anthropic format tool_use/tool_result as atomic units
Prakersh Maheshwari +1: Claude Opus 4.5Root Cause: The `find_tool_units()` function in `parser.py` only detected OpenAI format tool calls (assistant.tool_calls + role="tool" messages), not Anthropic format (assistant.content[type=tool_use] + user.content[type=tool_result]). This caused RollingWindow and IntelligentContext transforms to treat Anthropic tool_use and tool_result as separate, independently droppable messages. When context needed to be trimmed, the assistant message with tool_use could be dropped while keeping the user message with tool_result, creating orphaned tool_result blocks. When sent to the Anthropic API, this produces the error: "unexpected tool_use_id found in tool_result blocks" Changes: 1. parser.py: Extended `find_tool_units()` to detect Anthropic format: - Scan user messages for content blocks with type="tool_result" - Scan assistant messages for content blocks with type="tool_use" - Map tool_use_id to corresponding response message indices 2. rolling_window.py: Extended `_get_protecte…142a6dd
-
Prepare for OSS release v0.2.0
This commit prepares Headroom for public open source release with comprehensive documentation, licensing, and community infrastructure. License & Legal: - Add Apache 2.0 LICENSE file - Add NOTICE file with third-party attributions - Add SECURITY.md for vulnerability reporting Community: - Add CONTRIBUTING.md with contribution guidelines - Add CODE_OF_CONDUCT.md (Contributor Covenant) - Add GitHub issue templates (bug report, feature request) - Add pull request template Documentation: - Update README.md with compelling value proposition - Add docs/getting-started.md - Add docs/proxy.md for proxy server documentation - Add docs/transforms.md for transform reference - Add docs/api.md for API reference - Add examples/README.md Package Infrastructure: - Add headroom/py.typed for PEP 561 compliance - Add headroom/cli.py for CLI entry point - Add .github/workflows/ci.yml for CI pipeline - Add .github/workflows/publish.yml for PyPI publishing - Update pyproject.toml with proper metadata N…175746c -
Initial commit: Headroom SDK - LLM context optimization toolkit
A comprehensive SDK for optimizing LLM context windows, reducing token usage while preserving critical information for AI agents. Core Features: - SmartCrusher: Statistical compression of tool outputs (70-85% reduction) - CacheAligner: Prefix optimization for prompt cache hits - RollingWindow: Intelligent context window management - BM25/Hybrid relevance scoring for smart item selection Integrations: - OpenAI and Anthropic provider support - LangChain integration (ChatModel, Callbacks, Runnable) - MCP (Model Context Protocol) integration for tool compression Test Coverage: - 372 tests passing across all modules - 35 performance benchmarks - Real-world agent evaluations with 88% token savings Key Components: - headroom/transforms/: Core compression transforms - headroom/providers/: OpenAI and Anthropic support - headroom/integrations/: LangChain and MCP integrations - headroom/relevance/: BM25 and hybrid scoring - headroom/pricing/: Model pricing registry - benchmarks/: Performance …9c7d451