Lesson 2 of 5 Multi-Agent Systems and Agent Safeguards

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.

An auditable ReAct loop in a Step Functions Standard workflow. A Task state calls the model, a Choice state checks the stop reason, a tool Task runs the requested tool and increments a counter, and a second Choice state loops back while fewer than ten tool calls have been made. At the limit, the case goes to a human analyst; the execution history records every call.
The limit of ten calls comes from the scenario above.
Put in order

ReAct in Step Functions

Exam skills 2.1.2 · 2.1.3

Put the states of a ReAct loop built in Step Functions in order.

Log in to try this activity Interactive activities are free with an account.

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.

PatternStep Functions construct
ReAct loopTask (model) + Choice on stopReason + Task (tool) + iteration counter
Plan and executeTask (plan) + Map (steps) + Task (verify)
RoutingTask (classify) + Choice
ParallelizationParallel state
Evaluator-optimizerLoop of generate and evaluate Tasks with a limit
Human inputTask with .waitForTaskToken (Standard workflows)
Match the pairs

Patterns as states

Exam skills 2.1.2 · 2.5.5

Match each agent design pattern with the Step Functions construct that implements it.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.