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
In a nutshell
  • 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 TimeoutSeconds stop hung calls; Retry and Catch handle 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.

TaskstartStep Functionsreasoning loopeach stepAmazon Bedrockreason and actlow confidenceHuman reviewapprove or correctapprovedResult

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:

ReasonBedrock InvokeModelchosen actionChoice statewhich toolcallActLambda toolobservationReasonChoice statefinal answerDone
  • 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

Circuit breaker states: closed passes calls through; after too many failures, counted in DynamoDB, it opens and returns a fallback immediately; after a cool down it goes half open and lets a test call through, closing again if that call succeeds.

SafeguardImplemented withStops
Stopping conditionStep Functions counter checked in a Choice state; maximum iterationsEndless reasoning loops and runaway cost
TimeoutLambda function timeout; TimeoutSeconds and HeartbeatSeconds on Step Functions statesA tool or model call that hangs
Resource boundaryIAM policy on the workflow and tool roles, scoped to named models and resourcesThe model reaching data or actions it should not
Circuit breakerFailure count kept in DynamoDB; skip the failing dependency while openRepeated calls to a broken service
Error handlingRetry with backoff and Catch to a fallback stateOne 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.

Watch out

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.

WorkflowStep FunctionswaitForTaskTokenNotify reviewerSNS or email with tokenreviewsReviewerweb appapprove or rejectAPI GatewayLambdaSendTaskSuccessWorkflow
  1. A task uses the .waitForTaskToken integration and passes the task token to a notification or a review queue.
  2. The workflow pauses, with no compute running while it waits.
  3. The reviewer's decision reaches an API Gateway endpoint, and a Lambda function calls SendTaskSuccess or SendTaskFailure with the token.
  4. 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.

PatternHuman roleExample
Approval gateApproves before the action runsRefund above a threshold
Review on exceptionChecks only low confidence outputsDocument fields below a score
AugmentationEdits a model draftSupport reply drafted by the FM
Feedback loopRates after the factThumbs 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 .waitForTaskToken with API Gateway and Lambda calling SendTaskSuccess.
  • "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 TimeoutSeconds stop hung calls; Retry and Catch handle errors.
  • IAM is the hard resource boundary for any action an FM can trigger.
  • Human approval uses .waitForTaskToken and SendTaskSuccess or SendTaskFailure.
  • API Gateway endpoints collect user feedback that improves the system over time.
Exam tip

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 .waitForTaskToken task, and the approval handler calls SendTaskSuccess or SendTaskFailure with 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.