Class: SolidAgent::HasTools::ToolBuilder
- Inherits:
-
Object
- Object
- SolidAgent::HasTools::ToolBuilder
- Defined in:
- lib/solid_agent/has_tools.rb
Overview
DSL builder for inline tool definitions.
Provides a clean API for defining tool schemas programmatically:
tool :my_tool do
description "Does something useful"
parameter :input, type: :string, required: true
end
Instance Method Summary collapse
-
#description(text) ⇒ void
Sets the tool description.
-
#initialize(name) ⇒ ToolBuilder
constructor
A new instance of ToolBuilder.
-
#parameter(name, type:, required: false, description: nil, enum: nil, items: nil, properties: nil, default: nil) ⇒ void
Defines a parameter for the tool.
-
#to_schema ⇒ Hash
Converts the builder state to an OpenAI-compatible tool schema.
Constructor Details
#initialize(name) ⇒ ToolBuilder
Returns a new instance of ToolBuilder.
193 194 195 196 197 198 |
# File 'lib/solid_agent/has_tools.rb', line 193 def initialize(name) @name = name.to_s @description = "" @parameters = {} @required = [] end |
Instance Method Details
#description(text) ⇒ void
This method returns an undefined value.
Sets the tool description.
204 205 206 |
# File 'lib/solid_agent/has_tools.rb', line 204 def description(text) @description = text end |
#parameter(name, type:, required: false, description: nil, enum: nil, items: nil, properties: nil, default: nil) ⇒ void
This method returns an undefined value.
Defines a parameter for the tool.
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/solid_agent/has_tools.rb', line 228 def parameter(name, type:, required: false, description: nil, enum: nil, items: nil, properties: nil, default: nil) param_schema = { type: type.to_s } param_schema[:description] = description if description param_schema[:enum] = enum if enum param_schema[:items] = items if items param_schema[:properties] = properties if properties param_schema[:default] = default if default @parameters[name.to_s] = param_schema @required << name.to_s if required end |
#to_schema ⇒ Hash
Converts the builder state to an OpenAI-compatible tool schema.
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/solid_agent/has_tools.rb', line 243 def to_schema { type: "function", name: @name, description: @description, parameters: { type: "object", properties: @parameters, required: @required }.compact } end |