Class: Envoy::ToolDefinition
- Inherits:
-
Object
- Object
- Envoy::ToolDefinition
- Defined in:
- lib/envoy/tool_definition.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#perform_block ⇒ Object
readonly
Returns the value of attribute perform_block.
-
#tool_class ⇒ Object
Returns the value of attribute tool_class.
Instance Method Summary collapse
- #access(level = nil) ⇒ Object
-
#description(text = nil) ⇒ Object
--- DSL ---.
- #enum_for(param_name) ⇒ Object
-
#initialize(name) ⇒ ToolDefinition
constructor
A new instance of ToolDefinition.
-
#param(name, desc, type: :string, required: true, enum: nil) ⇒ Object
enum declares a closed vocabulary for a param.
- #perform(&block) ⇒ Object
-
#read? ⇒ Boolean
--- introspection ---.
- #write? ⇒ Boolean
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/envoy/tool_definition.rb', line 3 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/envoy/tool_definition.rb', line 3 def params @params end |
#perform_block ⇒ Object (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_class ⇒ Object
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
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 ---
45 |
# File 'lib/envoy/tool_definition.rb', line 45 def read? = @access == :read |
#write? ⇒ Boolean
46 |
# File 'lib/envoy/tool_definition.rb', line 46 def write? = @access == :write |