Class: AgentRuntime::ToolRegistry

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

Overview

Registry mapping tool names to Ruby callables.

This class maintains a registry of available tools that can be called by the executor. Tools are registered as callable objects (procs, lambdas, or objects responding to #call).

Examples:

Initialize with tools

tools = {
  "search" => ->(query:) { "Results for #{query}" },
  "calculate" => Calculator.new
}
registry = ToolRegistry.new(tools)

Call a tool

result = registry.call("search", { query: "weather" })
# => "Results for weather"

Instance Method Summary collapse

Constructor Details

#initialize(tools = {}) ⇒ ToolRegistry

Initialize a new ToolRegistry instance.

Examples:

registry = ToolRegistry.new({
  "search" => ->(query:) { search_api(query) },
  "email" => EmailTool.new
})

Parameters:

  • tools (Hash<String, #call>) (defaults to: {})

    Hash mapping tool names to callable objects



29
30
31
# File 'lib/agent_runtime/tool_registry.rb', line 29

def initialize(tools = {})
  @tools = tools
end

Instance Method Details

#call(action, params) ⇒ Object

Call a tool by name with the given parameters.

Examples:

result = registry.call("search", { query: "weather", limit: 10 })
# Calls: search_tool.call(query: "weather", limit: 10)

Parameters:

  • action (String, Symbol)

    The name of the tool to call

  • params (Hash)

    Parameters to pass to the tool (will be keyword-argument expanded)

Returns:

  • (Object)

    The result of calling the tool

Raises:



43
44
45
46
47
48
# File 'lib/agent_runtime/tool_registry.rb', line 43

def call(action, params)
  tool = @tools[action]
  raise ToolNotFound, "Tool not found: #{action}" unless tool

  tool.call(**params)
end