Spaces:
Build error
Build error
Commit History
-
feat: add LangGraph compress_tool_messages node for ToolMessage compression
kunallohtiadba81a5
-
Updating the README to reflect the right positioning for Headroom
- Added Discord channel as well - README is now simpler66ac1c8
-
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
-
Add headroom learn: offline failure learning for coding agents
Analyzes past conversation history to find tool call failure patterns, correlates each failure with what eventually succeeded, and writes specific project-level learnings to CLAUDE.md and MEMORY.md. Key design: - Success correlation: extracts the diff between failed and successful inputs as the learning (not generic advice) - Generic architecture: tool-agnostic ToolCall model with pluggable Scanner/Writer adapters (Claude Code first, extensible to Cursor/Codex) - 5 analyzers: Environment, Structure, Commands, Retries, Cross-Session - Dry-run by default, --apply to write, --all for all projects Also fixes mypy errors in litellm_callback, asgi, langchain chat_model, and anthropic provider (AsyncClient typing, ToolCall arg-type, int cast).c14b9ac -
Add Cloud mode to ASGI middleware and LiteLLM callback
Both CompressionMiddleware and HeadroomCallback now support a cloud mode (api_key="hdr_xxx") that calls Headroom Cloud API for managed compression with org-scoped CCR, TOIN learning, and analytics. Falls back to HEADROOM_API_KEY env var. Local mode (default) is unchanged. Also adds x-headroom-tokens-before/after response headers and updates uv.lock with mcp extra and version bump to 0.3.3.2bd9316 -
Fix LangChain tool_call argument handling for varied message formats
LangChain provides tool_call args in different shapes (dict args, str arguments, nested function.arguments) depending on the source. Add _tool_call_args_to_json() helper to normalize all formats to JSON strings. Use .get() instead of [] to handle missing keys gracefully.126b60e
-
Add one-function compress() API, ASGI middleware, LiteLLM callback
Three new integration paths — no proxy needed: 1. headroom.compress(messages, model) → CompressResult One function, auto-detects tokenizer per model, works with any client. 2. headroom.integrations.asgi.CompressionMiddleware Drop-in ASGI middleware for LiteLLM proxy, FastAPI, or any ASGI app. 3. headroom.integrations.litellm_callback.HeadroomCallback LiteLLM callback: litellm.callbacks = [HeadroomCallback()] Fix: TransformPipeline._get_tokenizer() no longer requires a Provider. Falls back to tokenizer registry which auto-detects per model: - OpenAI → tiktoken (exact) - Anthropic → calibrated estimation (3.5 chars/token) - Open models → HuggingFace (if installed) 15 tests covering compress(), ASGI middleware, LiteLLM callback.6505c43
-
feat: Add AWS Strands Agents SDK integration
## Description Add Headroom integration with AWS Strands Agents SDK, enabling automatic context optimization and tool output compression for Strands-based agents. Fixes #14 ## Type of Change - [x] New feature (non-breaking change that adds functionality) - [x] Documentation update ## Changes Made ### Core Integration (`headroom/integrations/strands/`) - **HeadroomHookProvider** - Implements Strands `HookProvider` interface for automatic tool output compression via `AfterToolCallEvent`. Compresses verbose tool outputs before they enter conversation context. - **HeadroomStrandsModel** - Model wrapper that extends Strands `Model` base class for message-level optimization. Implements all required abstract methods: `stream()`, `get_config()`, `update_config()`, `structured_output()`. - **Provider auto-detection** - Automatically detects appropriate Headroom provider (Anthropic, OpenAI, Google) based on wrapped Strands model type. - **`strands-agents` as optional dependen…2550bb7
-
Fix mypy errors and add network timeout handler for flaky CI tests
Mypy fixes (no-any-return errors from external libraries): - litellm_pricing.py: cast litellm.model_cost - anthropic.py: cast litellm cost returns - cohere.py: cast litellm info/cost returns - compressor.py: explicit int() for PIL size calculations - sqlite.py: explicit bytes() for numpy tobytes() - universal.py: explicit str() for CCR store key - direct_mem0.py: explicit list() for OpenAI embedding - langchain/agents.py: explicit str() for result - server.py: explicit str() for httpx response.text - runner_v2/v3.py: add hasattr check for backend.close() Test fixes (flaky network timeouts in CI): - Add network_timeout_handler decorator to skip on httpx.ReadTimeout - Applied to test_close_idempotent, test_save_with_entities, test_add_batch_basic Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>7a63807
-
Add reasoning capability forwarding to HeadroomAgnoModel
- Add underlying_model property for framework introspection - Forward capability attributes (thinking, reasoning_effort, etc.) from wrapped model - Add has_extended_thinking_enabled() method for detecting extended thinking config - Update docstring with guidance on reasoning mode compatibility - Add 17 unit tests for reasoning capability forwarding2c5a3a3
-
Add Phase 2 Progressive Summarization and fix Agno integration tests
Phase 2 - Progressive Summarization: - Add ProgressiveSummarizer with callback pattern for external summarization - Add AnchoredSummary for tracking which message positions were summarized - Add SummarizationResult for tracking summarization operations - Add extractive_summarizer fallback when no LLM callback provided - Integrate CCR for storing originals and enabling retrieval - Add SUMMARIZE strategy to IntelligentContextManager - Add comprehensive tests (59 total for intelligent context) Agno Integration Fix: - Add _ensure_message_objects() to convert dicts to Agno Message objects - Fix response(), response_stream(), aresponse(), aresponse_stream() to ensure messages are Message objects before calling super() - Update test mocks to use proper ModelResponse and Metrics objects - All 66 Agno tests now pass4102402 -
Fix HeadroomAgnoModel to optimize tool outputs at invoke level
Previously, HeadroomAgnoModel called wrapped_model.response() which ran the tool execution loop internally. This meant tool outputs (often 60k+ chars) were never optimized - only the initial messages were compressed. The fix delegates response() to the inherited Model.response(), which calls self.invoke() for each API call. Our invoke() override optimizes messages before delegating to wrapped_model.invoke(), ensuring tool outputs are compressed on every API request. Results from multi_tool_agent_test.py with Claude Sonnet: - Tokens before optimization: 25,713 - Tokens after optimization: 6,100 - Tokens saved: 19,613 (76.3%) - Both baseline and optimized found all critical information Also adds: - multi_tool_agent_test.py: Real function calling test with 4 tools - multi_tool_compression_test.py: Direct compression test - README update with multi-tool agent test results39a55b4 -
Fix agno model.py mypy errors by declaring name and provider fields
f858451 -
Fix mypy type errors for Python 3.12 compatibility
- Fix LangChain chat_model.py type errors: - Add type annotations for list[BaseMessage] conversions - Fix _stream/_astream return types to use ChatGenerationChunk - Fix on_llm_error signature to match supertype - Add type: ignore comments for fallback assignments - Fix LangChain memory.py override errors: - Fix messages property override - Fix add_user_message/add_ai_message signatures - Fix tree-sitter get_parser type errors in code_handler.py and code_compressor.py31c4f19 -
Fix HeadroomAgnoModel to extend agno.models.base.Model and add real integration tests
- Fix HeadroomAgnoModel to properly extend agno.models.base.Model as a dataclass - Implement required abstract methods (invoke, ainvoke, invoke_stream, ainvoke_stream) - Add type: ignore comments for method signature overrides - Fix mypy errors in telemetry/models.py and telemetry/toin.py - Add real Ollama integration tests for both Agno and LangChain (no API keys needed) - Add ollama and langchain-ollama to dev dependencies for local testing - Update existing tests to use new HeadroomAgnoModel API67c927f
-
Add Agno agent framework integration
- HeadroomAgnoModel: Drop-in wrapper for any Agno model with automatic context optimization - HeadroomPreHook/HeadroomPostHook: Agent-level hooks for tracking optimization metrics across tool calls - Provider detection for Agno models (OpenAI, Anthropic, Google, etc.) - Full test coverage for model wrapper and hooksf1e7b62
-
Add seamless LangChain integration
- Add HeadroomChatModel wrapper with auto provider detection (OpenAI, Anthropic, Google) - Add HeadroomChatMessageHistory for automatic conversation compression - Add HeadroomDocumentCompressor for retriever integration - Add wrap_tools_with_headroom() for agent tool output compression - Add async support (ainvoke, astream) - Add LangSmith integration for observability - Restructure integrations package into nested langchain/ and mcp/ subpackages - Fix Pydantic v2 deprecation warning - Add comprehensive docs/langchain.md guide with real-world examples - Update README with LangChain quickstart and framework integrations Bump version to 0.2.3bb04104
-
Fix all mypy type errors and flaky embedding test
- Fix 34 mypy errors across 17 files with type annotations and casts - Add type: ignore comments for legitimate dynamic patterns - Handle None operands with (value or 0) pattern - Cast return values to proper types (int, float, str, bool) - Add EstimatingTokenCounter imports where needed - Use getattr() for potentially missing attributes - Fix flaky test_paraphrase_match with more distinct semantic examples - Add mlx to mypy ignore list (broken third-party stubs)3ab0a5d -
Fix all mypy type errors and flaky embedding test
- Fix 34 mypy errors across 17 files with type annotations and casts - Add type: ignore comments for legitimate dynamic patterns - Handle None operands with (value or 0) pattern - Cast return values to proper types (int, float, str, bool) - Add EstimatingTokenCounter imports where needed - Use getattr() for potentially missing attributes - Fix flaky test_paraphrase_match with more distinct semantic examples - Add mlx to mypy ignore list (broken third-party stubs)bf779b5 -
Fix all ruff lint and format errors for CI
- Fix E402: Move module-level imports to top of file - Fix F401: Add noqa for availability check imports - Fix F402: Rename loop variables shadowing imports - Fix E722: Replace bare except with except Exception - Fix B904: Add exception chaining (from e) - Fix F811: Remove duplicate imports - Fix B027: Add noqa for empty close() method - Fix E741: Rename ambiguous variable l -> label - Fix I001: Import sorting issues - Apply ruff format to all 106 files All 902 tests pass.e4a41fa
-
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