Class: Roast::Cogs::Agent::Providers::Pi::PiInvocation
- Inherits:
-
Object
- Object
- Roast::Cogs::Agent::Providers::Pi::PiInvocation
- 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
-
#completed? ⇒ Boolean
: () -> bool.
-
#failed? ⇒ Boolean
: () -> bool.
-
#initialize(config, prompt, session) ⇒ PiInvocation
constructor
: (Agent::Config, String, String?) -> void.
-
#result ⇒ Object
: () -> Result.
-
#run! ⇒ Object
: () -> void.
-
#running? ⇒ Boolean
: () -> bool.
-
#started? ⇒ Boolean
: () -> bool.
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. #: 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
117 118 119 |
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 117 def completed? @completed ||= false end |
#failed? ⇒ Boolean
: () -> bool
122 123 124 |
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 122 def failed? @failed ||= false end |
#result ⇒ Object
: () -> Result
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
112 113 114 |
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 112 def running? started? && !completed? && !failed? end |
#started? ⇒ Boolean
: () -> bool
107 108 109 |
# File 'lib/roast/cogs/agent/providers/pi/pi_invocation.rb', line 107 def started? @started ||= false end |