Class: Rubyagents::Tool
- Inherits:
-
Object
show all
- Defined in:
- lib/rubyagents/tool.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.description(value = nil) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/rubyagents/tool.rb', line 20
def description(value = nil)
if value
@description = value
else
@description || ""
end
end
|
.inherited(subclass) ⇒ Object
6
7
8
9
|
# File 'lib/rubyagents/tool.rb', line 6
def inherited(subclass)
super
subclass.instance_variable_set(:@inputs, {})
end
|
28
29
30
|
# File 'lib/rubyagents/tool.rb', line 28
def input(name, type:, description:, required: true)
@inputs[name] = { type: type, description: description, required: required }
end
|
32
33
34
|
# File 'lib/rubyagents/tool.rb', line 32
def inputs
@inputs ||= {}
end
|
.output_type(value = nil) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/rubyagents/tool.rb', line 36
def output_type(value = nil)
if value
@output_type = value
else
@output_type || :string
end
end
|
.to_prompt ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/rubyagents/tool.rb', line 67
def to_prompt
lines = ["Tool: #{tool_name}", "Description: #{description}"]
if inputs.any?
lines << "Inputs:"
inputs.each do |param_name, config|
opt = config[:required] ? "" : " (optional)"
lines << " - #{param_name} (#{config[:type]}#{opt}): #{config[:description]}"
end
end
lines << "Output type: #{output_type}"
lines.join("\n")
end
|
.to_schema ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/rubyagents/tool.rb', line 44
def to_schema
properties = {}
required = []
inputs.each do |param_name, config|
properties[param_name] = {
type: config[:type].to_s,
description: config[:description]
}
required << param_name.to_s if config[:required]
end
{
name: tool_name,
description: description,
parameters: {
type: "object",
properties: properties,
required: required
}
}
end
|
11
12
13
14
15
16
17
|
# File 'lib/rubyagents/tool.rb', line 11
def tool_name(value = nil)
if value
@tool_name = value
else
@tool_name || name.split("::").last.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end
end
|
Instance Method Details
#call(**kwargs) ⇒ Object
83
84
85
|
# File 'lib/rubyagents/tool.rb', line 83
def call(**kwargs)
raise NotImplementedError, "#{self.class} must implement #call"
end
|