Class: Smith::Workflow::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, from:, to:) ⇒ Transition

Returns a new instance of Transition.



10
11
12
13
14
15
# File 'lib/smith/workflow/transition.rb', line 10

def initialize(name, from:, to:, &)
  @name = name
  @from = from
  @to = to
  instance_eval(&) if block_given?
end

Instance Attribute Details

#agent_nameObject (readonly)

Returns the value of attribute agent_name.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def agent_name
  @agent_name
end

#agent_optsObject (readonly)

Returns the value of attribute agent_opts.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def agent_opts
  @agent_opts
end

#deterministic_blockObject (readonly)

Returns the value of attribute deterministic_block.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def deterministic_block
  @deterministic_block
end

#deterministic_kindObject (readonly)

Returns the value of attribute deterministic_kind.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def deterministic_kind
  @deterministic_kind
end

#failure_transitionObject (readonly)

Returns the value of attribute failure_transition.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def failure_transition
  @failure_transition
end

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def from
  @from
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def name
  @name
end

#optimization_configObject (readonly)

Returns the value of attribute optimization_config.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def optimization_config
  @optimization_config
end

#orchestrator_configObject (readonly)

Returns the value of attribute orchestrator_config.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def orchestrator_config
  @orchestrator_config
end

#router_configObject (readonly)

Returns the value of attribute router_config.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def router_config
  @router_config
end

#success_transitionObject (readonly)

Returns the value of attribute success_transition.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def success_transition
  @success_transition
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def to
  @to
end

#workflow_classObject (readonly)

Returns the value of attribute workflow_class.



6
7
8
# File 'lib/smith/workflow/transition.rb', line 6

def workflow_class
  @workflow_class
end

Instance Method Details

#deterministic?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/smith/workflow/transition.rb', line 90

def deterministic?
  !@deterministic_block.nil?
end

#execute(agent_name, **opts) ⇒ Object

Raises:



17
18
19
20
21
22
# File 'lib/smith/workflow/transition.rb', line 17

def execute(agent_name, **opts)
  raise WorkflowError, "transition cannot declare both execute and compute/run" if @deterministic_block

  @agent_name = agent_name
  @agent_opts = opts
end

#nested?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/smith/workflow/transition.rb', line 102

def nested?
  !@workflow_class.nil?
end

#on_failure(transition_name) ⇒ Object



28
29
30
# File 'lib/smith/workflow/transition.rb', line 28

def on_failure(transition_name)
  @failure_transition = transition_name
end

#on_success(transition_name) ⇒ Object



24
25
26
# File 'lib/smith/workflow/transition.rb', line 24

def on_success(transition_name)
  @success_transition = transition_name
end

#optimize(generator:, evaluator:, max_rounds:, evaluator_schema:, improvement_threshold: nil, evaluator_context: nil, before_eval: nil, on_exhaustion: :raise, on_converged: :raise, on_threshold: :raise) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/smith/workflow/transition.rb', line 49

def optimize(generator:, evaluator:, max_rounds:, evaluator_schema:,
             improvement_threshold: nil,
             evaluator_context: nil,
             before_eval: nil,
             on_exhaustion: :raise,
             on_converged: :raise,
             on_threshold: :raise)
  validate_optimize_conflicts!
  validate_optimize_controls!(generator, evaluator, max_rounds, evaluator_schema)
  validate_optimize_exit_modes!(on_exhaustion: on_exhaustion, on_converged: on_converged,
                                on_threshold: on_threshold)
  validate_optimize_evaluator_context!(evaluator_context)
  validate_optimize_before_eval!(before_eval)

  @optimization_config = {
    generator: generator, evaluator: evaluator, max_rounds: max_rounds,
    evaluator_schema: evaluator_schema, improvement_threshold: improvement_threshold,
    evaluator_context: evaluator_context,
    before_eval: before_eval,
    on_exhaustion: on_exhaustion,
    on_converged: on_converged,
    on_threshold: on_threshold
  }
end

#optimized?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/smith/workflow/transition.rb', line 98

def optimized?
  !@optimization_config.nil?
end

#orchestrate(**opts) ⇒ Object



74
75
76
77
78
# File 'lib/smith/workflow/transition.rb', line 74

def orchestrate(**opts)
  validate_orchestrate_conflicts!
  validate_orchestrate_controls!(opts)
  @orchestrator_config = opts
end

#orchestrated?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/smith/workflow/transition.rb', line 94

def orchestrated?
  !@orchestrator_config.nil?
end

#parallel?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/smith/workflow/transition.rb', line 110

def parallel?
  agent_opts&.dig(:parallel) == true
end

#route(agent_name, routes:, confidence_threshold:, fallback:) ⇒ Object

Raises:



32
33
34
35
36
37
# File 'lib/smith/workflow/transition.rb', line 32

def route(agent_name, routes:, confidence_threshold:, fallback:)
  raise WorkflowError, "transition cannot declare both route and compute/run" if @deterministic_block

  @agent_name = agent_name
  @router_config = { routes: routes, confidence_threshold: confidence_threshold, fallback: fallback }
end

#routed?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/smith/workflow/transition.rb', line 106

def routed?
  !@router_config.nil?
end

#workflow(klass) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
47
# File 'lib/smith/workflow/transition.rb', line 39

def workflow(klass)
  raise WorkflowError, "workflow binding must be a Class" unless klass.is_a?(Class)
  raise WorkflowError, "workflow binding must be a Smith::Workflow subclass" unless klass < Workflow
  raise WorkflowError, "transition cannot declare both workflow and execute" if @agent_name && !@router_config
  raise WorkflowError, "transition cannot declare both workflow and route" if @router_config
  raise WorkflowError, "transition cannot declare both workflow and compute/run" if @deterministic_block

  @workflow_class = klass
end