Class: Soka::Result
- Inherits:
-
Object
- Object
- Soka::Result
- Defined in:
- lib/soka/result.rb
Overview
Represents the result of an agent’s reasoning process
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#final_answer ⇒ Object
readonly
Returns the value of attribute final_answer.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#thoughts ⇒ Object
readonly
Returns the value of attribute thoughts.
Instance Method Summary collapse
-
#execution_details ⇒ Hash
Get execution details.
-
#failed? ⇒ Boolean
Check if the result failed.
-
#initialize(attributes = {}) ⇒ Result
constructor
Initialize a new Result instance.
-
#iterations ⇒ Integer
Get the number of iterations (thoughts).
-
#max_iterations_reached? ⇒ Boolean
Check if max iterations were reached.
-
#successful? ⇒ Boolean
Check if the result is successful.
-
#summary ⇒ String
Get a summary of the result.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_json ⇒ String
Convert to JSON string.
Constructor Details
#initialize(attributes = {}) ⇒ Result
Initialize a new Result instance
16 17 18 19 20 21 22 23 24 |
# File 'lib/soka/result.rb', line 16 def initialize(attributes = {}) @input = attributes[:input] @thoughts = attributes[:thoughts] || [] @final_answer = attributes[:final_answer] @status = attributes[:status] || :pending @error = attributes[:error] @execution_time = attributes[:execution_time] @created_at = Time.now end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def error @error end |
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def execution_time @execution_time end |
#final_answer ⇒ Object (readonly)
Returns the value of attribute final_answer.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def final_answer @final_answer end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def input @input end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def status @status end |
#thoughts ⇒ Object (readonly)
Returns the value of attribute thoughts.
6 7 8 |
# File 'lib/soka/result.rb', line 6 def thoughts @thoughts end |
Instance Method Details
#execution_details ⇒ Hash
Get execution details
74 75 76 77 78 79 80 |
# File 'lib/soka/result.rb', line 74 def execution_details { iterations: iterations, time: execution_time ? "#{execution_time.round(2)}s" : 'N/A', status: status } end |
#failed? ⇒ Boolean
Check if the result failed
36 37 38 |
# File 'lib/soka/result.rb', line 36 def failed? status == :failed end |
#iterations ⇒ Integer
Get the number of iterations (thoughts)
50 51 52 |
# File 'lib/soka/result.rb', line 50 def iterations thoughts.length end |
#max_iterations_reached? ⇒ Boolean
Check if max iterations were reached
42 43 44 |
# File 'lib/soka/result.rb', line 42 def max_iterations_reached? status == :max_iterations_reached end |
#successful? ⇒ Boolean
Check if the result is successful
30 31 32 |
# File 'lib/soka/result.rb', line 30 def successful? status == :success end |
#summary ⇒ String
Get a summary of the result
68 69 70 |
# File 'lib/soka/result.rb', line 68 def summary (status) end |
#to_h ⇒ Hash
Convert to hash representation
56 57 58 |
# File 'lib/soka/result.rb', line 56 def to_h build_hash.compact end |
#to_json ⇒ String
Convert to JSON string
62 63 64 |
# File 'lib/soka/result.rb', line 62 def to_json(*) Oj.dump(to_h, mode: :compat) end |