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



20
21
22
23
# File 'lib/turnkit/tool_runner.rb', line 20

def completion_message(execution)
  tool = tool_for(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
16
17
18
# File 'lib/turnkit/tool_runner.rb', line 9

def dispatch(tool_calls)
  tool_calls.each_with_index do |tool_call, index|
    execution = run(tool_call)
    if execution.completed? && tool_for(tool_call.name)&.ends_turn?
      skip_remaining(tool_calls.drop(index + 1), terminal: tool_call)
      return execution
    end
  end
  nil
end