Class: Rixie::ToolExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/rixie/tool_executor.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

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

#definitionsObject



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.message}", error: e)
end

#return_direct?(tool_calls) ⇒ Boolean

Returns:

  • (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