The Loop logic element in Optimizely Opal's workflow agent builder interface automates repetitive tasks within your workflows. Specifically, it functions as a "For Each" loop, iterating over a collection of items (such as URLs, keywords, or data sets) and executing a defined set of actions for each item. This capability significantly streamlines complex processes and lets you process multiple items without manual intervention.
You can add the following in a Loop:
- Specialized agent steps – Run an agent on each item.
- Conditional steps – Branch logic within each iteration.
- Nested loops – Add loops within loops for multi-level iteration.
When to use loops
Loops are ideal for scenarios where you perform the same operation on multiple pieces of data. Consider using a loop in the following situations:
- Iterating through data sets – Systematically go through a collection of data points, performing a specific action for each one.
- Processing lists of items – Apply the same action (for example, create content, update status, or generate reports) to each item in a collection, such as a list of assets, campaigns, keywords, variations, or segments.
- Generating multiple variations – Create multiple versions of content or other outputs based on different parameters from a list of inputs.
How to add a loop to a workflow
After you create a workflow agent from scratch and configure workflow, you can optionally add loops to your workflow.
- Drag and drop a Loop from the Logic section into the workspace.
- (Optional) Rename your loop and add a Description.
- Connect an agent that provides the collection of items to iterate on. Click the Agent and click a connector circle. Drag the connector to the Loop.
-
Drag and drop an agent, condition, or another loop into the loop.
- Click Save to update your workflow agent.
Best practices and considerations
Keep the following in mind when working with loops:
- Nesting – Use up to three nested loops to create complex iterative processes.
- Performance – Be mindful of the number of iterations. Very large loops impact the workflow agent's execution time.
- Variable scope – Understand how variables defined inside and outside the loop are accessed and modified to ensure correct data flow.
Example: dynamic landing page generator
Example scenario – Your marketing team runs a campaign targeting various customer segments. For example, small business owners, enterprise clients, and non-profit organizations. Each segment requires a slightly different landing page with tailored messaging, hero images, and calls-to-action (CTAs) to maximize conversion. Manually creating and maintaining dozens of unique landing pages is time-consuming and prone to errors.
You can create a workflow agent that uses a Loop to automate the generation of these dynamic landing pages.
The Loop takes a list of your customer segments as its input from the previous agent. Each segment profile includes attributes such as the following:
-
segment_name– Small Business -
hero_image_url– url_to_small_biz_image.jpg -
headline_text– Boost Your Small Business Growth -
cta_button_text– Start Your Free Trial -
target_audience_description– Entrepreneurs and startups
Loop body (for each segment):
- Fetch template – The agent starts with a base landing page template.
-
Customize content – The Customize landing page agent dynamically inserts the
headline_text,cta_button_text, andtarget_audience_descriptioninto the appropriate sections of the landing page template. -
Update visuals – The Update Visuals agent replaces the
hero_image_url, which is the default hero image on the page. -
Publish page – The Publish page agent publishes the customized landing page with a unique URL. For example,
yourdomain.com/campaign/small-business. - Output – The Loop completes, and you have a set of fully customized landing pages, each perfectly tailored to a specific customer segment, all generated automatically by a single workflow agent.
This example workflow agent lets you rapidly deploy highly relevant landing pages, significantly improving campaign performance and conversion rates while freeing your team from repetitive manual tasks.
Article is closed for comments.