Class: Anthropic::Helpers::Tools::Runner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/anthropic/helpers/tools/runner.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, params:, max_iterations: nil, compaction_control: nil) ⇒ Runner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Runner.

Parameters:



249
250
251
252
253
254
255
256
257
258
# File 'lib/anthropic/helpers/tools/runner.rb', line 249

def initialize(client, params:, max_iterations: nil, compaction_control: nil)
  @client = client
  @params = params.to_h
  @finished = false
  @max_iterations = max_iterations
  @iteration_count = 0
  @compaction_control = compaction_control
  @compaction_warned = false
  @last_response = nil
end

Instance Attribute Details

#paramsAnthropic::Models::Beta::MessageCreateParams

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/anthropic/helpers/tools/runner.rb', line 10

def params
  @params
end

Instance Method Details

#each_message {|| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yield Parameters:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/anthropic/helpers/tools/runner.rb', line 43

def each_message(&blk)
  unless block_given?
    raise ArgumentError.new("A block must be given to ##{__method__}")
  end

  fold do
    message = @client.beta.messages.create(with_helper_header(_1, "runner"))
    blk.call(message)
    [false, message]
  end
end

#each_streaming {|| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/anthropic/helpers/tools/runner.rb', line 56

def each_streaming(&blk)
  unless block_given?
    raise ArgumentError.new("A block must be given to ##{__method__}")
  end

  fold do
    stream = @client.beta.messages.stream(with_helper_header(_1, "runner"))
    blk.call(stream)
    [false, stream.accumulated_message]
  ensure
    stream&.close
  end
end

#feed_messages(*messages) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



16
17
18
# File 'lib/anthropic/helpers/tools/runner.rb', line 16

def feed_messages(*messages)
  self.params = {**params.to_h, messages: params[:messages].to_a + messages}
end

#finished?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



13
# File 'lib/anthropic/helpers/tools/runner.rb', line 13

def finished? = @finished

#next_messageAnthropic::Models::BetaMessage?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
# File 'lib/anthropic/helpers/tools/runner.rb', line 24

def next_message
  message = nil
  unless finished?
    fold do
      message = @client.beta.messages.create(with_helper_header(_1, "runner"))
      [true, message]
    end
  end
  message
end

#run_until_finishedArray<Anthropic::Models::BetaMessage>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



36
37
38
39
40
# File 'lib/anthropic/helpers/tools/runner.rb', line 36

def run_until_finished
  messages = []
  each_streaming { messages << _1.accumulated_message }
  messages
end