Class: LittleGhost::RunResult

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/run_result.rb,
lib/little_ghost/run_result.rb

Overview

RunResult gives callers one final view of an agent or workflow invocation. It includes the response, usage, updated conversation, state, and any validated structured value.

Use #output when the caller should accept either structured or textual agents. It returns the validated structured value when present and #text otherwise.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, stop_reason:, usage:, messages:, state:, structured_result: nil) ⇒ RunResult

Returns a new instance of RunResult.



15
16
17
# File 'lib/little_ghost/run_result.rb', line 15

def initialize(message:, stop_reason:, usage:, messages:, state:, structured_result: nil)
  super
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def message
  @message
end

#messagesObject (readonly)

Returns the value of attribute messages

Returns:

  • (Object)

    the current value of messages



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def messages
  @messages
end

#stateObject (readonly)

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def state
  @state
end

#stop_reasonObject (readonly)

Returns the value of attribute stop_reason

Returns:

  • (Object)

    the current value of stop_reason



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def stop_reason
  @stop_reason
end

#structured_resultObject (readonly)

Returns the value of attribute structured_result

Returns:

  • (Object)

    the current value of structured_result



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def structured_result
  @structured_result
end

#usageObject (readonly)

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



14
15
16
# File 'lib/little_ghost/run_result.rb', line 14

def usage
  @usage
end

Instance Method Details

#outputObject

Uses the structured value when present and otherwise #text.



30
31
32
# File 'lib/little_ghost/run_result.rb', line 30

def output
  structured? ? structured_result.value : text
end

#structured?Boolean

Indicates whether the run produced a validated structured result.

Returns:

  • (Boolean)


25
26
27
# File 'lib/little_ghost/run_result.rb', line 25

def structured?
  !structured_result.nil?
end

#textObject

Reads the final message text, or an empty string when no message exists.



20
21
22
# File 'lib/little_ghost/run_result.rb', line 20

def text
  message&.text.to_s
end