Class: Prescient::Agent::ToolRegistry
- Inherits:
-
Object
- Object
- Prescient::Agent::ToolRegistry
- 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
-
#all ⇒ Array<Tool>
Return all explicitly allowed tools.
-
#initialize(tools) ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
- #invoke(name, arguments) ⇒ Object
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
#all ⇒ Array<Tool>
Return all explicitly allowed tools.
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 |