You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/content/docs/en/yaml/blocks/loop.mdx
+74-12Lines changed: 74 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,6 @@ type: object
10
10
required:
11
11
- type
12
12
- name
13
-
- inputs
14
13
- connections
15
14
properties:
16
15
type:
@@ -22,21 +21,23 @@ properties:
22
21
description: Display name for this loop block
23
22
inputs:
24
23
type: object
25
-
required:
26
-
- loopType
24
+
description: Optional. If omitted, defaults will be applied.
27
25
properties:
28
26
loopType:
29
27
type: string
30
28
enum: [for, forEach]
31
29
description: Type of loop to execute
30
+
default: for
32
31
iterations:
33
32
type: number
34
33
description: Number of iterations (for 'for' loops)
34
+
default: 5
35
35
minimum: 1
36
36
maximum: 1000
37
37
collection:
38
38
type: string
39
39
description: Collection to iterate over (for 'forEach' loops)
40
+
default: ""
40
41
maxConcurrency:
41
42
type: number
42
43
description: Maximum concurrent executions
@@ -45,40 +46,48 @@ properties:
45
46
maximum: 10
46
47
connections:
47
48
type: object
48
-
required:
49
-
- loop
50
49
properties:
50
+
# Nested format (recommended)
51
51
loop:
52
52
type: object
53
-
required:
54
-
- start
55
53
properties:
56
54
start:
57
55
type: string
58
56
description: Target block ID to execute inside the loop
59
57
end:
60
58
type: string
61
59
description: Target block ID for loop completion (optional)
60
+
# Direct handle format (alternative)
61
+
loop-start-source:
62
+
type: string | string[]
63
+
description: Target block ID to execute inside the loop (direct format)
64
+
loop-end-source:
65
+
type: string | string[]
66
+
description: Target block ID for loop completion (direct format, optional)
62
67
error:
63
68
type: string
64
69
description: Target block ID for error handling
70
+
note: Use either the nested 'loop' format OR the direct 'loop-start-source' format, not both
65
71
```
66
72
67
73
## Connection Configuration
68
74
69
-
Loop blocks use a special connection format with a `loop` section:
75
+
Loop blocks support two connection formats:
76
+
77
+
### Direct Handle Format (Alternative)
70
78
71
79
```yaml
72
80
connections:
73
-
loop:
74
-
start: <string> # Target block ID to execute inside the loop
75
-
end: <string> # Target block ID after loop completion (optional)
81
+
loop-start-source: <string> # Target block ID to execute inside the loop
82
+
loop-end-source: <string> # Target block ID after loop completion (optional)
76
83
error: <string> # Target block ID for error handling (optional)
77
84
```
78
85
86
+
Both formats work identically. Use whichever you prefer.
87
+
79
88
## Child Block Configuration
80
89
81
-
Blocks inside a loop must have their `parentId` set to the loop block ID:
90
+
Blocks inside a loop must have their `parentId` set to the loop block ID. The `extent` property is automatically set to `'parent'` and doesn't need to be specified:
82
91
83
92
```yaml
84
93
loop-1:
@@ -261,6 +270,59 @@ process-task:
261
270
success: task-completed
262
271
```
263
272
273
+
### Direct Handle Format Example
274
+
275
+
The same loop can be written using the direct handle format:
276
+
277
+
```yaml
278
+
my-loop:
279
+
type: loop
280
+
name: "Process Items"
281
+
inputs:
282
+
loopType: forEach
283
+
collection: <start.items>
284
+
connections:
285
+
loop-start-source: process-item # Direct handle format
286
+
loop-end-source: final-results # Direct handle format
287
+
error: handle-error
288
+
289
+
process-item:
290
+
type: agent
291
+
name: "Process Item"
292
+
parentId: my-loop
293
+
inputs:
294
+
systemPrompt: "Process this item"
295
+
userPrompt: <loop.currentItem>
296
+
model: gpt-4o
297
+
apiKey: '{{OPENAI_API_KEY}}'
298
+
```
299
+
300
+
### Minimal Loop Example (Using Defaults)
301
+
302
+
You can omit the `inputs` section entirely, and defaults will be applied:
303
+
304
+
```yaml
305
+
simple-loop:
306
+
type: loop
307
+
name: "Simple Loop"
308
+
# No inputs section - defaults to loopType: 'for', iterations: 5
309
+
connections:
310
+
loop-start-source: process-step
311
+
loop-end-source: complete
312
+
313
+
process-step:
314
+
type: agent
315
+
name: "Process Step"
316
+
parentId: simple-loop
317
+
inputs:
318
+
systemPrompt: "Execute step"
319
+
userPrompt: "Step <loop.index>"
320
+
model: gpt-4o
321
+
apiKey: '{{OPENAI_API_KEY}}'
322
+
```
323
+
324
+
This loop will execute 5 iterations by default.
325
+
264
326
## Loop Variables
265
327
266
328
Inside loop child blocks, these special variables are available:
0 commit comments