Class: Legate::ToolRegistry
- Inherits:
-
Object
- Object
- Legate::ToolRegistry
- Defined in:
- lib/legate/tool_registry.rb
Overview
Manages a collection of tool definitions for a specific agent instance.
Instance Attribute Summary collapse
-
#tools ⇒ Object
readonly
Make tools readable.
Instance Method Summary collapse
-
#available_tool_names ⇒ Array<Symbol>
Get the set of registered tool name symbols.
-
#create_instance(name_symbol) ⇒ Legate::Tool?
Create an instance of a tool by its name symbol using the class registered here.
-
#find_class(name_symbol) ⇒ Class?
Find a tool class by its name symbol within this registry.
-
#initialize ⇒ ToolRegistry
constructor
Initialize an empty tool registry.
-
#list_tools ⇒ Array<Hash>
Get a list of available tools registered in this instance with basic info.
-
#register(name, klass) ⇒ Object
Register a tool class with this registry instance.
Constructor Details
#initialize ⇒ ToolRegistry
Initialize an empty tool registry.
12 13 14 |
# File 'lib/legate/tool_registry.rb', line 12 def initialize @tools = {} # Stores { name_symbol => tool_class } for this instance end |
Instance Attribute Details
#tools ⇒ Object (readonly)
Make tools readable
9 10 11 |
# File 'lib/legate/tool_registry.rb', line 9 def tools @tools end |
Instance Method Details
#available_tool_names ⇒ Array<Symbol>
Get the set of registered tool name symbols.
60 61 62 |
# File 'lib/legate/tool_registry.rb', line 60 def available_tool_names @tools.keys end |
#create_instance(name_symbol) ⇒ Legate::Tool?
Create an instance of a tool by its name symbol using the class registered here.
52 53 54 55 56 |
# File 'lib/legate/tool_registry.rb', line 52 def create_instance(name_symbol) klass = find_class(name_symbol) Legate.logger.debug("[ToolRegistry #{@object_id}] create_instance(#{name_symbol.inspect}): Found class: #{klass.inspect}") klass&.new end |
#find_class(name_symbol) ⇒ Class?
Find a tool class by its name symbol within this registry.
43 44 45 46 47 |
# File 'lib/legate/tool_registry.rb', line 43 def find_class(name_symbol) found_class = @tools[name_symbol.to_sym] Legate.logger.debug("[ToolRegistry #{@object_id}] find_class(#{name_symbol.inspect}): Found class in @tools: #{found_class.inspect}") found_class end |
#list_tools ⇒ Array<Hash>
Get a list of available tools registered in this instance with basic info.
66 67 68 69 70 71 |
# File 'lib/legate/tool_registry.rb', line 66 def list_tools @tools.values.map do |klass| = klass. # Get the full { name:, description:, parameters: } hash # Return the full hash end.sort_by { |t| t[:name].to_s } end |
#register(name, klass) ⇒ Object
Register a tool class with this registry instance.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/legate/tool_registry.rb', line 19 def register(name, klass) logger = Legate.logger # Get the central logger instance unless klass < Legate::Tool logger.error("ToolRegistry: Attempted to register non-tool class: #{klass.inspect} for name '#{name}'.") return false end name_symbol = name.to_sym # Ensure it's a symbol if @tools.key?(name_symbol) # Use the local variable 'logger' logger.warn("ToolRegistry: Tool '#{name_symbol}' is already registered in this registry. Overwriting with class #{klass}.") else # Use the local variable 'logger' logger.info("ToolRegistry: Registering tool '#{name_symbol}' with class #{klass} in this registry.") end @tools[name_symbol] = klass true # Indicate success end |