Class: Omnibot::Tool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Omnibot::Tool
- Defined in:
- lib/omnibot/tool.rb
Defined Under Namespace
Modules: SafeExecute
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
- .from_block(name_sym, description_str, &block) ⇒ Object
-
.inherited(subclass) ⇒ Object
Wrap every subclass's #execute with error capture + instrumentation.
Instance Method Summary collapse
-
#initialize(context = {}) ⇒ Tool
constructor
A new instance of Tool.
Constructor Details
#initialize(context = {}) ⇒ Tool
Returns a new instance of Tool.
5 6 7 8 |
# File 'lib/omnibot/tool.rb', line 5 def initialize(context = {}) super() @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/omnibot/tool.rb', line 3 def context @context end |
Class Method Details
.from_block(name_sym, description_str, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/omnibot/tool.rb', line 16 def self.from_block(name_sym, description_str, &block) Class.new(self) do description(description_str) define_method(:execute, &block) define_method(:name) { name_sym.to_s } # Declare params from the block's own signature: SafeExecute shadows # #execute with (**kwargs), so ruby_llm's signature inference sees no # keywords and would emit an empty schema. block.parameters.each do |kind, pname| param(pname) if kind == :keyreq param(pname, required: false) if kind == :key end end end |
.inherited(subclass) ⇒ Object
Wrap every subclass's #execute with error capture + instrumentation.
11 12 13 14 |
# File 'lib/omnibot/tool.rb', line 11 def self.inherited(subclass) super subclass.prepend(SafeExecute) unless subclass.ancestors.include?(SafeExecute) end |