From 73f24011f21b51c2a6cb1e792a7234cf7c9ff0c6 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Sat, 20 Dec 2025 22:20:23 +0700 Subject: [PATCH] More token efficient jetbrains overview tool The grouping by type and the removing of the per-symbol-repeated name_path leads to a huge reduction in output size while the same information is retained! From {"symbols": [{"name_path": "collections", "type": "Py:IMPORT_ELEMENT"}, ... To {"symbols": {"Py:IMPORT_ELEMENT": ["collections", ... --- src/serena/tools/jetbrains_tools.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/serena/tools/jetbrains_tools.py b/src/serena/tools/jetbrains_tools.py index e103854b..0c9f644e 100644 --- a/src/serena/tools/jetbrains_tools.py +++ b/src/serena/tools/jetbrains_tools.py @@ -1,3 +1,5 @@ +from collections import defaultdict + from serena.tools import Tool, ToolMarkerOptional, ToolMarkerSymbolicRead from serena.tools.jetbrains_plugin_client import JetBrainsPluginClient @@ -117,5 +119,15 @@ class JetBrainsGetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOp response_dict = client.get_symbols_overview( relative_path=relative_path, ) - result = self._to_json(response_dict) + symbols = response_dict["symbols"] + # symbols come with name_path and type, we group them by type for token efficiency + grouped_symbols = defaultdict(list) + for symbol in symbols: + type = symbol.pop("type", "unknown") + if len(symbol) == 1: + # we only have the name_path key, no need to repeat it in each entry + symbol = symbol["name_path"] + grouped_symbols[type].append(symbol) + response_dict["symbols"] = grouped_symbols + result = self._to_json(response_dict) return self._limit_length(result, max_answer_chars)