Class: Ragents::ToolRegistry
- Inherits:
-
Object
- Object
- Ragents::ToolRegistry
- Includes:
- Enumerable
- Defined in:
- lib/ragents/tool.rb
Overview
Registry of tools that can be shared across agents
Instance Method Summary collapse
- #[](name) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #freeze ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
- #register(name = nil, tool = nil, &block) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #to_anthropic_schemas ⇒ Object
- #to_json_schemas ⇒ Object
Constructor Details
#initialize ⇒ ToolRegistry
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
251 252 253 |
# File 'lib/ragents/tool.rb', line 251 def empty? @tools.empty? end |
#freeze ⇒ Object
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
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 |
#size ⇒ Object
247 248 249 |
# File 'lib/ragents/tool.rb', line 247 def size @tools.size end |
#to_a ⇒ Object
235 236 237 |
# File 'lib/ragents/tool.rb', line 235 def to_a @tools.values end |
#to_anthropic_schemas ⇒ Object
243 244 245 |
# File 'lib/ragents/tool.rb', line 243 def to_anthropic_schemas @tools.values.map(&:to_anthropic_schema) end |
#to_json_schemas ⇒ Object
239 240 241 |
# File 'lib/ragents/tool.rb', line 239 def to_json_schemas @tools.values.map(&:to_json_schema) end |