State Machines for Tool Workflows
About 40 min
Goal
By the end of this lesson, you can represent a multi-step tool workflow as explicit states and transitions and detect invalid moves, loops, and terminal outcomes.
A board game makes some moves legal only from certain positions. If your piece is still at START, you cannot claim the reward reserved for FINISH just because someone writes "finished" on a card. The game board and transition rules determine which moves are valid.
A state machine gives a software workflow that same explicit structure. A state says where the workflow currently is, an event proposes what happened next, and a transition rule decides whether that move is legal. A guard is an extra condition on an otherwise possible move—for example, approval must match the current order and refund amount before the workflow may enter an approved state.
This explicit structure matters as soon as a workflow can call more than one tool, because a free-form “model decides the next step” loop is difficult to audit.