Class: Brute::Tool
- Inherits:
-
Object
- Object
- Brute::Tool
- Defined in:
- lib/brute/tool.rb
Overview
Base class for Brute's built-in tools — a tiny, framework-agnostic tool DSL. It intentionally mirrors the common tool-library shape (description + params) so tools read the same as they would in any LLM library, without depending on one:
class Shell < Brute::Tool
description "Execute a shell command"
param :command, type: 'string', desc: "The command", required: true
def name; "shell"; end
def execute(command:)
...
end
end
For tools whose arguments don't fit the flat param list, pass a raw JSON schema instead:
params({ type: 'object', properties: { ... }, required: [...] })
Instances expose the neutral interface Brute::Tools::Adapter understands: #name, #description, #params, #params_schema, #call.
Direct Known Subclasses
Brute::Tools::FSPatch, Brute::Tools::FSRead, Brute::Tools::FSRemove, Brute::Tools::FSSearch, Brute::Tools::FSUndo, Brute::Tools::FSWrite, Brute::Tools::NetFetch, Brute::Tools::Question, Brute::Tools::Shell, Brute::Tools::SkillLoad, Brute::Tools::TodoRead, Brute::Tools::TodoWrite
Class Method Summary collapse
- .description(text = nil) ⇒ Object
-
.param(name, type: "string", desc: nil, required: true, **opts) ⇒ Object
Declare one parameter: param :key, type:, desc:, required:.
- .param_definitions ⇒ Object
-
.params(schema = nil) ⇒ Object
Raw JSON-schema override for complex argument shapes.
Instance Method Summary collapse
-
#call(arguments = {}) ⇒ Object
Execute with a string- or symbol-keyed argument hash, as delivered by LLM providers.
- #description ⇒ Object
- #execute ⇒ Object
-
#name ⇒ Object
Tool name; subclasses usually override with an explicit short name.
-
#params ⇒ Object
{ key => { type:, desc:, required: } }.
-
#params_schema ⇒ Object
The raw JSON schema, when declared via params(...).
Class Method Details
.description(text = nil) ⇒ Object
32 33 34 35 36 |
# File 'lib/brute/tool.rb', line 32 def description(text = nil) return @description unless text @description = text end |
.param(name, type: "string", desc: nil, required: true, **opts) ⇒ Object
Declare one parameter: param :key, type:, desc:, required:
39 40 41 |
# File 'lib/brute/tool.rb', line 39 def param(name, type: "string", desc: nil, required: true, **opts) param_definitions[name.to_sym] = { type: type, desc: desc, required: required, **opts }.compact end |
.param_definitions ⇒ Object
43 44 45 |
# File 'lib/brute/tool.rb', line 43 def param_definitions @param_definitions ||= {} end |
.params(schema = nil) ⇒ Object
Raw JSON-schema override for complex argument shapes.
48 49 50 51 52 |
# File 'lib/brute/tool.rb', line 48 def params(schema = nil) return @params_schema unless schema @params_schema = schema.deep_symbolize_keys end |
Instance Method Details
#call(arguments = {}) ⇒ Object
Execute with a string- or symbol-keyed argument hash, as delivered by LLM providers.
76 77 78 |
# File 'lib/brute/tool.rb', line 76 def call(arguments = {}) execute(**arguments.to_h.transform_keys(&:to_sym)) end |
#description ⇒ Object
60 61 62 |
# File 'lib/brute/tool.rb', line 60 def description self.class.description.to_s end |
#execute ⇒ Object
80 81 82 |
# File 'lib/brute/tool.rb', line 80 def execute(**) raise NotImplementedError, "#{self.class} must implement #execute" end |
#name ⇒ Object
Tool name; subclasses usually override with an explicit short name.
56 57 58 |
# File 'lib/brute/tool.rb', line 56 def name self.class.name.demodulize.underscore end |
#params ⇒ Object
{ key => { type:, desc:, required: } }
65 66 67 |
# File 'lib/brute/tool.rb', line 65 def params self.class.param_definitions end |
#params_schema ⇒ Object
The raw JSON schema, when declared via params(...).
70 71 72 |
# File 'lib/brute/tool.rb', line 70 def params_schema self.class.params end |