From b9ce323c5fae791740910ee6c9b4448bfa096b93 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Sat, 23 May 2026 10:26:42 -0700 Subject: [PATCH] [eric] deadcode: remove unused _summarize_message_block --- backend/apps/agents/agent_manager.py | 1 - backend/apps/agents/history_compaction.py | 58 ----------------------- linter/config/vulture_whitelist.py | 1 - 3 files changed, 60 deletions(-) diff --git a/backend/apps/agents/agent_manager.py b/backend/apps/agents/agent_manager.py index eb210c38..9dec92bd 100644 --- a/backend/apps/agents/agent_manager.py +++ b/backend/apps/agents/agent_manager.py @@ -52,7 +52,6 @@ from backend.apps.agents.aux_llm import _safe_resp_text from backend.apps.agents.history_compaction import ( _build_history_prefix, _get_branch_messages, - _summarize_message_block, _truncate_large_tool_result, ) from backend.apps.agents.prompt_context import ( diff --git a/backend/apps/agents/history_compaction.py b/backend/apps/agents/history_compaction.py index aaa30a25..2757758b 100644 --- a/backend/apps/agents/history_compaction.py +++ b/backend/apps/agents/history_compaction.py @@ -62,64 +62,6 @@ def _build_history_prefix(messages) -> str: return "\n" + "\n".join(lines) + "\n" -def _summarize_message_block(messages: list) -> str: - """Programmatic, no-LLM summary of a message slice. Mirrors the - shape of browser_agent._summarize_messages: extracts the original - user task, counts tool calls, captures the last assistant text. - Cheap, deterministic, and never makes a network call, so - compaction itself adds zero latency to the user's turn. - """ - if not messages: - return "" - - initial_task = "" - for m in messages: - if getattr(m, "role", "") == "user": - content = getattr(m, "content", "") - txt = content if isinstance(content, str) else str(content) - if txt.strip(): - initial_task = txt.strip()[:400] - break - - tool_calls_by_name: dict[str, int] = {} - last_tool_results = 0 - last_assistant_text = "" - for m in messages: - role = getattr(m, "role", "") - if role == "tool_call": - content = getattr(m, "content", {}) or {} - name = (content.get("tool") if isinstance(content, dict) else None) or "unknown" - tool_calls_by_name[name] = tool_calls_by_name.get(name, 0) + 1 - elif role == "tool_result": - last_tool_results += 1 - elif role == "assistant": - content = getattr(m, "content", "") - if isinstance(content, str) and content.strip(): - last_assistant_text = content.strip() - elif isinstance(content, list): - for block in content: - if isinstance(block, dict) and block.get("type") == "text": - txt = (block.get("text") or "").strip() - if txt: - last_assistant_text = txt - - parts = [""] - parts.append("[The following is a programmatic summary of earlier turns in this session. Originals are preserved on disk and viewable via the chat UI's compaction drawer.]") - if initial_task: - parts.append(f'Initial user request: "{initial_task}"') - if tool_calls_by_name: - total = sum(tool_calls_by_name.values()) - top = sorted(tool_calls_by_name.items(), key=lambda kv: -kv[1])[:8] - parts.append(f"Tool calls so far ({total} total): " + ", ".join(f"{n}×{c}" for n, c in top)) - if last_tool_results: - parts.append(f"Tool results received: {last_tool_results}") - if last_assistant_text: - parts.append("Last assistant message:") - parts.append(last_assistant_text[:1200]) - parts.append("") - return "\n".join(parts) - - def _truncate_large_tool_result(content: object, session_id: str, msg_id: str, max_bytes: int = 50_000) -> tuple[object, str | None]: """Spill a large tool_result body to disk, return a truncated inline replacement plus the on-disk path (or None if untouched). diff --git a/linter/config/vulture_whitelist.py b/linter/config/vulture_whitelist.py index e73921b3..1c176406 100644 --- a/linter/config/vulture_whitelist.py +++ b/linter/config/vulture_whitelist.py @@ -48,7 +48,6 @@ requests_delta # This task is tooling-only and must not edit backend source, so these stay # whitelisted rather than deleted. They have zero call sites today; a future # non-additive cleanup pass should remove the definitions and these lines. -_summarize_message_block thinking_params_for _resolve_model load_output