Class: Roast::Cogs::Agent::Providers::Pi::PiInvocation

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/cogs/agent/providers/pi/pi_invocation.rb

Defined Under Namespace

Classes: Context, PiAlreadyStartedError, PiFailedError, PiInvocationError, PiNotCompletedError, PiNotStartedError, Result

Instance Method Summary collapse

Constructor Details

#initialize(config, prompt, session) ⇒ PiInvocation

: (Agent::Config, String, String?) -> void



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 57

def initialize(config, prompt, session)
  @base_command = config.valid_command #: (String | Array[String])?
  @model = config.valid_model #: String?
  @append_system_prompt = config.valid_append_system_prompt #: String?
  @replace_system_prompt = config.valid_replace_system_prompt #: String?
  @working_directory = config.valid_working_directory #: Pathname?
  @prompt = prompt #: String
  @session = session #: String?
  @context = Context.new #: Context
  @result = Result.new #: Result
  @raw_dump_file = config.valid_dump_raw_agent_messages_to_path #: Pathname?
  @show_prompt = config.show_prompt? #: bool
  @show_progress = config.show_progress? #: bool
  @show_response = config.show_response? #: bool
  @num_turns = 0 #: Integer
  @total_cost = 0.0 #: Float
  @model_usage_accumulator = {} #: Hash[String, Hash[Symbol, Numeric]]
  @current_text_block = +"" #: String
  @start_time_ms = nil #: Integer?
end

Instance Method Details

#completed?Boolean

: () -> bool

Returns:

  • (Boolean)


117
118
119
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 117

def completed?
  @completed ||= false
end

#failed?Boolean

: () -> bool

Returns:

  • (Boolean)


122
123
124
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 122

def failed?
  @failed ||= false
end

#resultObject

: () -> Result

Raises:



127
128
129
130
131
132
133
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 127

def result
  raise PiNotStartedError unless started?
  raise PiFailedError, @result.response if failed?
  raise PiNotCompletedError, @result.response unless completed?

  @result
end

#run!Object

: () -> void



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 79

def run!
  raise PiAlreadyStartedError if started?

  @started = true
  Event << { block: { header: "USER PROMPT", content: @prompt } } if @show_prompt
  @start_time_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i
  _stdout, stderr, status = CommandRunner.execute(
    command_line,
    working_directory: @working_directory,
    stdin_content: @prompt,
    stdout_handler: lambda { |line| handle_stdout(line) },
  )
  @end_time_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i #: Integer?

  if status.success?
    @completed = true
    @result.success = true
    finalize_stats!
    Event << { block: { header: "AGENT RESPONSE", content: @result.response } } if @show_response
  else
    @failed = true
    @result.success = false
    @result.response += "\n" unless @result.response.blank? || @result.response.ends_with?("\n")
    @result.response += stderr
  end
end

#running?Boolean

: () -> bool

Returns:

  • (Boolean)


112
113
114
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 112

def running?
  started? && !completed? && !failed?
end

#started?Boolean

: () -> bool

Returns:

  • (Boolean)


107
108
109
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 107

def started?
  @started ||= false
end