Class: Agentic::TaskFailure
- Inherits:
-
Object
- Object
- Agentic::TaskFailure
- Defined in:
- lib/agentic/task_failure.rb
Overview
Represents a failure that occurred during task execution
Instance Attribute Summary collapse
-
#context ⇒ Hash
readonly
Additional context about the failure.
-
#message ⇒ String
readonly
The failure message.
-
#timestamp ⇒ Time
readonly
When the failure occurred.
-
#type ⇒ String
readonly
The type of failure.
Class Method Summary collapse
-
.from_exception(exception, context = {}) ⇒ TaskFailure
Creates a task failure from an exception.
-
.from_hash(hash) ⇒ TaskFailure
Creates a task failure from a hash.
Instance Method Summary collapse
-
#initialize(message:, type:, context: {}) ⇒ TaskFailure
constructor
Initializes a new task failure.
-
#to_h ⇒ Hash
Returns a serializable representation of the failure.
Constructor Details
#initialize(message:, type:, context: {}) ⇒ TaskFailure
Initializes a new task failure
17 18 19 20 21 22 |
# File 'lib/agentic/task_failure.rb', line 17 def initialize(message:, type:, context: {}) @message = @type = type @timestamp = Time.now @context = context end |
Instance Attribute Details
#context ⇒ Hash (readonly)
Additional context about the failure
9 10 11 |
# File 'lib/agentic/task_failure.rb', line 9 def context @context end |
#message ⇒ String (readonly)
The failure message
9 10 11 |
# File 'lib/agentic/task_failure.rb', line 9 def @message end |
#timestamp ⇒ Time (readonly)
When the failure occurred
9 10 11 |
# File 'lib/agentic/task_failure.rb', line 9 def @timestamp end |
#type ⇒ String (readonly)
The type of failure
9 10 11 |
# File 'lib/agentic/task_failure.rb', line 9 def type @type end |
Class Method Details
.from_exception(exception, context = {}) ⇒ TaskFailure
Creates a task failure from an exception
39 40 41 42 43 44 45 46 47 |
# File 'lib/agentic/task_failure.rb', line 39 def self.from_exception(exception, context = {}) new( message: exception., type: exception.class.name, context: context.merge( backtrace: exception.backtrace&.first(10) ) ) end |
.from_hash(hash) ⇒ TaskFailure
Creates a task failure from a hash
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/agentic/task_failure.rb', line 52 def self.from_hash(hash) # Handle the case where hash is not actually a hash return new(message: "Unknown error", type: "UnknownError") 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) new( message: hash[:message] || "Unknown error", type: hash[:type] || "UnknownError", context: hash[:context] || {} ) end |
Instance Method Details
#to_h ⇒ Hash
Returns a serializable representation of the failure
26 27 28 29 30 31 32 33 |
# File 'lib/agentic/task_failure.rb', line 26 def to_h { message: @message, type: @type, timestamp: @timestamp.iso8601, context: @context } end |