Right this moment, we’re excited to announce help for DoWhile loops in Amazon Bedrock Flows. With this highly effective new functionality, you may create iterative, condition-based workflows immediately inside your Amazon Bedrock flows, utilizing Immediate nodes, AWS Lambda capabilities, Amazon Bedrock Brokers, Amazon Bedrock Flows inline code, Amazon Bedrock Data Bases, Amazon Easy Storage Service (Amazon S3), and different Amazon Bedrock nodes throughout the loop construction. This characteristic avoids the necessity for complicated workarounds, enabling subtle iteration patterns that use the complete vary of Amazon Bedrock Flows parts. Duties like content material refinement, recursive evaluation, and multi-step processing can now seamlessly combine AI mannequin calls, customized code execution, and data retrieval in repeated cycles. By offering loop help with various node sorts, this characteristic simplifies generative AI software growth and accelerates enterprise adoption of complicated, adaptive AI options.
Organizations utilizing Amazon Bedrock Flows can now use DoWhile loops to design and deploy workflows for constructing extra scalable and environment friendly generative AI functions totally throughout the Amazon Bedrock atmosphere whereas reaching the next:
- Iterative processing – Execute repeated operations till particular situations are met, enabling dynamic content material refinement and recursive enhancements
- Conditional logic – Implement subtle decision-making inside flows based mostly on AI outputs and enterprise guidelines
- Complicated use circumstances – Handle multi-step generative AI workflows that require repeated execution and refinement
- Builder-friendly – Create and handle loops by each the Amazon Bedrock API and AWS Administration Console within the traces
- Observability – Make use of seamless monitoring of loop iterations, situations, and execution paths
On this submit, we talk about the advantages of this new characteristic, and present easy methods to use DoWhile loops in Amazon Bedrock Flows.
Advantages of DoWhile loops in Amazon Bedrock Flows
Utilizing DoWhile loops in Amazon Bedrock Flows affords the next advantages:
- Simplified move management – Create subtle iterative workflows with out complicated orchestration or exterior providers
- Versatile processing – Allow dynamic, condition-based execution paths that may adapt based mostly on AI outputs and enterprise guidelines
- Enhanced growth expertise – Assist customers construct complicated iterative workflows by an intuitive interface, with out requiring exterior workflow administration
Answer overview
Within the following sections, we present easy methods to create a easy Amazon Bedrock move utilizing Do-while loops with Lambda capabilities. Our instance showcases a sensible software the place we assemble a move that generates a weblog submit on a given subject in an iterative method till sure acceptance standards are fulfilled. The move demonstrates the ability of mixing several types of Amazon Bedrock Flows nodes inside a loop construction, the place Immediate nodes generate and fine-tune the weblog submit, Inline Code nodes permit writing customized Python code to research the outputs, and S3 Storage nodes allow storing every model of the weblog submit through the course of for reference. The DoWhile loop continues to execute till the standard of the weblog submit meets the situation set within the loop controller. This instance illustrates how completely different move nodes can work collectively inside a loop to progressively rework knowledge till desired situations are met, offering a basis for understanding extra complicated iterative workflows with numerous node mixtures.
Stipulations
Earlier than implementing the brand new capabilities, be sure to have the next:
After these parts are in place, you may proceed with utilizing Amazon Bedrock Flows with DoWhile loop capabilities in your generative AI use case.
Create your move utilizing DoWhile Loop nodes
Full the next steps to create your move:
- On the Amazon Bedrock console, select Flows below Builder instruments within the navigation pane.
- Create a brand new move, for instance, dowhile-loop-demo. For detailed directions on making a move, see Amazon Bedrock Flows is now usually accessible with enhanced security and traceability.
- Add a DoWhile loop node.
- Add further nodes in line with the answer workflow (mentioned within the subsequent part).
Amazon Bedrock supplies completely different node sorts to construct your immediate move. For this instance, we use a DoWhile Loop node for calling several types of nodes for a generative AI-powered software, which creates a weblog submit on a given subject and checks the standard in each loop. There’s one DoWhile Loop node within the move. This new node kind is on the Nodes tab within the left pane, as proven within the following screenshot.

DoWhile loop workflow
A DoWhile loop consists of two components: the loop and the loop controller. The loop controller validates the logic for the loop and decides whether or not to proceed or exit the loop. On this instance, it’s executing Immediate, Inline Code, S3 Storage nodes every time the loop is executed.
Let’s undergo this move step-by-step, as illustrated within the previous screenshot:
- A consumer asks to put in writing a weblog submit on a particular subject (for instance, utilizing the next immediate: {“subject”: “AWS Lambda”, “Viewers”: “Chief Expertise Officer”, “word_count”:”500}). This immediate is shipped to the Immediate node (Content_Generator).
- The Immediate node (Content_Generator) writes a weblog submit based mostly on the immediate utilizing one of many Amazon Bedrock supplied LLMs (equivalent to Amazon Nova or Anthropic’s Claude) and is shipped to the Loop Enter node. That is the entry level to the DoWhile Loop node.
- Three steps occur in tandem:
- The Loop Enter node forwards the weblog submit content material to a different Immediate node (Blog_Analysis_Rating) for score the submit based mostly on standards talked about as a part of the immediate. The output of this Immediate node is JSON code like the next instance. The output of a Immediate node is all the time of kind String. You’ll be able to modify the immediate to get several types of output in line with your wants. Nevertheless, it’s also possible to ask the LLM to output a single score quantity.
- The weblog submit is shipped to the move output throughout each iteration. That is the ultimate model at any time when the loop situation will not be met (exiting the loop) or the tip of most loop iterations.
- On the similar time, the output of the earlier Immediate node (Content_Generator) is forwarded to a different Immediate node (Blog_Refinement) by the Loop Enter node. This node recreates or modifies the weblog submit based mostly on the suggestions from the evaluation.
- The output of the Immediate node (Blog_Analysis_Rating) is fed into the Inline Code node to extract the mandatory score and return that as a quantity or different data required for checking the situation contained in the loop controller as enter variables (for instance, a score).
Python code contained in the Inline Code should be handled as untrusted, and acceptable parsing, validation, and knowledge dealing with needs to be applied.
- The output of the Inline Code node is fed into the loop situation contained in the loop controller to validate towards the situation we arrange contained in the proceed loop. On this instance, we’re checking for a score lower than or equal to 9 for the generated weblog submit. You’ll be able to verify as much as 5 situations. Moreover, a most loop iterations parameter makes positive that loop doesn’t proceed infinitely.
- The step consists of two components:
- A Immediate node (Blog_Refinement) forwards the newly generated weblog submit to loopinput contained in the loop controller.
- The loop controller shops the model of the submit in Amazon S3 for future reference and evaluating the completely different variations generated.
- This path will execute if one of many situations is met contained in the proceed loop and most loop iterations. If this continues, then the brand new modified weblog submit from earlier is forwarded to the enter discipline within the Loop Enter node as LoopInput and the loop continues.
- The ultimate output is produced after the DoWhile loop situation is met or most variety of iterations are accomplished. The output will likely be last model of the weblog submit.
You’ll be able to see the output as proven within the following screenshot. The system additionally supplies entry to node execution traces, providing detailed insights into every processing step, real-time efficiency metrics, and highlighting points that will have occurred through the move’s execution. Traces might be enabled utilizing an API and despatched to an Amazon CloudWatch log. Within the API, set the enableTrace discipline to true in an InvokeFlow request. Every flowOutputEvent within the response is returned alongside a flowTraceEvent.

You’ve now efficiently created and executed an Amazon Bedrock move utilizing DoWhile Loop nodes. You may also use Amazon Bedrock APIs to programmatically execute this move. For extra particulars on easy methods to configure flows, see Amazon Bedrock Flows is now usually accessible with enhanced security and traceability.
Issues
When working with DoWhile Loop nodes in Amazon Bedrock Flows, the next are the essential issues to notice:
- DoWhile Loop nodes don’t help nested loops (loops inside loops)
- Every loop controller can consider as much as 5 enter situations for its exit standards
- A most iteration restrict should be specified to assist forestall infinite loops and allow managed execution
Conclusion
The combination of DoWhile loops in Amazon Bedrock Flows marks a major development in iterative workflow capabilities, enabling subtle loop-based processing that may incorporate Immediate nodes, Inline Code nodes, S3 Storage nodes, Lambda capabilities, brokers, DoWhile Loop nodes, and Data Base nodes. This enhancement responds on to enterprise clients’ wants for dealing with complicated, repetitive duties inside their AI workflows, serving to builders create adaptive, condition-based options with out requiring exterior orchestration instruments. By offering help for iterative processing patterns, DoWhile loops assist organizations construct extra subtle AI functions that may refine outputs, carry out recursive operations, and implement complicated enterprise logic immediately throughout the Amazon Bedrock atmosphere. This highly effective addition to Amazon Bedrock Flows democratizes the event of superior AI workflows, making iterative AI processing extra accessible and manageable throughout organizations.
DoWhile loops in Amazon Bedrock Flows are actually accessible in all of the AWS Areas the place Amazon Bedrock Flows is supported, aside from the AWS Gov Cloud (US) Area. To get began, open the Amazon Bedrock console or Amazon Bedrock APIs to start constructing flows with Amazon Bedrock Flows. To study extra, check with Create your first move in Amazon Bedrock and Observe every step in your move by viewing its hint in Amazon Bedrock.
We’re excited to see the revolutionary functions you’ll construct with these new capabilities. As all the time, we welcome your suggestions by AWS re:Put up for Amazon Bedrock or your common AWS contacts. Be a part of the generative AI builder group at group.aws to share your experiences and study from others.
Concerning the authors
Shubhankar Sumar is a Senior Options Architect at AWS, the place he focuses on architecting generative AI-powered options for enterprise software program and SaaS corporations throughout the UK. With a powerful background in software program engineering, Shubhankar excels at designing safe, scalable, and cost-effective multi-tenant techniques on the cloud. His experience lies in seamlessly integrating cutting-edge generative AI capabilities into current SaaS functions, serving to clients keep on the forefront of technological innovation.
Jesse Manders is a Senior Product Supervisor on Amazon Bedrock, the AWS Generative AI developer service. He works on the intersection of AI and human interplay with the purpose of making and bettering generative AI services and products to satisfy our wants. Beforehand, Jesse held engineering staff management roles at Apple and Lumileds, and was a senior scientist in a Silicon Valley startup. He has an M.S. and Ph.D. from the College of Florida, and an MBA from the College of California, Berkeley, Haas Faculty of Enterprise.
Eric Li is a Software program Improvement Engineer II at AWS, the place he builds core capabilities for Amazon Bedrock and SageMaker to help generative AI functions at scale. His work focuses on designing safe, observable, and cost-efficient techniques that assist builders and enterprises undertake generative AI with confidence. He’s captivated with advancing developer experiences for constructing with massive language fashions, making it simpler to combine AI into production-ready cloud functions.


