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
ci: bump astral-sh/setup-uv from 10.3.2 to 10.3.3 in the actions-minor-patch group (#4659)
dependabot[bot]8364ebbfab01
diff --git a/.github/workflows/security.yml b/.github/workflows/security.ymlindex a95b8a51c..6aa807654 100644--- a/.github/workflows/security.yml+++ b/.github/workflows/security.yml@@ -41,7 +41,7 @@ jobs:python-version: "3.12"- name: Install uv- uses: astral-sh/[email protected]+ uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3- name: Export production dependency set from uv.lockrun: |@@ -97,7 +97,7 @@ jobs:- name: Install uvif: steps.gate.outputs.run == 'true'- uses: astral-sh/[email protected]+ uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3- name: Resolve what pip installs from the package metadataif: steps.gate.outputs.run == 'true'diff --git a/tests/test_gemini_memory_tail_preserved.py b/tests/test_gemini_memory_tail_preserved.pyindex 8ef0b891c..8100eb4e0 100644--- a/tests/test_gemini_memory_tail_preserved.py+++ b/tests/test_gemini_memory_tail_preserved.py@@ -17,6 +17,7 @@ from types import SimpleNamespacefrom typing import Anyimport pytest+from fastapi import Requestfrom headroom.proxy.handlers.gemini import GeminiHandlerMixinfrom headroom.proxy.memory_handler import MemoryHandler@@ -24,13 +25,32 @@ from headroom.proxy.memory_handler import MemoryHandlerMEMORY_BLOCK = "<memory>user prefers metric units</memory>"-class _FakeRequest:- def __init__(self) -> None:- self.headers: dict[str, str] = {"x-headroom-user-id": "alice"}- self.query_params: dict[str, str] = {}- self.url = SimpleNamespace(path="/v1beta/models/gemini-pro:generateContent", query="")- self.scope: dict = {"type": "http", "method": "POST"}- self.client = SimpleNamespace(host="127.0.0.1", port=50000)+def _request(body: dict) -> Request:+ payload = json.dumps(body).encode("utf-8")+ split = len(payload) // 2+ messages = iter(+ [+ {"type": "http.request", "body": payload[:split], "more_body": True},+ {"type": "http.request", "body": payload[split:], "more_body": False},+ ]+ )++ async def receive() -> dict:+ return next(messages, {"type": "http.disconnect"})++ return Request(+ {+ "type": "http",+ "method": "POST",+ "scheme": "http",+ "path": "/v1beta/models/gemini-pro:generateContent",+ "query_string": b"",+ "headers": [(b"x-headroom-user-id", b"alice"), (b"content-type", b"application/json")],+ "client": ("127.0.0.1", 50000),+ "server": ("127.0.0.1", 8787),+ },+ receive,+ )class _UpstreamResponse:@@ -101,14 +121,10 @@ class _Handler(GeminiHandlerMixin):async def _send(monkeypatch: pytest.MonkeyPatch, body: dict) -> dict:- async def payload(request): # noqa: ANN001, ANN202- return body-- monkeypatch.setattr("headroom.proxy.helpers._read_request_json", payload)monkeypatch.setenv("HEADROOM_MEMORY_INJECTION_MODE", "live_zone_tail")handler = _Handler()- response = await handler.handle_gemini_generate_content(_FakeRequest(), "gemini-pro")+ response = await handler.handle_gemini_generate_content(_request(body), "gemini-pro")assert response.status_code == 200(forwarded,) = handler.forwardedreturn forwarded