Implementation and Integration · Topic 2 of 8
Structured Reasoning, Safeguarded Workflows and Human Review
Use Step Functions for ReAct loops and chain of thought, add stopping conditions, timeouts, IAM limits and circuit breakers, and build human review steps.
- 6 min
- Includes a diagram
- ReAct alternates reasoning and tool actions; chain of thought makes the model reason step by step.
- Step Functions makes reasoning loops explicit, auditable and limited with counters, Choice states and timeouts.
- Lambda timeouts and state
TimeoutSecondsstop hung calls;RetryandCatchhandle errors.
What it is
Complex problems need more than one model call. A structured reasoning system breaks the problem into steps, lets the model think and act in a loop, and keeps the loop under control.
This page covers three linked skills: building the reasoning loop, putting hard limits around it, and inserting people where the model should not decide alone. AWS Step Functions is the common thread, because it gives each step state, retries, timeouts and an audit history.
How it works
ReAct and chain of thought
Chain of thought asks the model to reason step by step before it answers. It improves multi step problems such as calculations or policy checks, and the reasoning can be logged for review.
ReAct (reason plus act) alternates thought, action and observation. The model reasons about what it needs, calls a tool, reads the result and reasons again.
Step Functions can run a ReAct loop explicitly:
- A Task state calls Bedrock through the optimized integration and stores the model output in the state.
- A Choice state reads the output and branches to a tool, back to reasoning, or to the end.
- A Map state runs independent sub tasks in parallel, such as analyzing each section of a contract.
Every thought and action appears in the execution history, which makes the loop easy to debug.
Safeguards around the loop

| Safeguard | Implemented with | Stops |
|---|---|---|
| Stopping condition | Step Functions counter checked in a Choice state; maximum iterations | Endless reasoning loops and runaway cost |
| Timeout | Lambda function timeout; TimeoutSeconds and HeartbeatSeconds on Step Functions states | A tool or model call that hangs |
| Resource boundary | IAM policy on the workflow and tool roles, scoped to named models and resources | The model reaching data or actions it should not |
| Circuit breaker | Failure count kept in DynamoDB; skip the failing dependency while open | Repeated calls to a broken service |
| Error handling | Retry with backoff and Catch to a fallback state | One failed call ending the workflow |
A circuit breaker has three states. Closed passes calls through; after too many failures it opens and returns a fallback immediately; after a cool down it lets a test call through (half open) and closes again if that call succeeds.
IAM is the only hard boundary. Even if a prompt injection convinces the model to call a delete tool, the tool's role should not hold that permission.
A system prompt that says "never call more than five tools" is a suggestion to the model, not a control. Enforce limits in the workflow and in IAM.
Human in the loop review
Some decisions need a person: high value refunds, medical or legal text, or any output the model scored with low confidence. Step Functions supports this with the callback pattern.
- A task uses the
.waitForTaskTokenintegration and passes the task token to a notification or a review queue. - The workflow pauses, with no compute running while it waits.
- The reviewer's decision reaches an API Gateway endpoint, and a Lambda function calls
SendTaskSuccessorSendTaskFailurewith the token. - The workflow continues on the approve or reject branch.
Set a timeout on the waiting state so an unanswered review escalates.
Feedback and human augmentation
Not every human touch is a gate. Feedback collection lets users rate or correct answers through an API Gateway endpoint that writes to a store such as DynamoDB or Amazon S3. Teams use that data to improve prompts, retrieval and evaluation sets.
Human augmentation patterns keep the person in charge and use the model as an assistant: the model drafts, the expert edits and sends. Confidence based routing sends only uncertain cases to people, so experts spend time where it matters.
| Pattern | Human role | Example |
|---|---|---|
| Approval gate | Approves before the action runs | Refund above a threshold |
| Review on exception | Checks only low confidence outputs | Document fields below a score |
| Augmentation | Edits a model draft | Support reply drafted by the FM |
| Feedback loop | Rates after the fact | Thumbs up or down in the app |
Amazon Augmented AI (Amazon A2I) also provides managed human review workflows for ML predictions, if a scenario asks for a ready made review UI and workforce.
How the exam asks about this
- "The agent sometimes loops calling the same tool and costs spike" -> a maximum iteration counter in the Step Functions workflow and a state timeout.
- "Refunds above a set amount need a manager's approval before processing, with no polling" -> Step Functions
.waitForTaskTokenwith API Gateway and Lambda callingSendTaskSuccess. - "A downstream CRM API is failing and every request still waits for it" -> a circuit breaker that returns a fallback while the API is unhealthy.
Common mistakes
Relying on prompt instructions as guardrails. The model can ignore them. Iteration limits, timeouts and IAM are enforced outside the model.
Polling for approvals. A loop that checks a database every minute wastes executions. The callback pattern pauses the workflow at no compute cost.
No timeout on human steps. People go on vacation. Add a timeout and an escalation branch.
Giving the tool role broad permissions. A wildcard policy turns a prompt injection into a data breach. Scope each role to the exact resources.
What to remember for the exam
- ReAct alternates reasoning and tool actions; chain of thought makes the model reason step by step.
- Step Functions makes reasoning loops explicit, auditable and limited with counters, Choice states and timeouts.
- Lambda timeouts and state
TimeoutSecondsstop hung calls;RetryandCatchhandle errors. - IAM is the hard resource boundary for any action an FM can trigger.
- Human approval uses
.waitForTaskTokenandSendTaskSuccessorSendTaskFailure. - API Gateway endpoints collect user feedback that improves the system over time.
When a question pairs "approval" with "Step Functions", look for the task token callback. When it pairs "feedback" with "API Gateway", look for an endpoint that stores ratings for later analysis.
Check yourself
How do you stop a Step Functions ReAct loop from running forever?
Keep an iteration counter in the state, check it in a Choice state, and set timeouts on the states.
How does a workflow wait for a manager's approval without polling?
It uses a
.waitForTaskTokentask, and the approval handler callsSendTaskSuccessorSendTaskFailurewith the token.What does an open circuit breaker do?
It stops calling the failing dependency and returns a fallback right away until a cool down test call succeeds.
Topic 2 of 8 in Implementation and Integration
Test yourself on Implementation and Integration
The full AWS AIP-C01 question bank has 827 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.