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
20 21 22 |
# File 'lib/clacky/agent/tool_registry.rb', line 20 def all @tools.values end |
#all_definitions ⇒ Object
24 25 26 |
# File 'lib/clacky/agent/tool_registry.rb', line 24 def all_definitions @tools.values.map(&:to_function_definition) end |
#allowed_definitions(allowed_tools = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/clacky/agent/tool_registry.rb', line 28 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
40 41 42 |
# File 'lib/clacky/agent/tool_registry.rb', line 40 def by_category(category) @tools.values.select { |tool| tool.category == category } end |
#get(name) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/clacky/agent/tool_registry.rb', line 13 def get(name) # Handle shell alias to safe_shell for backward compatibility name = 'safe_shell' if name == 'shell' && @tools.key?('safe_shell') && !@tools.key?('shell') @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
36 37 38 |
# File 'lib/clacky/agent/tool_registry.rb', line 36 def tool_names @tools.keys end |