Class: Prescient::Agent::ToolRegistry

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

Overview

Explicit allowlist and invocation boundary for agent tools.

Defined Under Namespace

Classes: Tool

Instance Method Summary collapse

Constructor Details

#initialize(tools) ⇒ ToolRegistry

Returns a new instance of ToolRegistry.



10
11
12
# File 'lib/prescient/agent/tool_registry.rb', line 10

def initialize(tools)
  @tools = tools.to_h { |name, tool| [name.to_sym, build_tool(name, tool)] }
end

Instance Method Details

#allArray<Tool>

Return all explicitly allowed tools.

Returns:

  • (Array<Tool>)

    Tool descriptors



16
17
18
# File 'lib/prescient/agent/tool_registry.rb', line 16

def all
  @tools.values
end

#invoke(name, arguments) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/prescient/agent/tool_registry.rb', line 20

def invoke(name, arguments)
  tool = @tools[name.to_sym]
  raise UnauthorizedToolError, "agent tool not allowed: #{name}" unless tool

  SchemaValidator.validate!(tool.schema, arguments)
  tool.callable.call(arguments)
end