Class: ActiveAgent::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/active_agent/tool.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Tool.



7
8
9
10
11
12
13
# File 'lib/active_agent/tool.rb', line 7

def initialize(name, description: "", &block)
  @name = name.to_s
  @description = description
  @parameters = {}
  @required_parameters = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/active_agent/tool.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/active_agent/tool.rb', line 5

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



5
6
7
# File 'lib/active_agent/tool.rb', line 5

def parameters
  @parameters
end

#required_parametersObject (readonly)

Returns the value of attribute required_parameters.



5
6
7
# File 'lib/active_agent/tool.rb', line 5

def required_parameters
  @required_parameters
end

Class Method Details

.map_type(type, uppercase: false) ⇒ Object

Translates ruby types to API-specific type strings



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_agent/tool.rb', line 24

def self.map_type(type, uppercase: false)
  mapped = case type.to_sym
           when :string then "string"
           when :integer then "integer"
           when :number, :float then "number"
           when :boolean then "boolean"
           when :array then "array"
           when :object then "object"
           else "string"
           end
  uppercase ? mapped.upcase : mapped
end

Instance Method Details

#parameter(param_name, type: :string, description: "", required: true) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/active_agent/tool.rb', line 15

def parameter(param_name, type: :string, description: "", required: true)
  @parameters[param_name.to_s] = {
    type: type,
    description: description
  }
  @required_parameters << param_name.to_s if required
end