What does it do?

Loops let you conditionally repeat parts of your Wordapp. You can use them to create complex interactions, like asking the user for input until they give you the right answer, or generating content until it meets a certain criteria.

Loops are a powerful tool for creating dynamic, interactive Wordapps. They let you build complex logic into your Wordapp, and can help you create more engaging and useful experiences. They also let you take advantage of the full power of AI, by allowing you to iterate on the content it generates. This pattern lives at the core of every agent.

We’ve got some examples of how to make the most of loops in our recipes, specifically the chatbot and basic agent recipes.

How do I use it?

A loop has two parts, a condition and an action. The condition determines how long to repeat the action, and the action is what you want to repeat.

To create a loop, type /loop in the editor, and hit Enter. You’ll be prompted to fill in a name and the condition and action for the loop.

Options

A number of options appear in the sidebar when you create a loop. Here’s what they mean:

Name

The name of the loop. You’ll need this later if you want to @mention the output of the loop.

Type

There are five types of condition you can use to determine when to stop the loop:

Condition typeHow it works
CountStops after a fixed number of iterations
MatchStops when two values are equal, typically at least one a @mention set elsewhere
ContainsStops when one value contains another, used for text comparisons
RelativeCompares two numeric inputs, with sub-options for the comparison operator (e.g. >, <)
ListLoops once for every element in a list, giving the action each such element, one at a time

A generation takes all the data that’s appeared in the Wordapp so far and passes it to your AI model of choice. The model then generates new content based on what it’s seen.

To create a generation, type /generation in the editor, and hit Enter. You’ll be prompted to fill in some details about the generation, like its name and the model you want to use, further explained below. Once you run the Wordapp, the model will be fed all the content above the generation and generate new content based on it, which you can then reference with a @mention.

Outputs

Loops produce a list-type output, containing all the outputs produced from the action of the loop.