Class: Agentic::TaskExecutionResult
- Inherits:
-
Object
- Object
- Agentic::TaskExecutionResult
- Defined in:
- lib/agentic/task_execution_result.rb
Overview
Value object representing the execution result of a task
Instance Attribute Summary collapse
-
#failure ⇒ TaskFailure?
readonly
The failure details (only if failed).
-
#output ⇒ Hash?
readonly
The output produced by the task (only if successful).
-
#status ⇒ Symbol
readonly
The status of the task execution (:completed, :failed, :canceled).
Class Method Summary collapse
-
.canceled ⇒ TaskExecutionResult
Creates a canceled execution result.
-
.failure(failure) ⇒ TaskExecutionResult
Creates a failed execution result.
-
.from_hash(hash) ⇒ TaskExecutionResult
Creates a task execution result from a hash.
-
.success(output) ⇒ TaskExecutionResult
Creates a successful execution result.
Instance Method Summary collapse
-
#canceled? ⇒ Boolean
Checks if the task execution was canceled.
-
#failed? ⇒ Boolean
Checks if the task execution failed.
-
#initialize(status:, output: nil, failure: nil) ⇒ TaskExecutionResult
constructor
A new instance of TaskExecutionResult.
-
#successful? ⇒ Boolean
Checks if the task execution was successful.
-
#to_h ⇒ Hash
Returns a hash representation of the execution result.
Constructor Details
#initialize(status:, output: nil, failure: nil) ⇒ TaskExecutionResult
Returns a new instance of TaskExecutionResult.
20 21 22 23 24 |
# File 'lib/agentic/task_execution_result.rb', line 20 def initialize(status:, output: nil, failure: nil) @status = status @output = output @failure = failure end |
Instance Attribute Details
#failure ⇒ TaskFailure? (readonly)
Returns The failure details (only if failed).
15 16 17 |
# File 'lib/agentic/task_execution_result.rb', line 15 def failure @failure end |
#output ⇒ Hash? (readonly)
Returns The output produced by the task (only if successful).
12 13 14 |
# File 'lib/agentic/task_execution_result.rb', line 12 def output @output end |
#status ⇒ Symbol (readonly)
Returns The status of the task execution (:completed, :failed, :canceled).
9 10 11 |
# File 'lib/agentic/task_execution_result.rb', line 9 def status @status end |
Class Method Details
.canceled ⇒ TaskExecutionResult
Creates a canceled execution result
42 43 44 |
# File 'lib/agentic/task_execution_result.rb', line 42 def self.canceled new(status: :canceled) end |
.failure(failure) ⇒ TaskExecutionResult
Creates a failed execution result
36 37 38 |
# File 'lib/agentic/task_execution_result.rb', line 36 def self.failure(failure) new(status: :failed, failure: failure) end |
.from_hash(hash) ⇒ TaskExecutionResult
Creates a task execution result from a hash
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/agentic/task_execution_result.rb', line 49 def self.from_hash(hash) # Handle the case where hash is not actually a hash (could be nil, Integer, etc.) return new(status: :completed) unless hash.is_a?(Hash) # Convert string keys to symbols if necessary hash = hash.transform_keys(&:to_sym) if hash.keys.first.is_a?(String) failure = hash[:failure] ? TaskFailure.from_hash(hash[:failure]) : nil new( status: hash[:status] || :completed, output: hash[:output], failure: failure ) end |
.success(output) ⇒ TaskExecutionResult
Creates a successful execution result
29 30 31 |
# File 'lib/agentic/task_execution_result.rb', line 29 def self.success(output) new(status: :completed, output: output) end |
Instance Method Details
#canceled? ⇒ Boolean
Checks if the task execution was canceled
78 79 80 |
# File 'lib/agentic/task_execution_result.rb', line 78 def canceled? @status == :canceled end |
#failed? ⇒ Boolean
Checks if the task execution failed
72 73 74 |
# File 'lib/agentic/task_execution_result.rb', line 72 def failed? @status == :failed end |
#successful? ⇒ Boolean
Checks if the task execution was successful
66 67 68 |
# File 'lib/agentic/task_execution_result.rb', line 66 def successful? @status == :completed end |
#to_h ⇒ Hash
Returns a hash representation of the execution result
84 85 86 87 88 89 90 |
# File 'lib/agentic/task_execution_result.rb', line 84 def to_h { status: @status, output: @output, failure: @failure&.to_h } end |