Orchestrating Agent Patterns with Step Functions
This lesson shows how AWS Step Functions gives explicit, auditable control over reasoning loops and agent design patterns, with the developer deciding the structure while the model fills in the reasoning.
Learning outcomes
After completing this lesson, you will be able to:
- Implement a ReAct loop as a state machine.
- Break chain-of-thought into auditable stages.
- Implement routing, parallelisation and other agent design patterns.
ReAct as a state machine
A ReAct loop maps naturally to states. A Task state calls the model (with the Bedrock Converse integration or a Lambda function) with the conversation and tool definitions. A Choice state checks the stop reason: if it is tool_use, a Task state runs the requested tool (often a Lambda function chosen by name), appends the result to the conversation and loops back; if it is end_turn, the workflow returns the answer. A counter in the state increments every loop, and a Choice state ends the loop when it reaches a maximum.
Every step appears in the execution history with inputs and outputs, so the reasoning path can be audited and failures pinpointed. Retry and Catch fields on each Task handle transient errors.
The following diagram shows a ReAct loop in a Step Functions workflow, with its iteration limit.

ReAct in Step Functions
Chain-of-thought stages and structured reasoning
Chain-of-thought prompting asks a model to reason step by step, but the reasoning remains hidden inside one long response, where errors are hard to find and impossible to test individually. Complex problems can instead be decomposed into explicit stages orchestrated by AWS Step Functions. A planning call produces a list of steps as JSON; a Map state executes each step, each possibly a model call or a tool call; a verification call checks the intermediate results against the plan; and a synthesis call writes the final answer.
Each stage's output is validated before the next stage runs, for example by checking that the plan is valid JSON with the required fields. The result turns hidden reasoning into a sequence of observable, testable steps: each stage can be logged, retried on failure, given its own model and timeout, and evaluated separately, and the execution history shows exactly where a wrong answer originated.
Other agent design patterns
Routing uses a classification call and a Choice state. Parallelization uses a Parallel state to run independent model calls, such as checking a document for legal, financial and safety issues at once, and merges the results. Orchestrator-workers uses a Map state over sub-tasks produced by an orchestrator call. Evaluator-optimizer loops a generation call and an evaluation call until the evaluation passes or a limit is reached.
Standard workflows suit long-running agents (up to a year) and support callbacks for human input; Express workflows suit high-volume, short executions of up to five minutes. The following table summarises the mapping of patterns to states.
| Pattern | Step Functions construct |
|---|---|
| ReAct loop | Task (model) + Choice on stopReason + Task (tool) + iteration counter |
| Plan and execute | Task (plan) + Map (steps) + Task (verify) |
| Routing | Task (classify) + Choice |
| Parallelization | Parallel state |
| Evaluator-optimizer | Loop of generate and evaluate Tasks with a limit |
| Human input | Task with .waitForTaskToken (Standard workflows) |
Patterns as states
Auditable reasoning
A bank wants an agent that investigates suspicious transactions by querying three internal systems. Regulators require a complete record of each step and the agent must never make more than ten tool calls per case.
A Step Functions Standard workflow implementing the ReAct loop with an iteration counter satisfies both: the execution history records every model call, tool call and result, and a Choice state stops the loop at ten calls, routing the case to a human analyst.
Which state runs several independent tool calls at the same time?
Show answer
A Parallel state. A Map state runs the same steps for each item.
Exam Tips
Remember for the exam
- ReAct in Step Functions: model Task, Choice on stopReason, tool Task, counter.
- Execution history gives an auditable reasoning path.
- Parallel state for independent calls; Map for per-step or per-item work.
- Callbacks for human input need Standard workflows.