Class: Zephira::Tools::WebSearch
- Defined in:
- lib/zephira/tools/web_search.rb
Instance Attribute Summary
Attributes inherited from BaseTool
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from BaseTool
announces_intent?, #arg, #error_result, #initialize, run, #success_result, #validate
Constructor Details
This class inherits a constructor from Zephira::Tools::BaseTool
Class Method Details
.description ⇒ Object
15 16 17 |
# File 'lib/zephira/tools/web_search.rb', line 15 def description "Performs a web search using the Brave Search API." end |
.name ⇒ Object
11 12 13 |
# File 'lib/zephira/tools/web_search.rb', line 11 def name "web_search" end |
.parameters ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zephira/tools/web_search.rb', line 23 def parameters { type: "object", properties: { intent: { type: "string", description: "Brief summary of intent of the operation, meant to be used for context compaction and presentation to the user. Use active voice (e.g., 'Reading X to do Y')." }, queries: { type: "array", description: "An array of search query instructions", items: { type: "object", properties: { query: { type: "string", description: "The string to search for" }, num_results: { type: "integer", description: "Maximum number of results to return (1-50)", minimum: 1, maximum: 50 } }, required: ["query", "num_results"], additionalProperties: false } } }, required: ["intent", "queries"] } end |
.read_only? ⇒ Boolean
19 20 21 |
# File 'lib/zephira/tools/web_search.rb', line 19 def read_only? true end |
Instance Method Details
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zephira/tools/web_search.rb', line 58 def run queries = validate(arg(:queries), arg_path: "queries", type: Array, allow_empty: false) api_key = Config.read("ZEPHIRA_BRAVE_SEARCH_API_KEY").to_s if api_key.strip.empty? return error_result(message: "ZEPHIRA_BRAVE_SEARCH_API_KEY not set (env var or .zephira.yml)") end results = queries.map { |query| run_query(query, api_key) } success_result(results) end |