Class: Legion::LLM::Routing::Outcome::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/llm/routing/outcome.rb

Overview

Immutable classified action. outcome preserves the originating ProviderOutcome for emission/diagnostics (never re-classified downstream).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(disposition:, outcome:, exclusions: [], global_transition: nil, rejection: nil) ⇒ Action

Returns a new instance of Action.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/legion/llm/routing/outcome.rb', line 51

def initialize(disposition:, outcome:, exclusions: [], global_transition: nil, rejection: nil, **)
  case disposition
  when :success
    raise ArgumentError, 'success carries no rejection/transition' if rejection || global_transition
  when :retry
    raise ArgumentError, 'retry carries no rejection' if rejection
  when :terminal
    raise ArgumentError, 'terminal requires a rejection' if rejection.nil?
    raise ArgumentError, 'terminal carries no global transition' if global_transition
  else
    raise ArgumentError, "unknown disposition: #{disposition.inspect}"
  end

  @disposition = disposition
  @outcome = outcome
  @exclusions = exclusions.freeze
  @global_transition = global_transition
  @rejection = rejection
  freeze
end

Instance Attribute Details

#dispositionObject (readonly)

Returns the value of attribute disposition.



37
38
39
# File 'lib/legion/llm/routing/outcome.rb', line 37

def disposition
  @disposition
end

#exclusionsObject (readonly)

Returns the value of attribute exclusions.



37
38
39
# File 'lib/legion/llm/routing/outcome.rb', line 37

def exclusions
  @exclusions
end

#global_transitionObject (readonly)

Returns the value of attribute global_transition.



37
38
39
# File 'lib/legion/llm/routing/outcome.rb', line 37

def global_transition
  @global_transition
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



37
38
39
# File 'lib/legion/llm/routing/outcome.rb', line 37

def outcome
  @outcome
end

#rejectionObject (readonly)

Returns the value of attribute rejection.



37
38
39
# File 'lib/legion/llm/routing/outcome.rb', line 37

def rejection
  @rejection
end

Class Method Details

.retry(exclusions:, outcome:, global_transition: nil) ⇒ Object



43
44
45
# File 'lib/legion/llm/routing/outcome.rb', line 43

def self.retry(exclusions:, outcome:, global_transition: nil, **)
  new(disposition: :retry, exclusions: exclusions, global_transition: global_transition, outcome: outcome)
end

.success(outcome:) ⇒ Object



39
40
41
# File 'lib/legion/llm/routing/outcome.rb', line 39

def self.success(outcome:, **)
  new(disposition: :success, outcome: outcome)
end

.terminal(rejection:, outcome:) ⇒ Object



47
48
49
# File 'lib/legion/llm/routing/outcome.rb', line 47

def self.terminal(rejection:, outcome:, **)
  new(disposition: :terminal, rejection: rejection, outcome: outcome)
end

Instance Method Details

#retry?Boolean

Returns:

  • (Boolean)


73
# File 'lib/legion/llm/routing/outcome.rb', line 73

def retry?(**) = @disposition == :retry

#success?Boolean

Returns:

  • (Boolean)


72
# File 'lib/legion/llm/routing/outcome.rb', line 72

def success?(**) = @disposition == :success

#terminal?Boolean

Returns:

  • (Boolean)


74
# File 'lib/legion/llm/routing/outcome.rb', line 74

def terminal?(**) = @disposition == :terminal