Class: TurnKit::ToolRunner
- Inherits:
-
Object
- Object
- TurnKit::ToolRunner
- Defined in:
- lib/turnkit/tool_runner.rb
Instance Method Summary collapse
- #completion_message(execution) ⇒ Object
- #dispatch(tool_calls) ⇒ Object
-
#initialize(turn) ⇒ ToolRunner
constructor
A new instance of ToolRunner.
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 (execution) tool = tool_for(execution.tool_name) tool.(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 |