Agents

How to Build an AI Workflow That Knows What Happens Next

A longer prompt will not preserve the order of work. Save the current stage, allow only named moves, and leave one safe way to resume.

By Vladislav Zhirnov13 min read

Use this when

you need the work to hold up in real use.

Create a small saved workflow whose current stage, allowed next move, stop reason, and resume action remain clear across people and AI sessions.

Headline, Know What Happens Next, beside BUILD, REVIEW, and RELEASE cards where an open track leads to review and a red barrier blocks release.
BUILD can move to REVIEW. A red barrier stops the shortcut to RELEASE.

A product team asks AI to help ship a new checkout flow. The plan is clear. The build looks finished. A new AI session sees the finished files and moves toward release.

One step is missing. Nobody reviewed the work.

The first session knew review came next. That fact lived in the chat, not in the workflow. When the session ended, the order disappeared with it.

The team does not need a longer prompt. It needs a saved answer to four questions: Where is the work now? What may happen next? What must be true first? What should happen if progress stops?

A small workflow state machine gives the team those answers. This guide shows how to make one, block a skipped review, and resume safely from a saved stop record.

Key takeaways

  • Save the current stage instead of asking a new AI session to infer it from chat.
  • Check every requested move against one named next stage and its required evidence.
  • Keep the workflow stage separate from whether a run is blocked, stopped, or done.
  • Test one valid move, one skipped review, and one fresh-session resume before trusting the control.

What is a workflow state machine for AI work?

An AI agent workflow state machine is a saved list of stages and allowed moves. It tells the system where work is, what may happen next, why it stopped, and how it can resume.

The ordinary idea is simple. A product release can move from planning to building, then review, approval, and release. It cannot jump from building straight to release because someone says it looks ready.

AWS Step Functions uses the same core model. A workflow contains states, and transition rules decide which state comes next. Some states end the workflow.

Your team does not need AWS to use the idea. A table, a saved record, and one check at every move can be enough.

The state machine controls order. It does not prove that the work inside each stage was good. Review quality, release proof, and outside actions still need their own checks.

Why is a stage name not enough?

A label can describe the work without controlling it.

Imagine a record that says BUILD. An AI asks to change it to RELEASE. If the system checks only that both names are valid, it will accept the jump. The stage changed, but review never happened.

A real control checks BUILD -> RELEASE. It then compares that request with the allowed next move, BUILD -> REVIEW.

The request should fail. The result should say why it failed and what can happen next.

A checklist has a similar limit. It can remind someone to review. It does not stop a release when the review box is empty. A diagram can show the right order and still let the real process ignore it.

The rule is blunt: if a skipped stage does not change the system's decision, the workflow is still advice.

Which stages should the first workflow use?

Start with one real product flow. Do not model the whole company.

The table below uses a small release path. Each row names the current stage, the next allowed stage, the guard, the owner, and the safe response when the guard fails.

A small guarded release workflow
Current stageAllowed next stageWhat must be true firstOwnerIf the guard failsHow work resumes
INTAKEPLANThe request, wanted result, owner, and limits are saved.Product ownerStop and name the missing answer.Add the answer, then request PLAN again.
PLANBUILDThe plan and acceptance criteria are approved for this version.Product leadStop before work starts.Approve or revise the plan, then request BUILD.
BUILDREVIEWThe result is saved and the review criteria are ready.BuilderStop with the unfinished item.Finish the item, then request REVIEW.
REVIEWAPPROVE or BUILDA reviewer records pass or changes requested.ReviewerStay in REVIEW.Record the verdict, then approve or return to BUILD.
APPROVERELEASEA named owner approves the exact version and target.Accountable ownerStop before the outside action.Get a fresh matching approval, then request RELEASE.
RELEASEDONEThe release receipt and a fresh result check match the intended version.Release ownerMark the result incomplete.Check or repair the release, then request DONE.
DONENoneRequired proof is present and no final issue is open.Accountable ownerKeep the workflow open.Resolve the issue before trying DONE again.

How should the workflow block a skipped review?

Every move should pass through the same check. That includes moves requested by a person, an AI, an automation, and a resumed session.

The check needs three inputs: the saved current stage, the requested next stage, and the guard evidence required for that move.

For the release example, the saved stage is BUILD and the requested stage is RELEASE. The requested move is BUILD -> RELEASE. The table allows only BUILD -> REVIEW, which means only REVIEW after BUILD.

Do not let the AI talk its way around this result. A confident release summary is not a transition rule. Neither is a prompt that says, "Never skip review."

The check has to sit where the status changes. That might be a workflow tool, a task system, an automation, or a person who refuses the move. If the status can change through another path, that path needs the same rule.

The blocked shortcut should name the legal move
ResultReasonAllowed next stage
BLOCKEDRELEASE cannot follow BUILD. Complete REVIEW first.REVIEW

What should a stopped run save?

Sometimes the next move is valid, but the run still cannot continue. The reviewer is away. A required answer is missing. A tool failed. The session is ending.

Do not replace the current stage with a vague PAUSED label. Save the stage and the run status separately. A stopped run in BUILD is different from a stopped run in RELEASE.

The saved values were direct: Run status: STOPPED. Stopped at stage: BUILD. Required next stage: REVIEW.

The stop reason explains why progress ended. The next action tells a fresh person what to do. The acceptance criteria say what a useful result looks like. The evidence reference points to the saved work without stuffing it into the record.

On resume, read this record before reading old chat. Check that every required field is present. Then send BUILD to REVIEW through the same transition rule used during the live run.

The smallest useful stop record
FieldSaved value
Runfixture-run-001
Run statusSTOPPED
Stopped at stageBUILD
Required next stageREVIEW
Stop reasonThe review result was not recorded before the session ended.
Next actionReview the saved build against the release criteria.
Acceptance criteriaA reviewer records pass or changes requested. Release stays blocked until review passes.
Evidence referencefixture-build-result.json

What happened when I tested the three rules?

I ran a small local experiment with made-up release data. It used a temporary file, started one fresh process for the resume check, and made no network or outside-system call.

The test asked the workflow to make three decisions. The results matched the transition table.

The skipped-review result said, "RELEASE cannot follow BUILD. Complete REVIEW first."

The fresh process recovered this next action: "Review the saved build against the release criteria." It did not need hidden context from the first process.

This experiment proves only those three decisions in the small fixture. It does not prove production reliability, security, or review quality. It does not prove that an evidence reference exists or that a live release worked.

That limit matters. A state machine can force the work to visit REVIEW. It cannot make the review thoughtful.

Observed results from the bounded workflow fixture
CaseRequestObserved result
Valid movePLAN to BUILDALLOWED because BUILD was the named next stage.
Skipped reviewBUILD to RELEASEBLOCKED because only REVIEW could follow BUILD.
Fresh-session resumeRead the stopped BUILD record in a new processSAFE_TO_RESUME at REVIEW, with the saved next action and criteria.

What did WarpOS reveal about stage control?

I found the same gap while building WarpOS, my agentic operating-system project for long-running AI work.

At the frozen public version I reviewed, the outer sprint runner had a fixed order: plan, design, execute, release preparation, then retrospective. It could halt at key boundaries. It also saved a reason, a restart command, and checkpoints for a later run.

That is real control at the outer level.

The inner execution helper saved its loop number, stage, checks, stop reason, next action, and recovery summary. But it checked only whether the requested stage name was on an approved list. It did not compare the previous stage with the requested next stage.

In plain language, it could save REVIEW as a real stage. It did not yet prove that TEST had to come before REVIEW.

The audit found another useful warning. Some values written by the full-run checkpoint did not match the allowed values in its own saved-record rules. The checkpoint existed, but the contract around it had drifted.

So the honest conclusion is narrow: WarpOS enforced an ordered outer workflow and saved useful inner state. Its inner stage recorder was not yet a complete guarded transition system at that commit.

The lesson is uncomfortable but useful. Saved state is not the same as guarded state. A record becomes a control only when the next move is checked and a bad move fails.

How can your team build the first version this week?

Choose one workflow that already causes arguments. A release, research review, customer email, or content publication is enough.

Write no more than six working stages, plus one final state. For each stage, name the owner, allowed next move, required evidence, stop behavior, and resume action.

Then plant three tests. Ask for one valid move. Ask to skip one important review or approval. Stop the run, open a fresh session, and resume from the saved record.

The second test must fail. The third test must not need the old chat.

If the table works only when everyone remembers to follow it, you have a useful draft. You do not have a control yet. Connect it to the real status change and run the three tests again.

FAQ

Is a checklist the same as a workflow state machine?

No. A checklist reminds someone what to do. A state machine also decides which move is allowed now. It should refuse a release when the required review has not happened.

How many stages should an AI workflow have?

Start with six working stages or fewer, plus one final state. Add a stage only when it changes the owner, required proof, or next legal move. Too many stages make the workflow harder to use and easier to ignore.

What is a transition guard?

A transition guard is a condition that must be true before work can move to the next stage. A recorded review verdict can guard REVIEW to APPROVE. A matching release approval can guard APPROVE to RELEASE.

Can a prompt enforce the stage order?

No. A prompt can explain or draft the order. Enforcement needs a check where the real status changes. Every person, AI, automation, and resumed session needs to use that same check.

How should an AI workflow resume after it stops?

Read the saved stop record first. Confirm the stopped stage, reason, required next stage, next action, criteria, and evidence references. Then validate the requested move with the same rule used before the stop.

Conclusion

AI should not guess where work stands from the last chat it can see.

Save the current stage. Name the next allowed move. Require a clear condition before the move. If work stops, keep the stage, reason, and one safe next action.

Then test the rule by trying to skip review.

If the workflow blocks the shortcut and a fresh session can resume without guessing, you have something more useful than a diagram. You have a small operating control.

Sources

Next move

Have one workflow that should move faster?

Bring the process, the bottleneck, and the outcome. I can help diagnose it, design the human and AI boundary, build the smallest working MVP, and measure whether it deserves another iteration.

Start with one workflow

About the author

Vladislav Zhirnov smiling outdoors

Vladislav Zhirnov

Product and AI systems leader

Vlad helps founders, product teams, and operations leaders use AI to improve delivery, streamline work, and build useful MVPs.

Related articles

Keep going

All articles