Class: SimpleAcp::Models::Run
Overview
Represents a single agent execution.
Tracks the lifecycle of an agent run from creation through completion, including status, output messages, errors, and timing.
Status Lifecycle
- created -> in_progress -> completed | failed | cancelled | awaiting
- awaiting -> in_progress (on resume)
- cancelling -> cancelled
Instance Attribute Summary collapse
-
#agent_name ⇒ String
readonly
Name of the agent being executed.
-
#await_request ⇒ AwaitRequest?
readonly
Request for client input (when awaiting).
-
#created_at ⇒ Time?
readonly
When the run was created.
-
#error ⇒ Error?
readonly
Error details if failed.
-
#finished_at ⇒ Time?
readonly
When the run finished (completed, failed, or cancelled).
-
#output ⇒ Array<Message>
readonly
Output messages from the agent.
-
#run_id ⇒ String
readonly
Unique UUID for this run.
-
#session_id ⇒ String?
readonly
Optional session ID.
-
#status ⇒ String
readonly
Current status (created, in-progress, completed, failed, cancelled, awaiting).
Class Method Summary collapse
-
.from_hash(hash) ⇒ Run?
Create from a hash (JSON deserialization).
Instance Method Summary collapse
-
#add_output(message) ⇒ self
Add a message to the output.
-
#await!(request) ⇒ self
Transition to awaiting status.
-
#awaiting? ⇒ Boolean
Check if the run is waiting for client input.
-
#cancel! ⇒ self
Transition to cancelling status.
-
#cancelled! ⇒ self
Transition to cancelled status.
-
#cancelled? ⇒ Boolean
Check if the run was cancelled.
-
#cancelling? ⇒ Boolean
Check if the run is being cancelled.
-
#complete!(output = nil) ⇒ self
Transition to completed status.
-
#completed? ⇒ Boolean
Check if the run completed successfully.
-
#fail!(error) ⇒ self
Transition to failed status.
-
#failed? ⇒ Boolean
Check if the run failed.
-
#in_progress? ⇒ Boolean
Check if the run is currently executing.
-
#initialize(**kwargs) ⇒ Run
constructor
A new instance of Run.
-
#raise_for_status! ⇒ self
Raise an exception if the run failed.
-
#start! ⇒ self
Transition to in_progress status.
-
#terminal? ⇒ Boolean
Check if the run is in a terminal state.
-
#valid? ⇒ Boolean
Validate the run.
Methods inherited from Base
#==, attribute, attributes, #hash, own_attributes, #to_h, #to_json
Constructor Details
#initialize(**kwargs) ⇒ Run
Returns a new instance of Run.
52 53 54 55 56 57 |
# File 'lib/simple_acp/models/run.rb', line 52 def initialize(**kwargs) super @run_id ||= Types.generate_uuid @output ||= [] @created_at ||= Time.now end |
Instance Attribute Details
#agent_name ⇒ String (readonly)
Returns name of the agent being executed.
22 |
# File 'lib/simple_acp/models/run.rb', line 22 attribute :agent_name, required: true |
#await_request ⇒ AwaitRequest? (readonly)
Returns request for client input (when awaiting).
34 |
# File 'lib/simple_acp/models/run.rb', line 34 attribute :await_request |
#created_at ⇒ Time? (readonly)
Returns when the run was created.
46 |
# File 'lib/simple_acp/models/run.rb', line 46 attribute :created_at |
#error ⇒ Error? (readonly)
Returns error details if failed.
42 |
# File 'lib/simple_acp/models/run.rb', line 42 attribute :error |
#finished_at ⇒ Time? (readonly)
Returns when the run finished (completed, failed, or cancelled).
50 |
# File 'lib/simple_acp/models/run.rb', line 50 attribute :finished_at |
#output ⇒ Array<Message> (readonly)
Returns output messages from the agent.
38 |
# File 'lib/simple_acp/models/run.rb', line 38 attribute :output, default: -> { [] } |
#run_id ⇒ String (readonly)
Returns unique UUID for this run.
18 |
# File 'lib/simple_acp/models/run.rb', line 18 attribute :run_id, required: true |
#session_id ⇒ String? (readonly)
Returns optional session ID.
26 |
# File 'lib/simple_acp/models/run.rb', line 26 attribute :session_id |
Class Method Details
.from_hash(hash) ⇒ Run?
Create from a hash (JSON deserialization).
63 64 65 66 67 68 69 |
# File 'lib/simple_acp/models/run.rb', line 63 def self.from_hash(hash) return nil if hash.nil? instance = allocate instance.send(:initialize_from_hash, hash) instance end |
Instance Method Details
#add_output(message) ⇒ self
Add a message to the output.
181 182 183 184 |
# File 'lib/simple_acp/models/run.rb', line 181 def add_output() @output << (.is_a?(Message) ? : Message.from_hash()) self end |
#await!(request) ⇒ self
Transition to awaiting status.
132 133 134 135 136 |
# File 'lib/simple_acp/models/run.rb', line 132 def await!(request) @status = Types::RunStatus::AWAITING @await_request = request self end |
#awaiting? ⇒ Boolean
Check if the run is waiting for client input.
88 89 90 |
# File 'lib/simple_acp/models/run.rb', line 88 def awaiting? @status == Types::RunStatus::AWAITING end |
#cancel! ⇒ self
Transition to cancelling status.
163 164 165 166 |
# File 'lib/simple_acp/models/run.rb', line 163 def cancel! @status = Types::RunStatus::CANCELLING self end |
#cancelled! ⇒ self
Transition to cancelled status.
171 172 173 174 175 |
# File 'lib/simple_acp/models/run.rb', line 171 def cancelled! @status = Types::RunStatus::CANCELLED @finished_at = Time.now self end |
#cancelled? ⇒ Boolean
Check if the run was cancelled.
109 110 111 |
# File 'lib/simple_acp/models/run.rb', line 109 def cancelled? @status == Types::RunStatus::CANCELLED end |
#cancelling? ⇒ Boolean
Check if the run is being cancelled.
116 117 118 |
# File 'lib/simple_acp/models/run.rb', line 116 def cancelling? @status == Types::RunStatus::CANCELLING end |
#complete!(output = nil) ⇒ self
Transition to completed status.
142 143 144 145 146 147 |
# File 'lib/simple_acp/models/run.rb', line 142 def complete!(output = nil) @status = Types::RunStatus::COMPLETED @output = output if output @finished_at = Time.now self end |
#completed? ⇒ Boolean
Check if the run completed successfully.
95 96 97 |
# File 'lib/simple_acp/models/run.rb', line 95 def completed? @status == Types::RunStatus::COMPLETED end |
#fail!(error) ⇒ self
Transition to failed status.
153 154 155 156 157 158 |
# File 'lib/simple_acp/models/run.rb', line 153 def fail!(error) @status = Types::RunStatus::FAILED @error = error.is_a?(Error) ? error : Error.server_error(error.to_s) @finished_at = Time.now self end |
#failed? ⇒ Boolean
Check if the run failed.
102 103 104 |
# File 'lib/simple_acp/models/run.rb', line 102 def failed? @status == Types::RunStatus::FAILED end |
#in_progress? ⇒ Boolean
Check if the run is currently executing.
81 82 83 |
# File 'lib/simple_acp/models/run.rb', line 81 def in_progress? @status == Types::RunStatus::IN_PROGRESS end |
#raise_for_status! ⇒ self
Raise an exception if the run failed.
190 191 192 193 194 |
# File 'lib/simple_acp/models/run.rb', line 190 def raise_for_status! return self unless failed? raise SimpleAcp::RunError, @error&. || "Run failed" end |
#start! ⇒ self
Transition to in_progress status.
123 124 125 126 |
# File 'lib/simple_acp/models/run.rb', line 123 def start! @status = Types::RunStatus::IN_PROGRESS self end |
#terminal? ⇒ Boolean
Check if the run is in a terminal state.
74 75 76 |
# File 'lib/simple_acp/models/run.rb', line 74 def terminal? Types::RunStatus.terminal?(@status) end |
#valid? ⇒ Boolean
Validate the run.
199 200 201 202 203 204 205 |
# File 'lib/simple_acp/models/run.rb', line 199 def valid? return false unless Types.valid_uuid?(@run_id) return false unless Types.valid_agent_name?(@agent_name) return false unless Types::RunStatus.valid?(@status) true end |