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(proxy): keep tool deferral for GitHub Copilot upstream (#4356)
divyamnpll217b65884538
diff --git a/headroom/proxy/helpers.py b/headroom/proxy/helpers.pyindex f13eca886..735a702c9 100644--- a/headroom/proxy/helpers.py+++ b/headroom/proxy/helpers.py@@ -4107,9 +4107,21 @@ def _warn_deferred_without_search_tool(tools: Any) -> None:)+#: Non-Anthropic upstreams that accept the first-party deferred tool shape.+#: These bill deferred schemas compactly, so downgrading deferral for them+#: inlines the whole catalog and multiplies billed prompt tokens.+_DEFERRAL_CAPABLE_HOSTS: frozenset[str] = frozenset({"api.githubcopilot.com"})++def anthropic_first_party_tool_search_supported(api_base_url: str | None) -> bool:"""Return whether Anthropic server-side tool search is valid for this upstream."""- from headroom.providers.claude.runtime import is_custom_anthropic_base_url+ from headroom.providers.claude.runtime import (+ _gate_view_host,+ is_custom_anthropic_base_url,+ )++ if _gate_view_host((api_base_url or "").strip()) in _DEFERRAL_CAPABLE_HOSTS:+ return Truereturn not is_custom_anthropic_base_url(api_base_url)diff --git a/tests/test_tool_search_client_deferral.py b/tests/test_tool_search_client_deferral.pyindex 80b048cd3..ba3cfcc60 100644--- a/tests/test_tool_search_client_deferral.py+++ b/tests/test_tool_search_client_deferral.py@@ -38,6 +38,7 @@ import pytestfrom headroom.proxy.helpers import (_TOOL_SEARCH_MIN_TOOLS,+ anthropic_first_party_tool_search_supported,claude_code_tool_search_inactive,inject_tool_search_deferral,inject_tool_search_deferral_openai,@@ -410,6 +411,29 @@ def test_nothing_to_strip_returns_the_same_list() -> None:assert out is tools+def test_github_copilot_upstream_keeps_deferral() -> None:+ """Copilot accepts the deferred shape and bills deferred schemas compactly."""+ tools = [ANTHROPIC_SEARCH_REGEX, {"name": "mcp__srv__a", "defer_loading": True}]++ out = strip_first_party_tool_search_tools_for_third_party_upstream(+ tools, "https://api.githubcopilot.com"+ )++ assert out is tools+ assert anthropic_first_party_tool_search_supported("https://api.githubcopilot.com")+++def test_copilot_host_match_is_exact() -> None:+ """A lookalike host must not inherit the exemption."""+ assert not anthropic_first_party_tool_search_supported("https://api.githubcopilot.com.evil.com")+++def test_other_third_party_upstreams_still_downgrade() -> None:+ """The exemption is host-scoped: Bedrock/Vertex/gateways are unchanged."""+ for url in (THIRD_PARTY_URL, "https://bedrock-runtime.us-east-1.amazonaws.com"):+ assert not anthropic_first_party_tool_search_supported(url)++# --------------------------------------------------------------------------# OpenAI Responses path# --------------------------------------------------------------------------