From e6cba84cd1fbf4deb4a4500020cb7605fc5aead8 Mon Sep 17 00:00:00 2001 From: banxian1987 Date: Wed, 26 Aug 2026 23:32:30 +0800 Subject: [PATCH] revert(router): preserve 100% untouched strix message payloads --- strix_hub/model_router.py | 42 +-------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/strix_hub/model_router.py b/strix_hub/model_router.py index 05865e2c..1ed450ff 100644 --- a/strix_hub/model_router.py +++ b/strix_hub/model_router.py @@ -176,11 +176,9 @@ def _create_router_handler(router_instance: ModelRouterServer) -> type[BaseHTTPR target_key = cfg["subagent_api_key"] role_label = "Subagent (执行打手)" - # 2. Rewrite model in payload and prune bloated historical context + # 2. Rewrite model in payload (preserving raw messages and reasoning context 100% intact) if isinstance(payload, dict): payload["model"] = target_model - if "messages" in payload and isinstance(payload["messages"], list): - payload["messages"] = _prune_messages_for_local_model(payload["messages"]) forward_body = json.dumps(payload, ensure_ascii=False).encode("utf-8") else: forward_body = raw_body @@ -317,41 +315,3 @@ def _parse_qwen_tool_calls(content: str) -> list[dict[str, Any]]: pass return tool_calls - - -def _prune_messages_for_local_model( - messages: list[dict[str, Any]], max_tool_output_chars: int = 1500 -) -> list[dict[str, Any]]: - """Prune bloated older tool outputs to prevent context explosion on local models.""" - if not isinstance(messages, list) or len(messages) <= 6: - return messages - - pruned: list[dict[str, Any]] = [] - # Keep the first 2 messages (system prompt + user task description) untouched - # Keep the latest 4 messages (recent turns) untouched - # For intermediate messages, trim excessively long tool outputs (nmap logs, HTML blobs) - cutoff = len(messages) - 4 - for idx, msg in enumerate(messages): - if idx <= 1 or idx >= cutoff: - pruned.append(msg) - continue - - if not isinstance(msg, dict): - pruned.append(msg) - continue - - role = msg.get("role") - content = msg.get("content") - - if role == "tool" and isinstance(content, str) and len(content) > max_tool_output_chars: - trimmed = ( - content[:max_tool_output_chars] - + f"\n\n[... Strix Hub: Output trimmed to {max_tool_output_chars} chars to accelerate local inference ...]" - ) - new_msg = dict(msg) - new_msg["content"] = trimmed - pruned.append(new_msg) - else: - pruned.append(msg) - - return pruned