Class: Legion::CLI::Chat::Tools::WebSearch
- Inherits:
-
Tools::Base
- Object
- Tools::Base
- Legion::CLI::Chat::Tools::WebSearch
- Defined in:
- lib/legion/cli/chat/tools/web_search.rb
Class Method Summary collapse
Methods inherited from Tools::Base
deferred, deferred?, description, error_response, extension, handle_exception, input_schema, log, mcp_category, mcp_tier, runner, sticky, tags, text_response, tool_name, trigger_words
Class Method Details
.call(query:, max_results: 5) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/cli/chat/tools/web_search.rb', line 22 def self.call(query:, max_results: 5) require 'legion/cli/chat/web_search' results = Chat::WebSearch.search(query, max_results: max_results) output = results[:results].map do |r| "### #{r[:title]}\n#{r[:url]}\n#{r[:snippet]}" end.join("\n\n") output += "\n\n---\n\n## Top Result Content\n\n#{results[:fetched_content]}" if results[:fetched_content] output rescue Chat::WebSearch::SearchError => e Legion::Logging.warn("WebSearch#execute search error for query #{query}: #{e.}") if defined?(Legion::Logging) "Search error: #{e.}" rescue StandardError => e Legion::Logging.warn("WebSearch#execute failed for query #{query}: #{e.}") if defined?(Legion::Logging) "Error: #{e.}" end |