Class: DebugAgent::ToolRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/debug_agent/tool_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeToolRegistry

Returns a new instance of ToolRegistry.



13
14
15
# File 'lib/debug_agent/tool_registry.rb', line 13

def initialize
  @tools = {}
end

Instance Method Details

#all_schemasObject



25
26
27
# File 'lib/debug_agent/tool_registry.rb', line 25

def all_schemas
  @tools.values.map(&:to_schema)
end

#execute(name, args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/debug_agent/tool_registry.rb', line 29

def execute(name, args)
  tool = @tools[name]
  return { error: "Unknown tool: #{name}" } unless tool

  begin
    result = tool.func.call(**args)
    result
  rescue => e
    { error: e.message }
  end
end

#get(name) ⇒ Object



21
22
23
# File 'lib/debug_agent/tool_registry.rb', line 21

def get(name)
  @tools[name]
end

#namesObject



41
42
43
# File 'lib/debug_agent/tool_registry.rb', line 41

def names
  @tools.keys
end

#register(tool) ⇒ Object



17
18
19
# File 'lib/debug_agent/tool_registry.rb', line 17

def register(tool)
  @tools[tool.name] = tool
end