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:



395
396
397
398
399
400
401
402
403
404
# File 'lib/anthropic/helpers/tools/runner.rb', line 395

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.



32
33
34
# File 'lib/anthropic/helpers/tools/runner.rb', line 32

def params
  @params
end

Instance Method Details

#each_message {|| ... } ⇒ Object

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:



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/anthropic/helpers/tools/runner.rb', line 65

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, StainlessHelperHeader::BETA_TOOL_RUNNER))
    blk.call(message)
    [false, message]
  end
end

#each_streaming {|| ... } ⇒ Object

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.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/anthropic/helpers/tools/runner.rb', line 78

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, StainlessHelperHeader::BETA_TOOL_RUNNER))
    blk.call(stream)
    [false, stream.accumulated_message]
  ensure
    stream&.close
  end
end

#feed_messages(*messages) ⇒ Object

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:

  • params (Array<Anthropic::Beta::BetaMessageParam>)


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

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:



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

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.



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

def next_message
  message = nil
  unless finished?
    fold do
      message = @client.beta.messages.create(with_helper_header(_1, StainlessHelperHeader::BETA_TOOL_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:



58
59
60
61
62
# File 'lib/anthropic/helpers/tools/runner.rb', line 58

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