Class: RCrewAI::Tools::WebSearch

Inherits:
Base
  • Object
show all
Defined in:
lib/rcrewai/tools/web_search.rb

Constant Summary

Constants included from RCrewAI::ToolSchema

RCrewAI::ToolSchema::TYPE_MAP

Instance Method Summary collapse

Methods inherited from Base

available_tools, create_tool, #description, #execute_with_validation, #json_schema, list_available_tools, #name, #validate_params!

Methods included from RCrewAI::ToolSchema

#description, extended, #json_schema, #param, #params, #tool_name

Constructor Details

#initialize(**options) ⇒ WebSearch

Returns a new instance of WebSearch.



18
19
20
21
22
# File 'lib/rcrewai/tools/web_search.rb', line 18

def initialize(**options)
  super()
  @max_results = options.fetch(:max_results, 5)
  @timeout = options.fetch(:timeout, 30)
end

Instance Method Details

#execute(**params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rcrewai/tools/web_search.rb', line 24

def execute(**params)
  validate_params!(params, required: [:query], optional: [:max_results])

  query = params[:query]
  max_results = params[:max_results] || @max_results

  begin
    search_results = perform_search(query, max_results)
    format_results(search_results)
  rescue StandardError => e
    "Search failed: #{e.message}"
  end
end