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

Method do

AskAgent/python/core/router.py:392–553  ·  view source on GitHub ↗

Main method that evaluates tools and stores results.

(self)

Source from the content-addressed store, hash-verified

390 }]
391
392 async def do(self):
393 """Main method that evaluates tools and stores results."""
394 try:
395 # Check if tool selection is enabled in config
396 if not CONFIG.is_tool_selection_enabled():
397 logger.info("Tool selection is disabled in config, skipping")
398 await self.handler.state.precheck_step_done(self.STEP_NAME)
399 return
400
401 # Check if site is "all" and aggregation is disabled - default to search
402 if (self.handler.site == "all" and not CONFIG.is_aggregation_enabled()):
403 logger.info("Site is 'all' and aggregation is disabled, defaulting to search tool")
404 # Find the search tool
405 tools = self.get_tools_by_type("Item") # Search is typically an Item-level tool
406 search_tool = next((t for t in tools if t.name == 'search'), None)
407
408 if search_tool:
409 # Create a default search result
410 query = self.handler.decontextualized_query or self.handler.query
411 self.handler.tool_routing_results = [{
412 "tool": search_tool,
413 "score": 100,
414 "result": {
415 "score": 100,
416 "justification": "Default to search for site='all' with aggregation disabled",
417 "search_query": query
418 }
419 }]
420
421 # Send debug message if in debug mode
422 if getattr(self.handler, 'debug_mode', False):
423 elapsed_time = time.time() - self.handler.init_time
424 await self.handler.send_message({
425 "message_type": "tool_selection",
426 "selected_tool": "search",
427 "score": 100,
428 "parameters": {"score": 100, "justification": "Site='all' with aggregation disabled"},
429 "query": query,
430 "time_elapsed": f"{elapsed_time:.3f}s",
431 "llm_skipped": True
432 })
433 else:
434 logger.warning("Search tool not found, continuing with normal tool selection")
435
436 await self.handler.state.precheck_step_done(self.STEP_NAME)
437 return
438
439 # Skip tool selection if generate_mode is summarize or generate
440 generate_mode = getattr(self.handler, 'generate_mode', 'none')
441 if generate_mode in ['summarize', 'generate']:
442 logger.info(f"Skipping tool selection because generate_mode is '{generate_mode}'")
443 await self.handler.state.precheck_step_done(self.STEP_NAME)
444 return
445
446 # Wait for decontextualization
447 await self.handler.state.wait_for_decontextualization()
448
449 # Get query and schema type

Callers

nothing calls this directly

Calls 12

get_tools_by_typeMethod · 0.95
precheck_step_doneMethod · 0.80
setMethod · 0.80
infoMethod · 0.45
send_messageMethod · 0.45
warningMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected