tooluniverse 0.1.4__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tooluniverse might be problematic. Click here for more details.
- tooluniverse/__init__.py +340 -4
- tooluniverse/admetai_tool.py +84 -0
- tooluniverse/agentic_tool.py +563 -0
- tooluniverse/alphafold_tool.py +96 -0
- tooluniverse/base_tool.py +129 -6
- tooluniverse/boltz_tool.py +207 -0
- tooluniverse/chem_tool.py +192 -0
- tooluniverse/compose_scripts/__init__.py +1 -0
- tooluniverse/compose_scripts/biomarker_discovery.py +293 -0
- tooluniverse/compose_scripts/comprehensive_drug_discovery.py +186 -0
- tooluniverse/compose_scripts/drug_safety_analyzer.py +89 -0
- tooluniverse/compose_scripts/literature_tool.py +34 -0
- tooluniverse/compose_scripts/output_summarizer.py +279 -0
- tooluniverse/compose_scripts/tool_description_optimizer.py +681 -0
- tooluniverse/compose_scripts/tool_discover.py +705 -0
- tooluniverse/compose_scripts/tool_graph_composer.py +448 -0
- tooluniverse/compose_tool.py +371 -0
- tooluniverse/ctg_tool.py +1002 -0
- tooluniverse/custom_tool.py +81 -0
- tooluniverse/dailymed_tool.py +108 -0
- tooluniverse/data/admetai_tools.json +155 -0
- tooluniverse/data/agentic_tools.json +1156 -0
- tooluniverse/data/alphafold_tools.json +87 -0
- tooluniverse/data/boltz_tools.json +9 -0
- tooluniverse/data/chembl_tools.json +16 -0
- tooluniverse/data/clait_tools.json +108 -0
- tooluniverse/data/clinicaltrials_gov_tools.json +326 -0
- tooluniverse/data/compose_tools.json +202 -0
- tooluniverse/data/dailymed_tools.json +70 -0
- tooluniverse/data/dataset_tools.json +646 -0
- tooluniverse/data/disease_target_score_tools.json +712 -0
- tooluniverse/data/efo_tools.json +17 -0
- tooluniverse/data/embedding_tools.json +319 -0
- tooluniverse/data/enrichr_tools.json +31 -0
- tooluniverse/data/europe_pmc_tools.json +22 -0
- tooluniverse/data/expert_feedback_tools.json +10 -0
- tooluniverse/data/fda_drug_adverse_event_tools.json +491 -0
- tooluniverse/data/fda_drug_labeling_tools.json +544 -168
- tooluniverse/data/fda_drugs_with_brand_generic_names_for_tool.py +76929 -148860
- tooluniverse/data/finder_tools.json +209 -0
- tooluniverse/data/gene_ontology_tools.json +113 -0
- tooluniverse/data/gwas_tools.json +1082 -0
- tooluniverse/data/hpa_tools.json +333 -0
- tooluniverse/data/humanbase_tools.json +47 -0
- tooluniverse/data/idmap_tools.json +74 -0
- tooluniverse/data/mcp_client_tools_example.json +113 -0
- tooluniverse/data/mcpautoloadertool_defaults.json +28 -0
- tooluniverse/data/medlineplus_tools.json +141 -0
- tooluniverse/data/monarch_tools.json +1 -1
- tooluniverse/data/openalex_tools.json +36 -0
- tooluniverse/data/opentarget_tools.json +82 -58
- tooluniverse/data/output_summarization_tools.json +101 -0
- tooluniverse/data/packages/bioinformatics_core_tools.json +1756 -0
- tooluniverse/data/packages/categorized_tools.txt +206 -0
- tooluniverse/data/packages/cheminformatics_tools.json +347 -0
- tooluniverse/data/packages/earth_sciences_tools.json +74 -0
- tooluniverse/data/packages/genomics_tools.json +776 -0
- tooluniverse/data/packages/image_processing_tools.json +38 -0
- tooluniverse/data/packages/machine_learning_tools.json +789 -0
- tooluniverse/data/packages/neuroscience_tools.json +62 -0
- tooluniverse/data/packages/original_tools.txt +0 -0
- tooluniverse/data/packages/physics_astronomy_tools.json +62 -0
- tooluniverse/data/packages/scientific_computing_tools.json +560 -0
- tooluniverse/data/packages/single_cell_tools.json +453 -0
- tooluniverse/data/packages/software_tools.json +4954 -0
- tooluniverse/data/packages/structural_biology_tools.json +396 -0
- tooluniverse/data/packages/visualization_tools.json +399 -0
- tooluniverse/data/pubchem_tools.json +215 -0
- tooluniverse/data/pubtator_tools.json +68 -0
- tooluniverse/data/rcsb_pdb_tools.json +1332 -0
- tooluniverse/data/reactome_tools.json +19 -0
- tooluniverse/data/semantic_scholar_tools.json +26 -0
- tooluniverse/data/special_tools.json +2 -25
- tooluniverse/data/tool_composition_tools.json +88 -0
- tooluniverse/data/toolfinderkeyword_defaults.json +34 -0
- tooluniverse/data/txagent_client_tools.json +9 -0
- tooluniverse/data/uniprot_tools.json +211 -0
- tooluniverse/data/url_fetch_tools.json +94 -0
- tooluniverse/data/uspto_downloader_tools.json +9 -0
- tooluniverse/data/uspto_tools.json +811 -0
- tooluniverse/data/xml_tools.json +3275 -0
- tooluniverse/dataset_tool.py +296 -0
- tooluniverse/default_config.py +165 -0
- tooluniverse/efo_tool.py +42 -0
- tooluniverse/embedding_database.py +630 -0
- tooluniverse/embedding_sync.py +396 -0
- tooluniverse/enrichr_tool.py +266 -0
- tooluniverse/europe_pmc_tool.py +52 -0
- tooluniverse/execute_function.py +1775 -95
- tooluniverse/extended_hooks.py +444 -0
- tooluniverse/gene_ontology_tool.py +194 -0
- tooluniverse/graphql_tool.py +158 -36
- tooluniverse/gwas_tool.py +358 -0
- tooluniverse/hpa_tool.py +1645 -0
- tooluniverse/humanbase_tool.py +389 -0
- tooluniverse/logging_config.py +254 -0
- tooluniverse/mcp_client_tool.py +764 -0
- tooluniverse/mcp_integration.py +413 -0
- tooluniverse/mcp_tool_registry.py +925 -0
- tooluniverse/medlineplus_tool.py +337 -0
- tooluniverse/openalex_tool.py +228 -0
- tooluniverse/openfda_adv_tool.py +283 -0
- tooluniverse/openfda_tool.py +393 -160
- tooluniverse/output_hook.py +1122 -0
- tooluniverse/package_tool.py +195 -0
- tooluniverse/pubchem_tool.py +158 -0
- tooluniverse/pubtator_tool.py +168 -0
- tooluniverse/rcsb_pdb_tool.py +38 -0
- tooluniverse/reactome_tool.py +108 -0
- tooluniverse/remote/boltz/boltz_mcp_server.py +50 -0
- tooluniverse/remote/depmap_24q2/depmap_24q2_mcp_tool.py +442 -0
- tooluniverse/remote/expert_feedback/human_expert_mcp_tools.py +2013 -0
- tooluniverse/remote/expert_feedback/simple_test.py +23 -0
- tooluniverse/remote/expert_feedback/start_web_interface.py +188 -0
- tooluniverse/remote/expert_feedback/web_only_interface.py +0 -0
- tooluniverse/remote/expert_feedback_mcp/human_expert_mcp_server.py +1611 -0
- tooluniverse/remote/expert_feedback_mcp/simple_test.py +34 -0
- tooluniverse/remote/expert_feedback_mcp/start_web_interface.py +91 -0
- tooluniverse/remote/immune_compass/compass_tool.py +327 -0
- tooluniverse/remote/pinnacle/pinnacle_tool.py +328 -0
- tooluniverse/remote/transcriptformer/transcriptformer_tool.py +586 -0
- tooluniverse/remote/uspto_downloader/uspto_downloader_mcp_server.py +61 -0
- tooluniverse/remote/uspto_downloader/uspto_downloader_tool.py +120 -0
- tooluniverse/remote_tool.py +99 -0
- tooluniverse/restful_tool.py +53 -30
- tooluniverse/scripts/generate_tool_graph.py +408 -0
- tooluniverse/scripts/visualize_tool_graph.py +829 -0
- tooluniverse/semantic_scholar_tool.py +62 -0
- tooluniverse/smcp.py +2452 -0
- tooluniverse/smcp_server.py +975 -0
- tooluniverse/test/mcp_server_test.py +0 -0
- tooluniverse/test/test_admetai_tool.py +370 -0
- tooluniverse/test/test_agentic_tool.py +129 -0
- tooluniverse/test/test_alphafold_tool.py +71 -0
- tooluniverse/test/test_chem_tool.py +37 -0
- tooluniverse/test/test_compose_lieraturereview.py +63 -0
- tooluniverse/test/test_compose_tool.py +448 -0
- tooluniverse/test/test_dailymed.py +69 -0
- tooluniverse/test/test_dataset_tool.py +200 -0
- tooluniverse/test/test_disease_target_score.py +56 -0
- tooluniverse/test/test_drugbank_filter_examples.py +179 -0
- tooluniverse/test/test_efo.py +31 -0
- tooluniverse/test/test_enrichr_tool.py +21 -0
- tooluniverse/test/test_europe_pmc_tool.py +20 -0
- tooluniverse/test/test_fda_adv.py +95 -0
- tooluniverse/test/test_fda_drug_labeling.py +91 -0
- tooluniverse/test/test_gene_ontology_tools.py +66 -0
- tooluniverse/test/test_gwas_tool.py +139 -0
- tooluniverse/test/test_hpa.py +625 -0
- tooluniverse/test/test_humanbase_tool.py +20 -0
- tooluniverse/test/test_idmap_tools.py +61 -0
- tooluniverse/test/test_mcp_server.py +211 -0
- tooluniverse/test/test_mcp_tool.py +247 -0
- tooluniverse/test/test_medlineplus.py +220 -0
- tooluniverse/test/test_openalex_tool.py +32 -0
- tooluniverse/test/test_opentargets.py +28 -0
- tooluniverse/test/test_pubchem_tool.py +116 -0
- tooluniverse/test/test_pubtator_tool.py +37 -0
- tooluniverse/test/test_rcsb_pdb_tool.py +86 -0
- tooluniverse/test/test_reactome.py +54 -0
- tooluniverse/test/test_semantic_scholar_tool.py +24 -0
- tooluniverse/test/test_software_tools.py +147 -0
- tooluniverse/test/test_tool_description_optimizer.py +49 -0
- tooluniverse/test/test_tool_finder.py +26 -0
- tooluniverse/test/test_tool_finder_llm.py +252 -0
- tooluniverse/test/test_tools_find.py +195 -0
- tooluniverse/test/test_uniprot_tools.py +74 -0
- tooluniverse/test/test_uspto_tool.py +72 -0
- tooluniverse/test/test_xml_tool.py +113 -0
- tooluniverse/tool_finder_embedding.py +267 -0
- tooluniverse/tool_finder_keyword.py +693 -0
- tooluniverse/tool_finder_llm.py +699 -0
- tooluniverse/tool_graph_web_ui.py +955 -0
- tooluniverse/tool_registry.py +416 -0
- tooluniverse/uniprot_tool.py +155 -0
- tooluniverse/url_tool.py +253 -0
- tooluniverse/uspto_tool.py +240 -0
- tooluniverse/utils.py +369 -41
- tooluniverse/xml_tool.py +369 -0
- tooluniverse-1.0.0.dist-info/METADATA +377 -0
- tooluniverse-1.0.0.dist-info/RECORD +186 -0
- {tooluniverse-0.1.4.dist-info → tooluniverse-1.0.0.dist-info}/WHEEL +1 -1
- tooluniverse-1.0.0.dist-info/entry_points.txt +9 -0
- tooluniverse-0.1.4.dist-info/METADATA +0 -141
- tooluniverse-0.1.4.dist-info/RECORD +0 -18
- {tooluniverse-0.1.4.dist-info → tooluniverse-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {tooluniverse-0.1.4.dist-info → tooluniverse-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Output Summarization Composer Script
|
|
3
|
+
|
|
4
|
+
This script handles the intelligent summarization of tool outputs by:
|
|
5
|
+
1. Chunking large outputs into manageable pieces
|
|
6
|
+
2. Processing each chunk with AI-powered summarization
|
|
7
|
+
3. Merging the summarized chunks into a coherent final summary
|
|
8
|
+
|
|
9
|
+
The script leverages ToolUniverse's AgenticTool infrastructure to provide
|
|
10
|
+
intelligent, context-aware summarization that focuses on information
|
|
11
|
+
relevant to the original query.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from typing import Dict, Any, List
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def compose(arguments: Dict[str, Any], tooluniverse, call_tool) -> Dict[str, Any]:
|
|
18
|
+
"""
|
|
19
|
+
Main composition function for output summarization.
|
|
20
|
+
|
|
21
|
+
This function orchestrates the complete summarization workflow:
|
|
22
|
+
- Chunks the input text into manageable pieces
|
|
23
|
+
- Summarizes each chunk using AI
|
|
24
|
+
- Merges the summaries into a final coherent result
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
arguments (Dict[str, Any]): Dictionary containing:
|
|
28
|
+
- tool_output (str): The original tool output to be summarized
|
|
29
|
+
- query_context (str): Context about the original query
|
|
30
|
+
- tool_name (str): Name of the tool that generated the output
|
|
31
|
+
- chunk_size (int, optional): Size of each chunk for processing
|
|
32
|
+
- focus_areas (str, optional): Areas to focus on in summarization
|
|
33
|
+
- max_summary_length (int, optional): Maximum length of final summary
|
|
34
|
+
tooluniverse: ToolUniverse instance for tool execution
|
|
35
|
+
call_tool: Function to call other tools within the composition
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Dict[str, Any]: Dictionary containing:
|
|
39
|
+
- success (bool): Whether summarization was successful
|
|
40
|
+
- original_length (int): Length of original output
|
|
41
|
+
- summary_length (int): Length of final summary
|
|
42
|
+
- chunks_processed (int): Number of chunks processed
|
|
43
|
+
- summary (str): The summarized output
|
|
44
|
+
- tool_name (str): Name of the original tool
|
|
45
|
+
- error (str, optional): Error message if summarization failed
|
|
46
|
+
"""
|
|
47
|
+
try:
|
|
48
|
+
# Extract and validate arguments
|
|
49
|
+
tool_output = arguments.get("tool_output", "")
|
|
50
|
+
query_context = arguments.get("query_context", "")
|
|
51
|
+
tool_name = arguments.get("tool_name", "")
|
|
52
|
+
chunk_size = arguments.get("chunk_size", 32000)
|
|
53
|
+
focus_areas = arguments.get("focus_areas", "key_findings_and_results")
|
|
54
|
+
max_summary_length = arguments.get("max_summary_length", 3000)
|
|
55
|
+
|
|
56
|
+
# Validate required arguments
|
|
57
|
+
if not tool_output:
|
|
58
|
+
return {
|
|
59
|
+
"success": False,
|
|
60
|
+
"error": "tool_output is required",
|
|
61
|
+
"original_output": "",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
print(f"🔍 Starting output summarization for {tool_name}")
|
|
65
|
+
print(f"📊 Original output length: {len(tool_output)} characters")
|
|
66
|
+
|
|
67
|
+
# Step 1: Chunk the output
|
|
68
|
+
chunks = _chunk_output(tool_output, chunk_size)
|
|
69
|
+
print(f"📝 Split into {len(chunks)} chunks")
|
|
70
|
+
|
|
71
|
+
# Step 2: Summarize each chunk
|
|
72
|
+
chunk_summaries = []
|
|
73
|
+
for i, chunk in enumerate(chunks):
|
|
74
|
+
print(f"🤖 Processing chunk {i+1}/{len(chunks)}")
|
|
75
|
+
summary = _summarize_chunk(
|
|
76
|
+
chunk, query_context, tool_name, focus_areas, call_tool
|
|
77
|
+
)
|
|
78
|
+
if summary:
|
|
79
|
+
chunk_summaries.append(summary)
|
|
80
|
+
print(f"✅ Chunk {i+1} summarized successfully")
|
|
81
|
+
else:
|
|
82
|
+
print(f"❌ Chunk {i+1} summarization failed")
|
|
83
|
+
|
|
84
|
+
# Step 3: Merge summaries
|
|
85
|
+
if chunk_summaries:
|
|
86
|
+
final_summary = _merge_summaries(
|
|
87
|
+
chunk_summaries, query_context, tool_name, max_summary_length, call_tool
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
final_summary = "Unable to generate summary due to processing errors."
|
|
91
|
+
print("❌ No chunk summaries were generated. This usually indicates:")
|
|
92
|
+
print(" 1. ToolOutputSummarizer tool is not available")
|
|
93
|
+
print(" 2. The output_summarization tools are not loaded")
|
|
94
|
+
print(" 3. There was an error in the summarization process")
|
|
95
|
+
print(" Please check that the SMCP server is started with hooks enabled.")
|
|
96
|
+
|
|
97
|
+
print(
|
|
98
|
+
f"✅ Summarization completed. Final length: {len(final_summary)} characters"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
"success": True,
|
|
103
|
+
"original_length": len(tool_output),
|
|
104
|
+
"summary_length": len(final_summary),
|
|
105
|
+
"chunks_processed": len(chunks),
|
|
106
|
+
"summary": final_summary,
|
|
107
|
+
"tool_name": tool_name,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
except Exception as e:
|
|
111
|
+
error_msg = f"Error in output summarization: {str(e)}"
|
|
112
|
+
print(f"❌ {error_msg}")
|
|
113
|
+
return {"success": False, "error": error_msg, "original_output": tool_output}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _chunk_output(text: str, chunk_size: int) -> List[str]:
|
|
117
|
+
"""
|
|
118
|
+
Split text into chunks of specified size with intelligent boundary detection.
|
|
119
|
+
|
|
120
|
+
This function attempts to break text at natural boundaries (sentences)
|
|
121
|
+
to maintain coherence within chunks while respecting the size limit.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
text (str): The text to be chunked
|
|
125
|
+
chunk_size (int): Maximum size of each chunk
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
List[str]: List of text chunks
|
|
129
|
+
"""
|
|
130
|
+
if len(text) <= chunk_size:
|
|
131
|
+
return [text]
|
|
132
|
+
|
|
133
|
+
chunks = []
|
|
134
|
+
start = 0
|
|
135
|
+
|
|
136
|
+
while start < len(text):
|
|
137
|
+
end = start + chunk_size
|
|
138
|
+
|
|
139
|
+
# Try to break at sentence boundary
|
|
140
|
+
if end < len(text):
|
|
141
|
+
# Look for sentence endings within the last 100 characters
|
|
142
|
+
search_start = max(start + chunk_size - 100, start)
|
|
143
|
+
for i in range(end, search_start, -1):
|
|
144
|
+
if text[i] in ".!?":
|
|
145
|
+
end = i + 1
|
|
146
|
+
break
|
|
147
|
+
|
|
148
|
+
chunk = text[start:end].strip()
|
|
149
|
+
if chunk:
|
|
150
|
+
chunks.append(chunk)
|
|
151
|
+
|
|
152
|
+
start = end
|
|
153
|
+
|
|
154
|
+
return chunks
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _summarize_chunk(
|
|
158
|
+
chunk: str, query_context: str, tool_name: str, focus_areas: str, call_tool
|
|
159
|
+
) -> str:
|
|
160
|
+
"""
|
|
161
|
+
Summarize a single chunk using the AgenticTool summarizer.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
chunk (str): The text chunk to summarize
|
|
165
|
+
query_context (str): Context about the original query
|
|
166
|
+
tool_name (str): Name of the tool that generated the output
|
|
167
|
+
focus_areas (str): Areas to focus on during summarization
|
|
168
|
+
call_tool: Function to call the summarizer tool
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
str: Summarized chunk text, or empty string if summarization fails
|
|
172
|
+
"""
|
|
173
|
+
try:
|
|
174
|
+
print(
|
|
175
|
+
f"🔍 Attempting to call ToolOutputSummarizer with chunk length: {len(chunk)}"
|
|
176
|
+
)
|
|
177
|
+
result = call_tool(
|
|
178
|
+
"ToolOutputSummarizer",
|
|
179
|
+
{
|
|
180
|
+
"tool_output": chunk,
|
|
181
|
+
"query_context": query_context,
|
|
182
|
+
"tool_name": tool_name,
|
|
183
|
+
"focus_areas": focus_areas,
|
|
184
|
+
"max_length": 500, # Shorter for individual chunks
|
|
185
|
+
},
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
print(
|
|
189
|
+
f"🔍 ToolOutputSummarizer returned: {type(result)} - {str(result)[:100]}..."
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
# Handle different result formats
|
|
193
|
+
if isinstance(result, dict) and result.get("success"):
|
|
194
|
+
return result.get("result", "")
|
|
195
|
+
elif isinstance(result, str):
|
|
196
|
+
return result
|
|
197
|
+
else:
|
|
198
|
+
print(
|
|
199
|
+
f"⚠️ ToolOutputSummarizer returned unexpected result format: {type(result)}"
|
|
200
|
+
)
|
|
201
|
+
return ""
|
|
202
|
+
|
|
203
|
+
except Exception as e:
|
|
204
|
+
error_msg = str(e)
|
|
205
|
+
print(f"⚠️ Error summarizing chunk: {error_msg}")
|
|
206
|
+
|
|
207
|
+
# Check if the error is due to missing tool
|
|
208
|
+
if "not found" in error_msg.lower() or "ToolOutputSummarizer" in error_msg:
|
|
209
|
+
print(
|
|
210
|
+
"❌ ToolOutputSummarizer tool is not available. This indicates the output_summarization tools are not loaded."
|
|
211
|
+
)
|
|
212
|
+
print(
|
|
213
|
+
" Please ensure the SMCP server is started with hooks enabled and the output_summarization category is loaded."
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
return ""
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _merge_summaries(
|
|
220
|
+
chunk_summaries: List[str],
|
|
221
|
+
query_context: str,
|
|
222
|
+
tool_name: str,
|
|
223
|
+
max_length: int,
|
|
224
|
+
call_tool,
|
|
225
|
+
) -> str:
|
|
226
|
+
"""
|
|
227
|
+
Merge chunk summaries into a final coherent summary.
|
|
228
|
+
|
|
229
|
+
If the combined summaries exceed the maximum length, they are further
|
|
230
|
+
summarized to create a concise final result.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
chunk_summaries (List[str]): List of summarized chunks
|
|
234
|
+
query_context (str): Context about the original query
|
|
235
|
+
tool_name (str): Name of the tool that generated the output
|
|
236
|
+
max_length (int): Maximum length of final summary
|
|
237
|
+
call_tool: Function to call the summarizer tool
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
str: Final merged summary
|
|
241
|
+
"""
|
|
242
|
+
if not chunk_summaries:
|
|
243
|
+
return ""
|
|
244
|
+
|
|
245
|
+
# If only one chunk, return it directly
|
|
246
|
+
if len(chunk_summaries) == 1:
|
|
247
|
+
return chunk_summaries[0]
|
|
248
|
+
|
|
249
|
+
# Combine all chunk summaries
|
|
250
|
+
combined_summaries = "\n\n".join(chunk_summaries)
|
|
251
|
+
|
|
252
|
+
# If combined length is within limit, return as is
|
|
253
|
+
if len(combined_summaries) <= max_length:
|
|
254
|
+
return combined_summaries
|
|
255
|
+
|
|
256
|
+
# Otherwise, summarize the combined summaries
|
|
257
|
+
try:
|
|
258
|
+
result = call_tool(
|
|
259
|
+
"ToolOutputSummarizer",
|
|
260
|
+
{
|
|
261
|
+
"tool_output": combined_summaries,
|
|
262
|
+
"query_context": query_context,
|
|
263
|
+
"tool_name": tool_name,
|
|
264
|
+
"focus_areas": "consolidate_and_prioritize",
|
|
265
|
+
"max_length": max_length,
|
|
266
|
+
},
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
# Handle different result formats
|
|
270
|
+
if isinstance(result, dict) and result.get("success"):
|
|
271
|
+
return result.get("result", combined_summaries)
|
|
272
|
+
elif isinstance(result, str):
|
|
273
|
+
return result
|
|
274
|
+
else:
|
|
275
|
+
return combined_summaries
|
|
276
|
+
|
|
277
|
+
except Exception as e:
|
|
278
|
+
print(f"⚠️ Error merging summaries: {str(e)}")
|
|
279
|
+
return combined_summaries
|