Class: Agentic::TaskExecutionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/task_execution_result.rb

Overview

Value object representing the execution result of a task

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, output: nil, failure: nil) ⇒ TaskExecutionResult

Returns a new instance of TaskExecutionResult.

Parameters:

  • status (Symbol)

    The status of the task execution

  • output (Hash, nil) (defaults to: nil)

    The output produced by the task

  • failure (TaskFailure, nil) (defaults to: nil)

    The failure details



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

#failureTaskFailure? (readonly)

Returns The failure details (only if failed).

Returns:

  • (TaskFailure, nil)

    The failure details (only if failed)



15
16
17
# File 'lib/agentic/task_execution_result.rb', line 15

def failure
  @failure
end

#outputHash? (readonly)

Returns The output produced by the task (only if successful).

Returns:

  • (Hash, nil)

    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

#statusSymbol (readonly)

Returns The status of the task execution (:completed, :failed, :canceled).

Returns:

  • (Symbol)

    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

.canceledTaskExecutionResult

Creates a canceled execution result

Returns:



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

Parameters:

Returns:



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

Parameters:

  • hash (Hash)

    The hash representation of a task execution result

Returns:



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

Parameters:

  • output (Hash)

    The task output

Returns:



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

Returns:

  • (Boolean)

    True if canceled, false otherwise



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

Returns:

  • (Boolean)

    True if failed, false otherwise



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

Returns:

  • (Boolean)

    True if successful, false otherwise



66
67
68
# File 'lib/agentic/task_execution_result.rb', line 66

def successful?
  @status == :completed
end

#to_hHash

Returns a hash representation of the execution result

Returns:

  • (Hash)

    The execution result as a hash



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