-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathfor-each-simple.yaml
More file actions
149 lines (130 loc) · 4.63 KB
/
Copy pathfor-each-simple.yaml
File metadata and controls
149 lines (130 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# For-Each Simple
#
# This example demonstrates dynamic parallel execution with for-each groups.
# It shows:
# - Processing variable-length arrays with for-each
# - Optional workflow inputs with fallback behavior
# - Loop variables ({{ item }}, {{ _index }}, {{ _key }})
# - Index-based output aggregation
# - Batched parallel execution
# - Accessing for-each outputs in downstream agents
#
# Usage:
# # With explicit items:
# conductor run examples/for-each-simple.yaml --input items='["apple", "banana", "cherry"]'
#
# # Without items (agent generates random topics):
# conductor run examples/for-each-simple.yaml
workflow:
name: for-each-simple
description: Simple demonstration of for-each dynamic parallel execution
version: "1.0.0"
entry_point: item_finder
runtime:
provider: copilot
default_model: claude-sonnet-4.5
limits:
max_iterations: 20
# Optional input: if provided, items are used directly; otherwise generated
input:
items:
type: string
required: false
description: JSON array of items to process (e.g. '["apple", "banana"]')
# For-each group definition
for_each:
- name: item_processors
type: for_each
description: Process each item found by the item_finder
source: item_finder.output.topics # Reference to array in context
as: item # Loop variable name
max_concurrent: 3 # Process 3 items at a time
failure_mode: continue_on_error # Continue even if some items fail
agent:
name: item_processor
model: claude-sonnet-4.5
prompt: |
You are a data processor. Process this item:
Item {{ _index + 1 }}: {{ item }}
Provide a brief analysis and transformation.
output:
original:
type: string
description: Original item value
processed:
type: string
description: Processed/transformed value
analysis:
type: string
description: Brief analysis
routes:
- to: aggregator
agents:
# Agent 1: Resolve items to process (pass-through or generate)
- name: item_finder
description: Returns items to process — uses provided input or generates random topics
model: claude-sonnet-4.5
prompt: |
{% if workflow.input.items %}
The user provided the following items to process. Return them exactly
as your topics array without modification:
{{ workflow.input.items }}
{% else %}
Generate a list of 5 interesting programming concepts to analyze.
Return them as a simple array of strings.
Examples: "functional programming", "type systems", "concurrency"
{% endif %}
output:
topics:
type: array
description: List of topics (strings) to process
routes:
- to: item_processors
# Agent 2: Aggregate results
- name: aggregator
description: Aggregates results from all processed items
model: claude-sonnet-4.5
input:
- item_finder.output
- item_processors.outputs
prompt: |
Summarize the batch processing results:
Original Items ({{ item_finder.output.topics | length }}):
{% for item in item_finder.output.topics %}
{{ loop.index }}. {{ item }}
{% endfor %}
Successfully Processed ({{ item_processors.outputs | length }}):
{% for result in item_processors.outputs %}
{{ loop.index }}. Original: {{ result.original }}
Processed: {{ result.processed }}
Analysis: {{ result.analysis }}
{% endfor %}
{% if item_processors.errors is defined and item_processors.errors %}
Failed Items ({{ item_processors.errors | length }}):
{% for idx, error in item_processors.errors.items() %}
- Index {{ idx }}: {{ error.message }}
{% endfor %}
{% endif %}
Provide:
1. Overall summary of processing
2. Key insights from analyses
3. Processing success rate
output:
summary:
type: string
description: Executive summary
insights:
type: array
description: Key insights from all analyses
success_rate:
type: string
description: Success rate (e.g., "5/5" or "4/5")
routes:
- to: $end
output:
summary: "{{ aggregator.output.summary }}"
insights: "{{ aggregator.output.insights | json }}"
success_rate: "{{ aggregator.output.success_rate }}"
total_items: "{{ item_finder.output.topics | length }}"
processed: "{{ item_processors.outputs | length }}"
failed: "{% if item_processors.errors is defined %}{{ item_processors.errors | length }}{% else %}0{% endif %}"