Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix: wire HEADROOM_EXCLUDE_TOOLS / HEADROOM_TOOL_PROFILES into Click proxy entrypoint (#943)
Matt Van Horn9b7b436b0411
diff --git a/headroom/cli/proxy.py b/headroom/cli/proxy.pyindex 1c126997e..2221e184a 100644--- a/headroom/cli/proxy.py+++ b/headroom/cli/proxy.py@@ -672,7 +672,12 @@ def proxy("""# Import here to avoid slow startuptry:- from headroom.proxy.server import ProxyConfig, run_server+ from headroom.proxy.server import (+ ProxyConfig,+ _parse_exclude_tools,+ _parse_tool_profiles,+ run_server,+ )except ImportError as e:click.secho("Error: Proxy dependencies not installed. Run: pip install headroom-ai[proxy]",@@ -786,6 +791,8 @@ def proxy(compress_user_messages=_get_env_bool("HEADROOM_COMPRESS_USER_MESSAGES", False),min_tokens_to_crush=_get_env_int_optional("HEADROOM_MIN_TOKENS") or 500,max_items_after_crush=_get_env_int_optional("HEADROOM_MAX_ITEMS") or 50,+ exclude_tools=_parse_exclude_tools(None) or None,+ tool_profiles=_parse_tool_profiles([]) or None,smart_crusher_with_compaction=_get_env_bool_optional("HEADROOM_SMART_CRUSHER_COMPACTION"),savings_profile=os.environ.get("HEADROOM_SAVINGS_PROFILE") or None,target_ratio=_get_env_float_optional("HEADROOM_TARGET_RATIO"),diff --git a/tests/test_cli_proxy_env.py b/tests/test_cli_proxy_env.pyindex 6556f311c..12781dfb1 100644--- a/tests/test_cli_proxy_env.py+++ b/tests/test_cli_proxy_env.py@@ -785,3 +785,120 @@ class TestArgparseBackendValidation:config = _proxy_config_from_env()assert config.disable_kompress is True+++class TestCLIProxyExcludeToolsEnvVar:+ """HEADROOM_EXCLUDE_TOOLS and HEADROOM_TOOL_PROFILES must reach ProxyConfig via the Click path.++ Regression coverage for issue #825: the Click entrypoint (headroom/cli/proxy.py)+ previously built ProxyConfig without calling _parse_exclude_tools or+ _parse_tool_profiles, so those env vars were silently ignored for all+ shared/deployed services that launch via `headroom proxy`.+ """++ def test_exclude_tools_single_name_from_env(self, runner):+ """HEADROOM_EXCLUDE_TOOLS=WebSearch propagates to ProxyConfig.exclude_tools."""+ captured_config = {}++ def mock_run_server(config, **kwargs):+ captured_config["config"] = config++ with patch("headroom.proxy.server.run_server", mock_run_server):+ result = runner.invoke(+ main,+ ["proxy"],+ env={"HEADROOM_EXCLUDE_TOOLS": "WebSearch"},+ catch_exceptions=False,+ )++ assert result.exit_code == 0, result.output+ cfg = captured_config["config"]+ assert cfg.exclude_tools is not None+ assert "WebSearch" in cfg.exclude_tools++ def test_exclude_tools_multi_name_from_env(self, runner):+ """HEADROOM_EXCLUDE_TOOLS=WebSearch,WebFetch yields both names (and lowercased) in result."""+ captured_config = {}++ def mock_run_server(config, **kwargs):+ captured_config["config"] = config++ with patch("headroom.proxy.server.run_server", mock_run_server):+ result = runner.invoke(+ main,+ ["proxy"],+ env={"HEADROOM_EXCLUDE_TOOLS": "WebSearch,WebFetch"},+ catch_exceptions=False,+ )++ assert result.exit_code == 0, result.output+ cfg = captured_config["config"]+ assert cfg.exclude_tools is not None+ assert "WebSearch" in cfg.exclude_tools+ assert "WebFetch" in cfg.exclude_tools+ assert "websearch" in cfg.exclude_tools+ assert "webfetch" in cfg.exclude_tools++ def test_exclude_tools_unset_leaves_none(self, runner):+ """Without HEADROOM_EXCLUDE_TOOLS, exclude_tools stays None (DEFAULT_EXCLUDE_TOOLS used)."""+ captured_config = {}++ def mock_run_server(config, **kwargs):+ captured_config["config"] = config++ env = {k: v for k, v in os.environ.items() if k != "HEADROOM_EXCLUDE_TOOLS"}++ with (+ patch("headroom.proxy.server.run_server", mock_run_server),+ patch.dict(os.environ, env, clear=True),+ ):+ result = runner.invoke(+ main,+ ["proxy"],+ catch_exceptions=False,+ )++ assert result.exit_code == 0, result.output+ assert captured_config["config"].exclude_tools is None++ def test_tool_profiles_from_env(self, runner):+ """HEADROOM_TOOL_PROFILES=Grep:conservative propagates to ProxyConfig.tool_profiles."""+ captured_config = {}++ def mock_run_server(config, **kwargs):+ captured_config["config"] = config++ with patch("headroom.proxy.server.run_server", mock_run_server):+ result = runner.invoke(+ main,+ ["proxy"],+ env={"HEADROOM_TOOL_PROFILES": "Grep:conservative"},+ catch_exceptions=False,+ )++ assert result.exit_code == 0, result.output+ cfg = captured_config["config"]+ assert cfg.tool_profiles is not None+ assert "Grep" in cfg.tool_profiles++ def test_tool_profiles_unset_leaves_none(self, runner):+ """Without HEADROOM_TOOL_PROFILES, tool_profiles stays None."""+ captured_config = {}++ def mock_run_server(config, **kwargs):+ captured_config["config"] = config++ env = {k: v for k, v in os.environ.items() if k != "HEADROOM_TOOL_PROFILES"}++ with (+ patch("headroom.proxy.server.run_server", mock_run_server),+ patch.dict(os.environ, env, clear=True),+ ):+ result = runner.invoke(+ main,+ ["proxy"],+ catch_exceptions=False,+ )++ assert result.exit_code == 0, result.output+ assert captured_config["config"].tool_profiles is None