Class: Smith::Workflow::DeterministicStep
- Inherits:
-
Object
- Object
- Smith::Workflow::DeterministicStep
- Defined in:
- lib/smith/workflow/deterministic_step.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#context_writes ⇒ Object
readonly
Returns the value of attribute context_writes.
-
#current_state ⇒ Object
readonly
Returns the value of attribute current_state.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#routed_to ⇒ Object
readonly
Returns the value of attribute routed_to.
-
#session_messages ⇒ Object
readonly
Returns the value of attribute session_messages.
-
#tool_results ⇒ Object
readonly
Returns the value of attribute tool_results.
-
#transition_name ⇒ Object
readonly
Returns the value of attribute transition_name.
Instance Method Summary collapse
- #fail!(message, retryable: nil, kind: nil, details: nil) ⇒ Object
-
#initialize(context:, session_messages:, tool_results:, state:, transition_name:) ⇒ DeterministicStep
constructor
A new instance of DeterministicStep.
- #last_output ⇒ Object (also: #output)
- #read_context(key) ⇒ Object
- #route_to(transition_name) ⇒ Object
- #write_context(key, value) ⇒ Object
- #write_outcome(kind:, payload:) ⇒ Object
Constructor Details
#initialize(context:, session_messages:, tool_results:, state:, transition_name:) ⇒ DeterministicStep
Returns a new instance of DeterministicStep.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/smith/workflow/deterministic_step.rb', line 9 def initialize(context:, session_messages:, tool_results:, state:, transition_name:) @context = context @session_messages = @tool_results = tool_results @current_state = state @transition_name = transition_name @context_writes = {} @routed_to = nil @outcome = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def context @context end |
#context_writes ⇒ Object (readonly)
Returns the value of attribute context_writes.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def context_writes @context_writes end |
#current_state ⇒ Object (readonly)
Returns the value of attribute current_state.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def current_state @current_state end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def outcome @outcome end |
#routed_to ⇒ Object (readonly)
Returns the value of attribute routed_to.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def routed_to @routed_to end |
#session_messages ⇒ Object (readonly)
Returns the value of attribute session_messages.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def @session_messages end |
#tool_results ⇒ Object (readonly)
Returns the value of attribute tool_results.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def tool_results @tool_results end |
#transition_name ⇒ Object (readonly)
Returns the value of attribute transition_name.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def transition_name @transition_name end |
Instance Method Details
#fail!(message, retryable: nil, kind: nil, details: nil) ⇒ Object
52 53 54 |
# File 'lib/smith/workflow/deterministic_step.rb', line 52 def fail!(, retryable: nil, kind: nil, details: nil) raise DeterministicStepFailure.new(, retryable: retryable, kind: kind, details: details) end |
#last_output ⇒ Object Also known as: output
20 21 22 23 24 25 |
# File 'lib/smith/workflow/deterministic_step.rb', line 20 def last_output return @last_output if defined?(@last_output) msg = .reverse.find { |m| m[:role] == :assistant || m[:role] == "assistant" } @last_output = msg&.dig(:content) end |
#read_context(key) ⇒ Object
29 30 31 |
# File 'lib/smith/workflow/deterministic_step.rb', line 29 def read_context(key) @context_writes.key?(key) ? @context_writes[key] : context[key] end |
#route_to(transition_name) ⇒ Object
39 40 41 42 43 |
# File 'lib/smith/workflow/deterministic_step.rb', line 39 def route_to(transition_name) raise WorkflowError, "route_to already called with :#{@routed_to}" if @routed_to @routed_to = transition_name end |
#write_context(key, value) ⇒ Object
33 34 35 36 37 |
# File 'lib/smith/workflow/deterministic_step.rb', line 33 def write_context(key, value) raise WorkflowError, "write_context key must be a Symbol, got #{key.class}" unless key.is_a?(Symbol) @context_writes[key] = value end |
#write_outcome(kind:, payload:) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/smith/workflow/deterministic_step.rb', line 45 def write_outcome(kind:, payload:) raise WorkflowError, "write_outcome kind must be a Symbol, got #{kind.class}" unless kind.is_a?(Symbol) raise WorkflowError, "write_outcome already called with :#{@outcome[:kind]}" if @outcome @outcome = { kind: kind, payload: payload } end |