Iteration Steps
Iteration steps provide control flow primitives for loops, conditionals, and sequence generation in Jetty workflows.
Available Steps
| Step | Activity Name | Description |
|---|---|---|
| Number Sequence Generator | number_sequence_generator | Generate sequences of numbers |
| Conditional Branch | conditional_branch | Execute conditional logic |
| Loop Counter | loop_counter | Maintain loop iteration state |
Number Sequence Generator
Generates lists or tuples of numbers based on configurable rules.
Activity Name
number_sequence_generator
Overview
This step generates sequences of numbers in various patterns. It's useful for creating lists to iterate over, generating test data, or producing numeric ranges for parallel processing.
Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mode | string | "range" | Generation mode: range, pairs, arithmetic, geometric |
start | int | 0 | Starting value |
end | int | 10 | Ending value |
step | int | 1 | Step increment (or ratio for geometric) |
output_format | string | "list" | Output format: list, tuples, json |
max_terms | int | 100 | Maximum terms for geometric sequences |
Path Expression Parameters
| Parameter | Description |
|---|---|
start_path | Path to dynamic start value |
end_path | Path to dynamic end value |
step_path | Path to dynamic step value |
Generation Modes
Range Mode
Simple range: [start, start+step, start+2*step, ..., end]
{
"activity": "number_sequence_generator",
"mode": "range",
"start": 0,
"end": 10,
"step": 2
}
// Output: [0, 2, 4, 6, 8, 10]
Pairs Mode
Consecutive pairs: [(a, a+1), (a+1, a+2), ...]
{
"activity": "number_sequence_generator",
"mode": "pairs",
"start": 0,
"end": 6,
"step": 2
}
// Output: [(0, 2), (2, 4), (4, 6)]
Arithmetic Mode
Arithmetic sequence with custom step.
{
"activity": "number_sequence_generator",
"mode": "arithmetic",
"start": 5,
"end": 20,
"step": 3
}
// Output: [5, 8, 11, 14, 17, 20]
Geometric Mode
Geometric sequence with custom ratio.
{
"activity": "number_sequence_generator",
"mode": "geometric",
"start": 1,
"end": 100,
"step": 2,
"max_terms": 10
}
// Output: [1, 2, 4, 8, 16, 32, 64]
Examples
Generate Batch Indices
{
"name": "create_batches",
"activity": "number_sequence_generator",
"config": {
"mode": "range",
"start": 0,
"end_path": "data_loader.outputs.total_items",
"step": 100
}
}
Create Test Thresholds
{
"name": "thresholds",
"activity": "number_sequence_generator",
"config": {
"mode": "arithmetic",
"start": 0,
"end": 100,
"step": 10,
"output_format": "list"
}
}
Output Structure
{
"outputs": {
"sequence": [0, 2, 4, 6, 8, 10],
"stats": {
"count": 6,
"min": 0,
"max": 10,
"sum": 30,
"avg": 5.0
},
"mode": "range",
"parameters": {
"start": 0,
"end": 10,
"step": 2,
"output_format": "list"
}
}
}
Conditional Branch
Executes conditional logic based on input values.
Activity Name
conditional_branch
Overview
This step evaluates a condition and returns different outputs based on the result. Use it to implement branching logic within workflows.
Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value_path | string | "init_params.value" | Path to the value to evaluate |
condition_type | string | "equals" | Type of comparison |
condition_value | any | null | Value to compare against |
true_output | object | {"result": true} | Output when condition is true |
false_output | object | {"result": false} | Output when condition is false |
Path Expression Parameters
| Parameter | Description |
|---|---|
condition_value_path | Path to dynamic comparison value |
Condition Types
| Type | Description | Example |
|---|---|---|
equals | Exact equality | value == condition_value |
not_equals | Not equal | value != condition_value |
greater_than | Greater than | value > condition_value |
less_than | Less than | value < condition_value |
greater_equal | Greater or equal | value >= condition_value |
less_equal | Less or equal | value <= condition_value |
contains | String contains | condition_value in value |
exists | Value is not None | value is not None |
is_empty | Value is empty/falsy | not value |
Examples
Quality Gate
{
"name": "quality_check",
"activity": "conditional_branch",
"config": {
"value_path": "evaluator.outputs.score",
"condition_type": "greater_equal",
"condition_value": 0.8,
"true_output": {
"status": "passed",
"action": "publish"
},
"false_output": {
"status": "failed",
"action": "review"
}
}
}
Check for Errors
{
"name": "error_check",
"activity": "conditional_branch",
"config": {
"value_path": "processor.outputs.error",
"condition_type": "exists",
"true_output": {
"has_error": true,
"next_step": "error_handler"
},
"false_output": {
"has_error": false,
"next_step": "continue"
}
}
}
Category Routing
{
"name": "route_by_type",
"activity": "conditional_branch",
"config": {
"value_path": "classifier.outputs.category",
"condition_type": "equals",
"condition_value": "urgent",
"true_output": {
"priority": "high",
"queue": "urgent_queue"
},
"false_output": {
"priority": "normal",
"queue": "standard_queue"
}
}
}
Output Structure
{
"outputs": {
"status": "passed",
"action": "publish",
"condition_result": true,
"evaluated_value": 0.92,
"condition": {
"type": "greater_equal",
"expected": 0.8,
"actual": 0.92,
"result": true
}
}
}
Loop Counter
Maintains loop counter and iteration state.
Activity Name
loop_counter
Overview
This step manages iteration state for loop-based workflows. It tracks the current iteration, calculates progress, and determines when the loop should complete.
Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
start_count | int | 0 | Initial count if no current count found |
max_iterations | int | 10 | Maximum number of iterations |
increment | int | 1 | Amount to increment each iteration |
Path Expression Parameters
| Parameter | Description |
|---|---|
current_count_path | Path to current iteration count |
max_iterations_path | Path to dynamic max iterations |
increment_path | Path to dynamic increment value |
Examples
Basic Loop Control
{
"name": "loop_control",
"activity": "loop_counter",
"config": {
"current_count_path": "init_params.iteration",
"max_iterations": 5,
"increment": 1
}
}
Dynamic Loop Bounds
{
"name": "dynamic_loop",
"activity": "loop_counter",
"config": {
"current_count_path": "previous_iteration.outputs.next_count",
"max_iterations_path": "data_loader.outputs.total_batches",
"increment": 1
}
}
Output Structure
{
"outputs": {
"current_count": 3,
"next_count": 4,
"is_complete": false,
"continue_loop": true,
"progress": 0.4,
"remaining_iterations": 6,
"loop_info": {
"current": 3,
"max": 10,
"increment": 1,
"progress_percent": 40.0
}
}
}
Common Patterns
Iterative Refinement Loop
Use loop counter with conditional to iteratively improve output:
{
"steps": ["generate", "evaluate", "check_quality", "loop_control"],
"step_configs": {
"generate": {
"activity": "litellm_chat",
"prompt_path": "init_params.prompt",
"model": "gpt-4o"
},
"evaluate": {
"activity": "simple_judge",
"instruction": "Rate the quality of this output",
"judge_type": "scale",
"scale_range": [1, 10],
"item_path": "generate.outputs.text"
},
"check_quality": {
"activity": "conditional_branch",
"value_path": "evaluate.outputs.results[0].score",
"condition_type": "greater_equal",
"condition_value": 8,
"true_output": {"done": true},
"false_output": {"done": false}
},
"loop_control": {
"activity": "loop_counter",
"max_iterations": 3
}
}
}
Batch Processing with Sequences
Generate batch boundaries for large dataset processing:
{
"steps": ["count_items", "generate_batches", "process_batches"],
"step_configs": {
"count_items": {
"activity": "read_text_file",
"text_path": "init_params.data_file"
},
"generate_batches": {
"activity": "number_sequence_generator",
"mode": "range",
"start": 0,
"end_path": "count_items.outputs.line_count",
"step": 100
},
"process_batches": {
"activity": "list_emit_await",
"items_path": "generate_batches.outputs.sequence",
"task_reference": {"task_name": "process_batch"},
"data_mapping": {
"offset": "{{ $item }}",
"limit": 100
}
}
}
}
Threshold Testing
Test multiple thresholds to find optimal values:
{
"steps": ["generate_thresholds", "test_all", "find_best"],
"step_configs": {
"generate_thresholds": {
"activity": "number_sequence_generator",
"mode": "arithmetic",
"start": 50,
"end": 100,
"step": 5
},
"test_all": {
"activity": "list_emit_await",
"items_path": "generate_thresholds.outputs.sequence",
"task_reference": {"task_name": "test_threshold"},
"data_mapping": {
"threshold": "{{ $item }}"
}
},
"find_best": {
"activity": "extract_from_trajectories",
"trajectory_list_path": "test_all.outputs.trajectory_references",
"extract_keys": {
"threshold": "init_params.threshold",
"accuracy": "steps.evaluate.outputs.accuracy"
}
}
}
}
Best Practices
Sequence Generation
- Use appropriate modes for your use case
- Set
max_termsfor geometric sequences to prevent runaway generation - Consider memory usage with very large sequences
Conditional Logic
- Keep conditions simple and readable
- Use descriptive
true_outputandfalse_outputvalues - Consider using multiple conditions for complex routing
Loop Control
- Always set reasonable
max_iterationsto prevent infinite loops - Track progress for long-running iterative processes
- Use
is_completeto determine loop termination
Related Steps
- List Emit Await - Process sequences in parallel
- Simple Judge - Evaluate loop outputs
- LiteLLM Chat - Generate content in loops