MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / _send_tool_selection_message

Method _send_tool_selection_message

AskAgent/python/core/router.py:340–390  ·  view source on GitHub ↗

Send tool selection messages in debug mode.

(self, tool_results, query, tools)

Source from the content-addressed store, hash-verified

338 return type_tools
339
340 async def _send_tool_selection_message(self, tool_results, query, tools):
341 """Send tool selection messages in debug mode."""
342 if not getattr(self.handler, 'debug_mode', False):
343 # Not in debug mode, but still need to handle no tools case
344 if not tool_results:
345 logger.info(f"No tools selected (all below threshold {self.MIN_TOOL_SCORE_THRESHOLD}), defaulting to search")
346 # Create a dummy search tool result for the handler
347 search_tool = next((t for t in tools if t.name == 'search'), None)
348 if search_tool:
349 self.handler.tool_routing_results = [{
350 "tool": search_tool,
351 "score": 0,
352 "result": {"score": 0, "justification": "Default fallback"}
353 }]
354 return
355
356 # In debug mode - send messages
357 if tool_results:
358 selected_tool = tool_results[0]
359 elapsed_time = time.time() - self.handler.init_time
360 logger.info(f"Tool selection complete: {selected_tool['tool'].name} (score: {selected_tool['score']:.2f})")
361 message = {
362 "message_type": "tool_selection",
363 "selected_tool": selected_tool['tool'].name,
364 "score": selected_tool['score'],
365 "parameters": selected_tool['result'],
366 "query": query,
367 "time_elapsed": f"{elapsed_time:.3f}s"
368 }
369 asyncio.create_task(self.handler.send_message(message))
370 else:
371 # No tools selected - default to search
372 logger.info(f"No tools selected (all below threshold {self.MIN_TOOL_SCORE_THRESHOLD}), defaulting to search")
373 elapsed_time = time.time() - self.handler.init_time
374 message = {
375 "message_type": "tool_selection",
376 "selected_tool": "search",
377 "score": 0,
378 "parameters": {"score": 0, "justification": "Default fallback - no tools met threshold"},
379 "query": query,
380 "time_elapsed": f"{elapsed_time:.3f}s"
381 }
382 asyncio.create_task(self.handler.send_message(message))
383 # Create a dummy search tool result for the handler
384 search_tool = next((t for t in tools if t.name == 'search'), None)
385 if search_tool:
386 self.handler.tool_routing_results = [{
387 "tool": search_tool,
388 "score": 0,
389 "result": {"score": 0, "justification": "Default fallback"}
390 }]
391
392 async def do(self):
393 """Main method that evaluates tools and stores results."""

Callers 1

doMethod · 0.95

Calls 2

infoMethod · 0.45
send_messageMethod · 0.45

Tested by

no test coverage detected