Class: Antigravity::ToolRunner
- Defined in:
- lib/antigravity/tool_runner.rb
Overview
Registers, resolves, and executes custom tools for agent callbacks. Tools are invoked by the harness when the model decides to call them.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#execute(name, **kwargs) ⇒ Object
Execute a tool by name with keyword args.
-
#initialize ⇒ ToolRunner
constructor
A new instance of ToolRunner.
-
#register(tool) ⇒ Object
Register a tool (Tool::Dynamic or any Tool subclass).
-
#registered?(name) ⇒ Boolean
Check if a tool is registered.
- #size ⇒ Object
-
#to_harness_tools ⇒ Object
Generate harness-compatible tool definitions for HarnessConfig.
Methods inherited from Base
Methods included from Emojifiable
Constructor Details
#initialize ⇒ ToolRunner
Returns a new instance of ToolRunner.
9 10 11 |
# File 'lib/antigravity/tool_runner.rb', line 9 def initialize @tools = {} end |
Instance Method Details
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/antigravity/tool_runner.rb', line 55 def empty? @tools.empty? end |
#execute(name, **kwargs) ⇒ Object
Execute a tool by name with keyword args. Returns the result or a { error: "..." } hash on failure.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/antigravity/tool_runner.rb', line 28 def execute(name, **kwargs) tool = @tools[name.to_s] raise ToolNotFoundError, "Tool '#{name}' not found" unless tool tool.call(**kwargs) rescue ToolNotFoundError raise rescue => e { error: e. } end |
#register(tool) ⇒ Object
Register a tool (Tool::Dynamic or any Tool subclass)
14 15 16 17 18 19 |
# File 'lib/antigravity/tool_runner.rb', line 14 def register(tool) name = tool.respond_to?(:tool_name) ? tool.tool_name : tool.to_s raise ToolError, "Tool '#{name}' is already registered" if @tools.key?(name) @tools[name] = tool end |
#registered?(name) ⇒ Boolean
Check if a tool is registered
22 23 24 |
# File 'lib/antigravity/tool_runner.rb', line 22 def registered?(name) @tools.key?(name.to_s) end |
#size ⇒ Object
51 52 53 |
# File 'lib/antigravity/tool_runner.rb', line 51 def size @tools.size end |
#to_harness_tools ⇒ Object
Generate harness-compatible tool definitions for HarnessConfig
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/antigravity/tool_runner.rb', line 40 def to_harness_tools @tools.values.map do |tool| schema = tool.to_json_schema { name: schema[:name], description: schema[:description], parametersJsonSchema: JSON.generate(schema[:parameters]) } end end |