Class: Rixie::ToolExecutor
- Inherits:
-
Object
- Object
- Rixie::ToolExecutor
- Defined in:
- lib/rixie/tool_executor.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #definitions ⇒ Object
- #execute(tool_call) ⇒ Object
-
#initialize(tools: []) ⇒ ToolExecutor
constructor
A new instance of ToolExecutor.
- #return_direct?(tool_calls) ⇒ Boolean
Constructor Details
#initialize(tools: []) ⇒ ToolExecutor
Returns a new instance of ToolExecutor.
10 11 12 |
# File 'lib/rixie/tool_executor.rb', line 10 def initialize(tools: []) @tools = tools.each_with_object({}) { |t, h| h[t.name] = t } end |
Instance Method Details
#definitions ⇒ Object
30 31 32 |
# File 'lib/rixie/tool_executor.rb', line 30 def definitions @tools.values end |
#execute(tool_call) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rixie/tool_executor.rb', line 14 def execute(tool_call) tool = @tools[tool_call.name] raise Rixie::ToolNotFoundError, "Tool not found: #{tool_call.name.inspect}" if tool.nil? content = tool.call(tool_call.arguments) Result.new(tool_call_id: tool_call.id, content: content.to_s, error: nil) rescue ToolNotFoundError raise # configuration bug, not a tool runtime error — let it propagate rescue => e Result.new(tool_call_id: tool_call.id, content: "Error: #{e.}", error: e) end |
#return_direct?(tool_calls) ⇒ Boolean
26 27 28 |
# File 'lib/rixie/tool_executor.rb', line 26 def return_direct?(tool_calls) tool_calls.any? { |tc| @tools[tc.name]&.return_direct? } end |