Step Watcher
StepWatcher is the conversation state machine. It manages the current step, tracks timers and round counts, handles branching, and returns a StepDecision after each user turn.
Defined in lib/agent/step-watcher.ts.
StepDecision
Lifecycle
begin()
Called at session start. Finds the Start step, sets it as current, starts any timers, and returns{ action: "advance" } with the opening instruction.
onUserTurn()
Called after every user message. Returns aStepDecision based on the current step type:
| Step type | Decision logic |
|---|---|
start | Advance to next step |
burst | Increment round count; advance when rounds complete |
timer | Check elapsed time; advance if duration exceeded |
opentalk | Continue; return evaluate if next is If/Else or Categorize |
ifelse | Return evaluate |
categorize | Return evaluate |
end | Return end (peek for webhook) |
webhook | Return webhook |
advanceToBranch(evaluationStep, branchKey)
Called by the agent after an LLM evaluation resolves a branch. Takes the evaluation step and the selected branch key ("true"/"false" or "cat_0", "cat_1", etc.) and advances to the corresponding next step.
Step progression for burst
Branching
Timer behavior
When a Timer step starts,StepWatcher records stepStartedAt and sets a JavaScript timeout. If the timer expires before the user triggers advancement, the step auto-advances on the next user turn check.