Class: DeepAgentsRb::Tools::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/deepagents/deepagentsrb/tools.rb

Overview

Tool class to define tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, &block) ⇒ Tool



12
13
14
15
16
# File 'lib/deepagents/deepagentsrb/tools.rb', line 12

def initialize(name, description, &block)
  @name = name
  @description = description
  @function = block
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/deepagents/deepagentsrb/tools.rb', line 10

def description
  @description
end

#functionObject (readonly)

Returns the value of attribute function.



10
11
12
# File 'lib/deepagents/deepagentsrb/tools.rb', line 10

def function
  @function
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/deepagents/deepagentsrb/tools.rb', line 10

def name
  @name
end

Instance Method Details

#call(*args, **kwargs) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/deepagents/deepagentsrb/tools.rb', line 18

def call(*args, **kwargs)
  begin
    @function.call(*args, **kwargs)
  rescue ArgumentError => e
    raise ToolError.new(@name, "Invalid arguments: #{e.message}")
  rescue => e
    raise ToolError.new(@name, e.message)
  end
end