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
refactor(parser): deprecate find_tool_units and get_message_content_text (#4108)
Tejas Chopra4bf4ae870d35
diff --git a/headroom/parser.py b/headroom/parser.pyindex 36bd99211..7a33ef812 100644--- a/headroom/parser.py+++ b/headroom/parser.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport hashlibimport jsonimport re+import warningsfrom typing import TYPE_CHECKING, Anyfrom .config import Block, WasteSignals@@ -539,7 +540,16 @@ def find_tool_units(messages: list[dict[str, Any]]) -> list[tuple[int, list[int]Returns:List of (assistant_index, [tool_response_indices]) tuples.++ .. deprecated::+ Nothing in Headroom uses it since the rolling-window stage was+ retired. It has no replacement."""+ warnings.warn(+ "find_tool_units is deprecated and will be removed in a future release; it has no replacement.",+ DeprecationWarning,+ stacklevel=2,+ )units: list[tuple[int, list[int]]] = []# Build map of tool_call_id -> message index for tool responses@@ -608,7 +618,16 @@ def find_tool_units(messages: list[dict[str, Any]]) -> list[tuple[int, list[int]def get_message_content_text(message: dict[str, Any]) -> str:- """Extract text content from a message."""+ """Extract text content from a message.++ .. deprecated::+ Nothing in Headroom uses it. It has no replacement.+ """+ warnings.warn(+ "get_message_content_text is deprecated and will be removed in a future release; it has no replacement.",+ DeprecationWarning,+ stacklevel=2,+ )content = message.get("content")if content is None:return ""diff --git a/tests/test_parser.py b/tests/test_parser.pyindex 9deed38d7..10fa76736 100644--- a/tests/test_parser.py+++ b/tests/test_parser.py@@ -489,6 +489,7 @@ class TestStreamingToolCallObjects:assert tool_call_blocks[0].flags.get("function_name") == "dummy_tool"assert "dummy_tool" in tool_call_blocks[0].text+ @pytest.mark.filterwarnings("ignore:find_tool_units is deprecated:DeprecationWarning")def test_find_tool_units_with_sdk_tool_call(self):"""The second `.get()` site: find_tool_units must still pair anSDK-object tool_call with its tool response message."""@@ -675,6 +676,7 @@ class TestRereadDetection:# --- TestFindToolUnits ---[email protected]("ignore:find_tool_units is deprecated:DeprecationWarning")class TestFindToolUnits:"""Tests for find_tool_units function."""@@ -864,6 +866,7 @@ class TestFindToolUnits:# --- TestGetMessageContentText ---[email protected]("ignore:get_message_content_text is deprecated:DeprecationWarning")class TestGetMessageContentText:"""Tests for get_message_content_text function."""@@ -931,6 +934,16 @@ class TestGetMessageContentText:assert text == ""+def test_find_tool_units_is_deprecated() -> None:+ with pytest.warns(DeprecationWarning, match="find_tool_units is deprecated"):+ assert find_tool_units([]) == []+++def test_get_message_content_text_is_deprecated() -> None:+ with pytest.warns(DeprecationWarning, match="get_message_content_text is deprecated"):+ assert get_message_content_text({"content": "hi"}) == "hi"++# --- Additional fixtures for complex tests ---