Class: SkillBench::Agent::ReactAgent::ToolExecutor
- Inherits:
-
Object
- Object
- SkillBench::Agent::ReactAgent::ToolExecutor
- Defined in:
- lib/skill_bench/agent/react_agent/tool_executor.rb
Overview
Service object responsible for executing a list of tool calls and returning the results formatted as messages to be appended to the conversation history.
Class Method Summary collapse
-
.call(tool_calls, working_dir, container_id = nil) ⇒ Array<Hash>
Executes the provided tool calls.
-
.execute_tool(tool_call, working_dir, container_id) ⇒ Hash
Executes a single tool call and returns the result message.
-
.tool_error_message(tool_call, message) ⇒ Hash
Builds a tool error message for the conversation history.
-
.tool_error_result(tool_call, message) ⇒ Hash
Builds an error result for a failed tool call.
Class Method Details
.call(tool_calls, working_dir, container_id = nil) ⇒ Array<Hash>
Executes the provided tool calls.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/skill_bench/agent/react_agent/tool_executor.rb', line 17 def self.call(tool_calls, working_dir, container_id = nil) tool_calls.map do |tool_call| function_name = tool_call.dig('function', 'name') next (tool_call, 'Missing function name') unless function_name warn "=== Calling Tool: #{function_name} ===" unless defined?(Minitest) result = execute_tool(tool_call, working_dir, container_id) if result.is_a?(Hash) && result[:role] == 'tool' result else error_msg = result.dig(:response, :error, :message) || 'Unknown tool error' (tool_call, error_msg) end end end |
.execute_tool(tool_call, working_dir, container_id) ⇒ Hash
Executes a single tool call and returns the result message.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/skill_bench/agent/react_agent/tool_executor.rb', line 40 def self.execute_tool(tool_call, working_dir, container_id) function_name = tool_call.dig('function', 'name') arguments = tool_call.dig('function', 'arguments') result = Tools.execute(function_name, arguments, working_dir, container_id) { role: 'tool', tool_call_id: tool_call['id'], content: result } rescue StandardError => e SkillBench::ErrorLogger.log_error(e, "Tool execution failed: #{function_name}") tool_error_result(tool_call, e.) end |
.tool_error_message(tool_call, message) ⇒ Hash
Builds a tool error message for the conversation history.
61 62 63 64 65 66 67 |
# File 'lib/skill_bench/agent/react_agent/tool_executor.rb', line 61 def self.(tool_call, ) { role: 'tool', tool_call_id: tool_call['id'], content: "Error: #{}" } end |
.tool_error_result(tool_call, message) ⇒ Hash
Builds an error result for a failed tool call.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/skill_bench/agent/react_agent/tool_executor.rb', line 74 def self.tool_error_result(tool_call, ) { success: false, response: { error: { message: "Tool call failed: #{}", tool_call: tool_call } } } end |