Class: Rixie::Tool
- Inherits:
-
Object
- Object
- Rixie::Tool
- Defined in:
- lib/rixie/tool.rb,
lib/rixie/tool/fetch.rb,
lib/rixie/tool/file_list.rb,
lib/rixie/tool/file_read.rb,
lib/rixie/tool/calculator.rb,
lib/rixie/tool/web_search.rb,
lib/rixie/tool/file_search.rb,
lib/rixie/tool/human_input.rb,
lib/rixie/tool/current_time.rb,
lib/rixie/tool/file_sandbox.rb,
lib/rixie/tool/wikipedia_search.rb
Defined Under Namespace
Modules: FileSandbox
Constant Summary collapse
- Fetch =
Tool.new( name: "fetch", description: "Fetch the content of a URL and return the readable text. Useful for reading web pages found via web_search.", input_schema: { type: "object", properties: { url: { type: "string", description: "The URL to fetch" } }, required: ["url"] }, call: ->(args) { begin require "nokogiri" rescue LoadError raise Rixie::ConfigurationError, "nokogiri gem is required for Tool::Fetch. Add `gem 'nokogiri'` to your Gemfile." end url = args["url"] || args[:url] response = Rixie::Http::Client.new.get(url) content_type = response[:headers]["content-type"]&.first.to_s next response[:body] unless content_type.include?("text/html") doc = Nokogiri::HTML(response[:body].to_s) doc.css("nav, script, style, footer, header, aside, img, link, figure, blockquote, button, noscript, iframe").remove doc.css("pre").each { |pre| pre.replace("[code block omitted]") } doc.css("body").text .gsub(/[^\S\n]+/, " ") .gsub(/^ +| +$/, "") .gsub(/\n{3,}/, "\n\n") .strip } )
- FileList =
build.call
- FileRead =
build.call
- Calculator =
Tool.new( name: "calculator", description: "Evaluate an arithmetic expression and return the result. " \ "Supports + - * / % and ^ (or **) for exponentiation, plus parentheses. " \ "Use this for any non-trivial arithmetic — LLMs are unreliable at calculation.", input_schema: { type: "object", properties: { expression: { type: "string", description: "An arithmetic expression, e.g. '(2 + 3) * 4 ^ 2'" } }, required: ["expression"] }, call: ->(args) { begin expr = args["expression"] || args[:expression] result = CalculatorParser.evaluate(expr) result.to_s rescue CalculatorParser::Error => e "Error: #{e.}" end } )
- WebSearch =
build.call
- FileSearch =
build.call
- HumanInput =
Tool.new( name: "human_input", description: "Call this tool when you need input, clarification, or approval from " \ "the user before proceeding. The user will see your question and reply " \ "in the next message.", input_schema: { type: "object", properties: { question: { type: "string", description: "The question or prompt to present to the user" } }, required: ["question"] }, call: ->(args) { args["question"] }, return_direct: true )
- CurrentTime =
Tool.new( name: "current_time", description: "Get the current date and time as an ISO 8601 string. " \ "LLMs do not know the current time on their own — call this " \ "when the user asks about \"now\", \"today\", relative dates, " \ "or anything time-sensitive.", input_schema: { type: "object", properties: { timezone: { type: "string", description: "Either 'local' (system local time) or 'utc'. Defaults to 'local'.", enum: ["local", "utc"] } } }, call: ->(args) { tz = (args["timezone"] || args[:timezone] || "local").to_s.downcase time = (tz == "utc") ? Time.now.utc : Time.now time.iso8601 } )
- WikipediaSearch =
build.call
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#input_schema ⇒ Object
readonly
Returns the value of attribute input_schema.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(arguments) ⇒ Object
-
#initialize(name:, description:, input_schema:, call:, return_direct: false) ⇒ Tool
constructor
A new instance of Tool.
- #return_direct? ⇒ Boolean
Constructor Details
#initialize(name:, description:, input_schema:, call:, return_direct: false) ⇒ Tool
Returns a new instance of Tool.
7 8 9 10 11 12 13 |
# File 'lib/rixie/tool.rb', line 7 def initialize(name:, description:, input_schema:, call:, return_direct: false) @name = name @description = description @input_schema = input_schema @call = call @return_direct = return_direct end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/rixie/tool.rb', line 5 def description @description end |
#input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
5 6 7 |
# File 'lib/rixie/tool.rb', line 5 def input_schema @input_schema end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/rixie/tool.rb', line 5 def name @name end |
Instance Method Details
#call(arguments) ⇒ Object
19 20 21 |
# File 'lib/rixie/tool.rb', line 19 def call(arguments) @call.call(arguments) end |
#return_direct? ⇒ Boolean
15 16 17 |
# File 'lib/rixie/tool.rb', line 15 def return_direct? @return_direct end |