Class: Ragents::ToolRegistry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ragents/tool.rb

Overview

Registry of tools that can be shared across agents

Instance Method Summary collapse

Constructor Details

#initializeToolRegistry

Returns a new instance of ToolRegistry.



209
210
211
# File 'lib/ragents/tool.rb', line 209

def initialize
  @tools = {}
end

Instance Method Details

#[](name) ⇒ Object



223
224
225
# File 'lib/ragents/tool.rb', line 223

def [](name)
  @tools[name.to_sym]
end

#each(&block) ⇒ Object



231
232
233
# File 'lib/ragents/tool.rb', line 231

def each(&block)
  @tools.values.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/ragents/tool.rb', line 251

def empty?
  @tools.empty?
end

#freezeObject



255
256
257
258
259
# File 'lib/ragents/tool.rb', line 255

def freeze
  @tools.freeze
  @tools.each_value(&:freeze)
  super
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/ragents/tool.rb', line 227

def include?(name)
  @tools.key?(name.to_sym)
end

#register(name = nil, tool = nil, &block) ⇒ Object



213
214
215
216
217
218
219
220
221
# File 'lib/ragents/tool.rb', line 213

def register(name = nil, tool = nil, &block)
  if block_given?
    tool = Tool.new(name, &block)
  elsif tool.nil?
    raise ArgumentError, "Must provide a Tool or a block"
  end

  @tools[tool.name] = tool
end

#sizeObject



247
248
249
# File 'lib/ragents/tool.rb', line 247

def size
  @tools.size
end

#to_aObject



235
236
237
# File 'lib/ragents/tool.rb', line 235

def to_a
  @tools.values
end

#to_anthropic_schemasObject



243
244
245
# File 'lib/ragents/tool.rb', line 243

def to_anthropic_schemas
  @tools.values.map(&:to_anthropic_schema)
end

#to_json_schemasObject



239
240
241
# File 'lib/ragents/tool.rb', line 239

def to_json_schemas
  @tools.values.map(&:to_json_schema)
end