Class: RSmolagent::Tools::WebSearchTool
- Inherits:
-
RSmolagent::Tool
- Object
- RSmolagent::Tool
- RSmolagent::Tools::WebSearchTool
- Defined in:
- lib/rsmolagent/tools/web_search.rb
Instance Attribute Summary
Attributes inherited from RSmolagent::Tool
#description, #input_schema, #name
Instance Method Summary collapse
- #execute(args) ⇒ Object
-
#initialize(max_results: 5) ⇒ WebSearchTool
constructor
A new instance of WebSearchTool.
Methods inherited from RSmolagent::Tool
Constructor Details
#initialize(max_results: 5) ⇒ WebSearchTool
Returns a new instance of WebSearchTool.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rsmolagent/tools/web_search.rb', line 9 def initialize(max_results: 5) super( name: "web_search", description: "Performs a web search based on your query (like a Google search) and returns the top search results", input_schema: { query: { type: "string", description: "The search query to perform" } } ) @max_results = max_results end |
Instance Method Details
#execute(args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rsmolagent/tools/web_search.rb', line 23 def execute(args) query = args[:query] # Ensure query isn't empty return "Error: Search query cannot be empty" if query.nil? || query.strip.empty? begin results = search_duckduckgo(query) if results.nil? || results.empty? return "No results found for query: '#{query}'. Try a less restrictive/shorter query." end # Format the results as markdown formatted_results = format_results(results) return "## Search Results\n\n#{formatted_results}" rescue => e return "Error performing search: #{e.}" end end |