Class: Clacky::ToolRegistry
- Inherits:
-
Object
- Object
- Clacky::ToolRegistry
- Defined in:
- lib/clacky/agent/tool_registry.rb
Instance Method Summary collapse
- #all ⇒ Object
- #all_definitions ⇒ Object
- #allowed_definitions(allowed_tools = nil) ⇒ Object
- #by_category(category) ⇒ Object
- #get(name) ⇒ Object
-
#initialize ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
- #register(tool) ⇒ Object
- #tool_names ⇒ Object
Constructor Details
#initialize ⇒ ToolRegistry
Returns a new instance of ToolRegistry.
5 6 7 |
# File 'lib/clacky/agent/tool_registry.rb', line 5 def initialize @tools = {} end |
Instance Method Details
#all ⇒ Object
17 18 19 |
# File 'lib/clacky/agent/tool_registry.rb', line 17 def all @tools.values end |
#all_definitions ⇒ Object
21 22 23 |
# File 'lib/clacky/agent/tool_registry.rb', line 21 def all_definitions @tools.values.map(&:to_function_definition) end |
#allowed_definitions(allowed_tools = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/clacky/agent/tool_registry.rb', line 25 def allowed_definitions(allowed_tools = nil) return all_definitions if allowed_tools.nil? || allowed_tools.include?("all") @tools.select { |name, _| allowed_tools.include?(name) } .values .map(&:to_function_definition) end |
#by_category(category) ⇒ Object
37 38 39 |
# File 'lib/clacky/agent/tool_registry.rb', line 37 def by_category(category) @tools.values.select { |tool| tool.category == category } end |
#get(name) ⇒ Object
13 14 15 |
# File 'lib/clacky/agent/tool_registry.rb', line 13 def get(name) @tools[name] || raise(Clacky::ToolCallError, "Tool not found: #{name}") end |
#register(tool) ⇒ Object
9 10 11 |
# File 'lib/clacky/agent/tool_registry.rb', line 9 def register(tool) @tools[tool.name] = tool end |
#tool_names ⇒ Object
33 34 35 |
# File 'lib/clacky/agent/tool_registry.rb', line 33 def tool_names @tools.keys end |