Class: Hellm::Tools::Registry
- Inherits:
-
Object
- Object
- Hellm::Tools::Registry
- Defined in:
- lib/hellm/tools/registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(tool_name, instance = nil, &factory) ⇒ Object
- #add_agents(*agents) ⇒ Object
- #get(*tool_names) ⇒ Object
- #get_agent_tools(*agent_names) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 |
# File 'lib/hellm/tools/registry.rb', line 9 def initialize @tools = {} @agent_tools = {} end |
Class Method Details
.instance ⇒ Object
5 6 7 |
# File 'lib/hellm/tools/registry.rb', line 5 def self.instance @instance ||= new end |
Instance Method Details
#add(tool_name, instance = nil, &factory) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/hellm/tools/registry.rb', line 14 def add(tool_name, instance=nil, &factory) @tools[tool_name.to_s] = { factory: factory, instance: instance } end |
#add_agents(*agents) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/hellm/tools/registry.rb', line 33 def add_agents(*agents) agents.each do |agent| tool_name = agent_tool_name(agent.name) tool = Hellm::Tools::AgentToolFactory.create_sub_agent_tool(tool_name, agent) add(tool_name, tool) end end |
#get(*tool_names) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hellm/tools/registry.rb', line 21 def get(*tool_names) tools = tool_names.map do |tool_name| entry = @tools[tool_name.to_s] if entry.nil? raise ArgumentError, "Tool not found: #{tool_name}" end entry[:instance] ||= entry[:factory].call entry[:instance] end tools.compact end |
#get_agent_tools(*agent_names) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/hellm/tools/registry.rb', line 41 def get_agent_tools(*agent_names) tool_names = agent_names.map do |name| agent_tool_name(name) end get(*tool_names) end |