iteration.mdx


Overview

The Iteration component is designed to facilitate iterative workflows over segmented text inputs. Its primary functionality is to split a given text input into smaller text segments based on a configurable delimiter, then execute a predefined internal workflow for each segment. This is particularly useful when the number of iterations depends dynamically on the content size or segmentation rather than a fixed loop count.

Typical use cases include:


Detailed Explanation

Main Component: Iteration

The Iteration component acts as a container and controller for looping workflows over text segments.

Inputs

Multiple inputs can be specified, and the component supports various delimiters for splitting text:

Delimiter

Description

Comma (,)

Default delimiter

Line break

New line character

Tab

Tab character (\t)

Underline

Underscore (_)

Forward slash

Slash (/)

Dash

Hyphen (-)

Semicolon

Semicolon (;)

Functionality

  1. Text Segmentation: The input text(s) are split into segments based on the chosen delimiter.

  2. Workflow Iteration: For each text segment, the internal workflow is executed once.

  3. Encapsulation: The internal workflow is encapsulated and invisible outside the Iteration component.


Internal Components

IterationItem


Building Internal Workflow


Usage Example

Suppose you want to translate a long document paragraph-by-paragraph using an LLM:

  1. Add an Iteration component.

  2. Define the input variable as a Reference to the document text.

  3. Set the delimiter to "Line break" to split the document into paragraphs.

  4. Build an internal workflow containing a Generate component that performs the translation.

  5. Inside the Generate component, reference the current paragraph via IterationItem.

  6. Run the Iteration component to translate each paragraph sequentially.


Important Implementation Details


Interaction with Other Components


Visual Diagram

flowchart TD
    Iteration["Iteration Component"]
    IterationItem["IterationItem (Internal Loop Manager)"]
    Segmentation["Text Segmentation\n(by delimiter)"]
    InternalWorkflow["Internal Workflow\n(Components)"]
    ExternalInputs["External Inputs\n(Reference / Text)"]

    ExternalInputs --> Iteration
    Iteration --> Segmentation
    Segmentation --> IterationItem
    IterationItem --> InternalWorkflow
    InternalWorkflow --> IterationItem

    style Iteration fill:#f9f,stroke:#333,stroke-width:2px
    style IterationItem fill:#bbf,stroke:#333,stroke-width:1.5px,stroke-dasharray: 5 5
    style Segmentation fill:#bfb,stroke:#333,stroke-width:1.5px
    style InternalWorkflow fill:#ffb,stroke:#333,stroke-width:1.5px
    style ExternalInputs fill:#eee,stroke:#333,stroke-width:1.5px

Summary

The Iteration component is a powerful tool to automate repetitive workflows on segmented textual data. It abstracts the complexity of dynamic loops controlled by text content size, enabling modular and scalable processing pipelines such as multi-part generation, translation, or analysis. The internal IterationItem component manages iteration state, while the encapsulated workflow ensures clean separation from the broader system.

This design fosters reusable, maintainable, and flexible workflows adaptable to various natural language processing tasks within the system.