Class: DeepAgents::Tool
- Inherits:
-
Object
- Object
- DeepAgents::Tool
- Defined in:
- lib/deepagents/tools.rb
Overview
Tool class for defining tools that can be used by the agent
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #call(*args, **kwargs) ⇒ Object
-
#initialize(name, description, parameters = [], &block) ⇒ Tool
constructor
A new instance of Tool.
- #to_h ⇒ Object
Constructor Details
#initialize(name, description, parameters = [], &block) ⇒ Tool
Returns a new instance of Tool.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/deepagents/tools.rb', line 8 def initialize(name, description, parameters = [], &block) raise ArgumentError, "Tool name cannot be nil or empty" if name.nil? || name.empty? raise ArgumentError, "Tool description cannot be nil or empty" if description.nil? || description.empty? raise ArgumentError, "Tool function block must be provided" unless block_given? @name = name @description = description @parameters = parameters @function = block end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/deepagents/tools.rb', line 6 def description @description end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
6 7 8 |
# File 'lib/deepagents/tools.rb', line 6 def function @function end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/deepagents/tools.rb', line 6 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/deepagents/tools.rb', line 6 def parameters @parameters end |
Instance Method Details
#call(*args, **kwargs) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/deepagents/tools.rb', line 19 def call(*args, **kwargs) begin @function.call(*args, **kwargs) rescue => e raise ToolError.new(@name, e.) end end |
#to_h ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/deepagents/tools.rb', line 27 def to_h { name: @name, description: @description, parameters: @parameters } end |