Class: Soka::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/soka/result.rb

Overview

Represents the result of an agent’s reasoning process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Result

Initialize a new Result instance

Parameters:

  • attributes (Hash) (defaults to: {})

    Result attributes

Options Hash (attributes):

  • :input (String)

    The original input

  • :thoughts (Array)

    Array of thought objects

  • :final_answer (String)

    The final answer

  • :status (Symbol)

    The result status

  • :error (String)

    Error message if failed

  • :execution_time (Float)

    Time taken in seconds



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

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/soka/result.rb', line 6

def error
  @error
end

#execution_timeObject (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_answerObject (readonly)

Returns the value of attribute final_answer.



6
7
8
# File 'lib/soka/result.rb', line 6

def final_answer
  @final_answer
end

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/soka/result.rb', line 6

def input
  @input
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/soka/result.rb', line 6

def status
  @status
end

#thoughtsObject (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_detailsHash

Get execution details

Returns:

  • (Hash)


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

Returns:

  • (Boolean)


36
37
38
# File 'lib/soka/result.rb', line 36

def failed?
  status == :failed
end

#iterationsInteger

Get the number of iterations (thoughts)

Returns:

  • (Integer)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


30
31
32
# File 'lib/soka/result.rb', line 30

def successful?
  status == :success
end

#summaryString

Get a summary of the result

Returns:

  • (String)


68
69
70
# File 'lib/soka/result.rb', line 68

def summary
  status_message_for(status)
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)


56
57
58
# File 'lib/soka/result.rb', line 56

def to_h
  build_hash.compact
end

#to_jsonString

Convert to JSON string

Returns:

  • (String)


62
63
64
# File 'lib/soka/result.rb', line 62

def to_json(*)
  Oj.dump(to_h, mode: :compat)
end