Class: Envoy::ToolDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/envoy/tool_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ToolDefinition

Returns a new instance of ToolDefinition.



6
7
8
9
10
11
12
# File 'lib/envoy/tool_definition.rb', line 6

def initialize(name)
  @name = name.to_s
  @description = ""
  @access = :read
  @params = []
  @perform_block = ->(**) { }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/envoy/tool_definition.rb', line 3

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/envoy/tool_definition.rb', line 3

def params
  @params
end

#perform_blockObject (readonly)

Returns the value of attribute perform_block.



3
4
5
# File 'lib/envoy/tool_definition.rb', line 3

def perform_block
  @perform_block
end

#tool_classObject

Returns the value of attribute tool_class.



4
5
6
# File 'lib/envoy/tool_definition.rb', line 4

def tool_class
  @tool_class
end

Instance Method Details

#access(level = nil) ⇒ Object

Raises:



20
21
22
23
24
# File 'lib/envoy/tool_definition.rb', line 20

def access(level = nil)
  return @access if level.nil?
  raise Envoy::Error, "access must be :read or :write" unless %i[read write].include?(level)
  @access = level
end

#description(text = nil) ⇒ Object

--- DSL ---



15
16
17
18
# File 'lib/envoy/tool_definition.rb', line 15

def description(text = nil)
  return @description if text.nil?
  @description = text
end

#enum_for(param_name) ⇒ Object



36
37
38
# File 'lib/envoy/tool_definition.rb', line 36

def enum_for(param_name)
  @params.find { |p| p[:name] == param_name.to_sym }&.fetch(:enum)
end

#param(name, desc, type: :string, required: true, enum: nil) ⇒ Object

enum declares a closed vocabulary for a param. RubyLLM::Parameter has no enum support (its initializer would raise on the keyword), so the values are folded into the description the model reads, and Guard enforces them — yielding the same "error":..,"type":"invalid" shape as any other bad argument.



30
31
32
33
34
# File 'lib/envoy/tool_definition.rb', line 30

def param(name, desc, type: :string, required: true, enum: nil)
  enum = enum&.map(&:to_s)
  desc = "#{desc} One of: #{enum.join(', ')}." if enum
  @params << { name: name.to_sym, desc: desc, type: type, required: required, enum: enum }
end

#perform(&block) ⇒ Object



40
41
42
# File 'lib/envoy/tool_definition.rb', line 40

def perform(&block)
  @perform_block = block
end

#read?Boolean

--- introspection ---

Returns:

  • (Boolean)


45
# File 'lib/envoy/tool_definition.rb', line 45

def read?  = @access == :read

#write?Boolean

Returns:

  • (Boolean)


46
# File 'lib/envoy/tool_definition.rb', line 46

def write? = @access == :write