Skip to content

Commit fc7f56e

Browse files
improvement(docs): loop and parallel var reference syntax (#2975)
1 parent 8429040 commit fc7f56e

File tree

2 files changed

+87
-19
lines changed

2 files changed

+87
-19
lines changed

apps/docs/content/docs/en/blocks/loop.mdx

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,44 @@ Choose between four types of loops:
124124
3. Drag other blocks inside the loop container
125125
4. Connect the blocks as needed
126126

127-
### Accessing Results
127+
### Referencing Loop Data
128128

129-
After a loop completes, you can access aggregated results:
129+
There's an important distinction between referencing loop data from **inside** vs **outside** the loop:
130130

131-
- **`<loop.results>`**: Array of results from all loop iterations
131+
<Tabs items={['Inside the Loop', 'Outside the Loop']}>
132+
<Tab>
133+
**Inside the loop**, use `<loop.>` references to access the current iteration context:
134+
135+
- **`<loop.index>`**: Current iteration number (0-based)
136+
- **`<loop.currentItem>`**: Current item being processed (forEach only)
137+
- **`<loop.items>`**: Full collection being iterated (forEach only)
138+
139+
```
140+
// Inside a Function block within the loop
141+
const idx = <loop.index>; // 0, 1, 2, ...
142+
const item = <loop.currentItem>; // Current item
143+
```
144+
145+
<Callout type="info">
146+
These references are only available for blocks **inside** the loop container. They give you access to the current iteration's context.
147+
</Callout>
148+
</Tab>
149+
<Tab>
150+
**Outside the loop** (after it completes), reference the loop block by its name to access aggregated results:
151+
152+
- **`<LoopBlockName.results>`**: Array of results from all iterations
153+
154+
```
155+
// If your loop block is named "Process Items"
156+
const allResults = <processitems.results>;
157+
// Returns: [result1, result2, result3, ...]
158+
```
159+
160+
<Callout type="info">
161+
After the loop completes, use the loop's block name (not `loop.`) to access the collected results. The block name is normalized (lowercase, no spaces).
162+
</Callout>
163+
</Tab>
164+
</Tabs>
132165

133166
## Example Use Cases
134167

@@ -184,28 +217,29 @@ Variables (i=0) → Loop (While i<10) → Agent (Process) → Variables (i++)
184217
</ul>
185218
</Tab>
186219
<Tab>
220+
Available **inside** the loop only:
187221
<ul className="list-disc space-y-2 pl-6">
188222
<li>
189-
<strong>loop.currentItem</strong>: Current item being processed
223+
<strong>{"<loop.index>"}</strong>: Current iteration number (0-based)
190224
</li>
191225
<li>
192-
<strong>loop.index</strong>: Current iteration number (0-based)
226+
<strong>{"<loop.currentItem>"}</strong>: Current item being processed (forEach only)
193227
</li>
194228
<li>
195-
<strong>loop.items</strong>: Full collection (forEach loops)
229+
<strong>{"<loop.items>"}</strong>: Full collection (forEach only)
196230
</li>
197231
</ul>
198232
</Tab>
199233
<Tab>
200234
<ul className="list-disc space-y-2 pl-6">
201235
<li>
202-
<strong>loop.results</strong>: Array of all iteration results
236+
<strong>{"<blockname.results>"}</strong>: Array of all iteration results (accessed via block name)
203237
</li>
204238
<li>
205239
<strong>Structure</strong>: Results maintain iteration order
206240
</li>
207241
<li>
208-
<strong>Access</strong>: Available in blocks after the loop
242+
<strong>Access</strong>: Available in blocks after the loop completes
209243
</li>
210244
</ul>
211245
</Tab>

apps/docs/content/docs/en/blocks/parallel.mdx

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,44 @@ Choose between two types of parallel execution:
7676
3. Drag a single block inside the parallel container
7777
4. Connect the block as needed
7878

79-
### Accessing Results
79+
### Referencing Parallel Data
8080

81-
After a parallel block completes, you can access aggregated results:
81+
There's an important distinction between referencing parallel data from **inside** vs **outside** the parallel block:
8282

83-
- **`<parallel.results>`**: Array of results from all parallel instances
83+
<Tabs items={['Inside the Parallel', 'Outside the Parallel']}>
84+
<Tab>
85+
**Inside the parallel**, use `<parallel.>` references to access the current instance context:
86+
87+
- **`<parallel.index>`**: Current instance number (0-based)
88+
- **`<parallel.currentItem>`**: Item for this instance (collection-based only)
89+
- **`<parallel.items>`**: Full collection being distributed (collection-based only)
90+
91+
```
92+
// Inside a Function block within the parallel
93+
const idx = <parallel.index>; // 0, 1, 2, ...
94+
const item = <parallel.currentItem>; // This instance's item
95+
```
96+
97+
<Callout type="info">
98+
These references are only available for blocks **inside** the parallel container. They give you access to the current instance's context.
99+
</Callout>
100+
</Tab>
101+
<Tab>
102+
**Outside the parallel** (after it completes), reference the parallel block by its name to access aggregated results:
103+
104+
- **`<ParallelBlockName.results>`**: Array of results from all instances
105+
106+
```
107+
// If your parallel block is named "Process Tasks"
108+
const allResults = <processtasks.results>;
109+
// Returns: [result1, result2, result3, ...]
110+
```
111+
112+
<Callout type="info">
113+
After the parallel completes, use the parallel's block name (not `parallel.`) to access the collected results. The block name is normalized (lowercase, no spaces).
114+
</Callout>
115+
</Tab>
116+
</Tabs>
84117

85118
## Example Use Cases
86119

@@ -98,11 +131,11 @@ Parallel (["gpt-4o", "claude-3.7-sonnet", "gemini-2.5-pro"]) → Agent → Evalu
98131

99132
### Result Aggregation
100133

101-
Results from all parallel instances are automatically collected:
134+
Results from all parallel instances are automatically collected and accessible via the block name:
102135

103136
```javascript
104-
// In a Function block after the parallel
105-
const allResults = input.parallel.results;
137+
// In a Function block after a parallel named "Process Tasks"
138+
const allResults = <processtasks.results>;
106139
// Returns: [result1, result2, result3, ...]
107140
```
108141

@@ -158,25 +191,26 @@ Understanding when to use each:
158191
</ul>
159192
</Tab>
160193
<Tab>
194+
Available **inside** the parallel only:
161195
<ul className="list-disc space-y-2 pl-6">
162196
<li>
163-
<strong>parallel.currentItem</strong>: Item for this instance
197+
<strong>{"<parallel.index>"}</strong>: Instance number (0-based)
164198
</li>
165199
<li>
166-
<strong>parallel.index</strong>: Instance number (0-based)
200+
<strong>{"<parallel.currentItem>"}</strong>: Item for this instance (collection-based only)
167201
</li>
168202
<li>
169-
<strong>parallel.items</strong>: Full collection (collection-based)
203+
<strong>{"<parallel.items>"}</strong>: Full collection (collection-based only)
170204
</li>
171205
</ul>
172206
</Tab>
173207
<Tab>
174208
<ul className="list-disc space-y-2 pl-6">
175209
<li>
176-
<strong>parallel.results</strong>: Array of all instance results
210+
<strong>{"<blockname.results>"}</strong>: Array of all instance results (accessed via block name)
177211
</li>
178212
<li>
179-
<strong>Access</strong>: Available in blocks after the parallel
213+
<strong>Access</strong>: Available in blocks after the parallel completes
180214
</li>
181215
</ul>
182216
</Tab>

0 commit comments

Comments
 (0)