Class: Smith::Workflow::DeterministicStep
- Inherits:
-
Object
- Object
- Smith::Workflow::DeterministicStep
- Defined in:
- lib/smith/workflow/deterministic_step.rb
Instance Attribute Summary collapse
-
#allowed_routes ⇒ Object
readonly
Returns the value of attribute allowed_routes.
-
#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:, **options) ⇒ DeterministicStep
constructor
A new instance of DeterministicStep.
-
#last_agent_model ⇒ Object
The model id / provider that actually served the most recent serial
execute :agentstep (post fallback resolution), or nil if no serial agent step has run. - #last_agent_provider ⇒ Object
- #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:, **options) ⇒ DeterministicStep
Returns a new instance of DeterministicStep.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/smith/workflow/deterministic_step.rb', line 9 def initialize(context:, session_messages:, tool_results:, state:, **) () transition = [:transition] @context = context @session_messages = @tool_results = tool_results @current_state = state @transition_name = transition ? transition.name : .fetch(:transition_name) @allowed_routes = snapshot_allowed_routes(transition ? transition.deterministic_routes : [:allowed_routes]) @last_agent_execution = [:last_agent_execution] @context_writes = {} @routed_to = nil @outcome = nil end |
Instance Attribute Details
#allowed_routes ⇒ Object (readonly)
Returns the value of attribute allowed_routes.
6 7 8 |
# File 'lib/smith/workflow/deterministic_step.rb', line 6 def allowed_routes @allowed_routes end |
#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
68 69 70 |
# File 'lib/smith/workflow/deterministic_step.rb', line 68 def fail!(, retryable: nil, kind: nil, details: nil) raise DeterministicStepFailure.new(, retryable: retryable, kind: kind, details: details) end |
#last_agent_model ⇒ Object
The model id / provider that actually served the most recent serial
execute :agent step (post fallback resolution), or nil if no serial
agent step has run. Symmetric with last_output, which returns that
step's content; use these to attribute an agent output to its model.
28 29 30 |
# File 'lib/smith/workflow/deterministic_step.rb', line 28 def last_agent_model @last_agent_execution && @last_agent_execution[:model] end |
#last_agent_provider ⇒ Object
32 33 34 |
# File 'lib/smith/workflow/deterministic_step.rb', line 32 def last_agent_provider @last_agent_execution && @last_agent_execution[:provider] end |
#last_output ⇒ Object Also known as: output
36 37 38 39 40 41 |
# File 'lib/smith/workflow/deterministic_step.rb', line 36 def last_output return @last_output if defined?(@last_output) msg = .reverse.find { |m| m[:role] == :assistant || m["role"] == "assistant" } @last_output = msg && (msg[:content] || msg["content"]) end |
#read_context(key) ⇒ Object
45 46 47 |
# File 'lib/smith/workflow/deterministic_step.rb', line 45 def read_context(key) @context_writes.key?(key) ? @context_writes[key] : context[key] end |
#route_to(transition_name) ⇒ Object
55 56 57 58 59 |
# File 'lib/smith/workflow/deterministic_step.rb', line 55 def route_to(transition_name) raise WorkflowError, "route_to already called with :#{@routed_to}" if @routed_to @routed_to = route_target_for(transition_name) end |
#write_context(key, value) ⇒ Object
49 50 51 52 53 |
# File 'lib/smith/workflow/deterministic_step.rb', line 49 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
61 62 63 64 65 66 |
# File 'lib/smith/workflow/deterministic_step.rb', line 61 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 |