Class: Mistri::Result

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

Overview

The outcome of a run. A run either finishes, or suspends because a tool needs a human's approval, or stops on abort or budget. Suspension is a first-class outcome, not an error: the run returns immediately with awaiting_approval? true and the pending calls, so nothing blocks waiting for a decision that may come days later.

Reads delegate to the final message, so result.text works whether the run completed or suspended. output is a task's validated value, nil on plain runs. usage is the run's own accounting: every persisted turn plus compaction calls, summed (a resumed run counts from the resume; task sums across its fix passes). handed_off marks a run that ended because an ends_turn tool executed: complete, but the final word was the tool's, and whatever comes next (a human's answer) arrives as the next run's input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, status:, pending: [], output: nil, usage: Usage.zero, handed_off: false) ⇒ Result

Returns a new instance of Result.



19
20
21
22
# File 'lib/mistri/result.rb', line 19

def initialize(message:, status:, pending: [], output: nil, usage: Usage.zero,
               handed_off: false)
  super
end

Instance Attribute Details

#handed_offObject (readonly)

Returns the value of attribute handed_off

Returns:

  • (Object)

    the current value of handed_off



18
19
20
# File 'lib/mistri/result.rb', line 18

def handed_off
  @handed_off
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



18
19
20
# File 'lib/mistri/result.rb', line 18

def message
  @message
end

#outputObject (readonly)

Returns the value of attribute output

Returns:

  • (Object)

    the current value of output



18
19
20
# File 'lib/mistri/result.rb', line 18

def output
  @output
end

#pendingObject (readonly)

Returns the value of attribute pending

Returns:

  • (Object)

    the current value of pending



18
19
20
# File 'lib/mistri/result.rb', line 18

def pending
  @pending
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



18
19
20
# File 'lib/mistri/result.rb', line 18

def status
  @status
end

#usageObject (readonly)

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



18
19
20
# File 'lib/mistri/result.rb', line 18

def usage
  @usage
end

Instance Method Details

#aborted?Boolean

Returns:

  • (Boolean)


26
# File 'lib/mistri/result.rb', line 26

def aborted? = status == :aborted

#awaiting_approval?Boolean

Returns:

  • (Boolean)


25
# File 'lib/mistri/result.rb', line 25

def awaiting_approval? = status == :awaiting_approval

#completed?Boolean

Returns:

  • (Boolean)


24
# File 'lib/mistri/result.rb', line 24

def completed? = status == :completed

#error_messageObject



33
# File 'lib/mistri/result.rb', line 33

def error_message = message&.error_message

#errored?Boolean

Returns:

  • (Boolean)


28
# File 'lib/mistri/result.rb', line 28

def errored? = status == :error

#handed_off?Boolean

Returns:

  • (Boolean)


29
# File 'lib/mistri/result.rb', line 29

def handed_off? = handed_off

#stop_reasonObject



32
# File 'lib/mistri/result.rb', line 32

def stop_reason = message&.stop_reason

#stopped_by_budget?Boolean

Returns:

  • (Boolean)


27
# File 'lib/mistri/result.rb', line 27

def stopped_by_budget? = status == :budget

#textObject



31
# File 'lib/mistri/result.rb', line 31

def text = message&.text

#to_sObject



35
# File 'lib/mistri/result.rb', line 35

def to_s = text.to_s

#tool_callsObject



34
# File 'lib/mistri/result.rb', line 34

def tool_calls = message ? message.tool_calls : []