Class: TurnKit::ToolRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/turnkit/tool_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(turn) ⇒ ToolRunner

Returns a new instance of ToolRunner.



5
6
7
# File 'lib/turnkit/tool_runner.rb', line 5

def initialize(turn)
  @turn = turn
end

Instance Method Details

#completion_message(execution) ⇒ Object



17
18
19
20
# File 'lib/turnkit/tool_runner.rb', line 17

def completion_message(execution)
  tool = tool_class(execution.tool_name)
  tool.completion_message(execution.result) || execution.result&.fetch("result", nil) || "Completed via #{execution.tool_name}."
end

#dispatch(tool_calls) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/turnkit/tool_runner.rb', line 9

def dispatch(tool_calls)
  tool_calls.each do |tool_call|
    execution = run(tool_call)
    return execution if execution.completed? && tool_class(tool_call.name)&.ends_turn?
  end
  nil
end