-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrol_flow_while_loop.yaml
More file actions
139 lines (125 loc) · 4.5 KB
/
control_flow_while_loop.yaml
File metadata and controls
139 lines (125 loc) · 4.5 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
id: control-flow-while-loop
# While Loop Example
# Demonstrates iterative processing with a simple counter
name: Iterative Number Guessing
description: Generate numbers until we reach a target
version: "1.0.0"
parameters:
target_number:
type: integer
default: 42
description: Target number to reach
max_attempts:
type: integer
default: 10
description: Maximum attempts
steps:
# Initialize the process
- id: initialize
action: generate_text
parameters:
prompt: "Starting number guessing game. Target is {{ target_number }}"
model: <AUTO task="summarize">Select a model for initialization</AUTO>
max_tokens: 50
# Create initial state file
- id: init_state
tool: filesystem
action: write
parameters:
path: "examples/outputs/control_flow_while_loop/state/current_guess.txt"
content: "0"
dependencies:
- initialize
# Iterative guessing loop
- id: guessing_loop
while: 'true' # Simple always-true condition, will use max_iterations
max_iterations: "{{ max_attempts }}"
steps:
# Read current guess
- id: read_guess
tool: filesystem
action: read
parameters:
path: "examples/outputs/control_flow_while_loop/state/current_guess.txt"
# Generate next guess
- id: generate_guess
action: generate_text
parameters:
prompt: |
We're trying to guess the number {{ target_number }}.
Current guess: {{ read_guess.result.content }}
Iteration: {{ guessing_loop.iteration }}
What number should we guess next? Reply with just a number between 1 and 100.
model: <AUTO task="generate">Select a model for number generation</AUTO>
max_tokens: 10
dependencies:
- read_guess
# Extract number from response
- id: extract_number
action: analyze_text
parameters:
text: "Generated guess: {{ generate_guess.result | regex_search('[0-9]+') | default('25') }}"
model: <AUTO task="analyze">Select a model for number extraction</AUTO>
analysis_type: "extract_number"
dependencies:
- generate_guess
# Update state
- id: update_state
tool: filesystem
action: write
parameters:
path: "examples/outputs/control_flow_while_loop/state/current_guess.txt"
content: "{{ generate_guess.result | regex_search('[0-9]+') | default('25') }}"
dependencies:
- extract_number
# Log the attempt
- id: log_attempt
tool: filesystem
action: write
parameters:
path: "examples/outputs/control_flow_while_loop/logs/attempt_{{ guessing_loop.iteration }}.txt"
content: |
Iteration: {{ guessing_loop.iteration }}
Previous guess: {{ read_guess.result.content }}
New guess: {{ generate_guess.result | regex_search('[0-9]+') | default('25') }}
Target: {{ target_number }}
dependencies:
- update_state
# Check if we found the target
- id: check_result
action: analyze_text
parameters:
text: "{{ generate_guess.result | regex_search('[0-9]+') | default('25') }}"
model: <AUTO task="analyze">Select a model for comparison</AUTO>
analysis_type: "compare_to_target"
target: "{{ target_number }}"
dependencies:
- log_attempt
# Update loop state
- id: update_loop_state
action: generate_text
parameters:
prompt: "Attempt {{ guessing_loop.iteration }} complete. Found target: {{ check_result.matches_target | default(false) }}"
model: <AUTO task="summarize">Select a model for status update</AUTO>
max_tokens: 20
dependencies:
- check_result
dependencies:
- init_state
# Final result
- id: final_result
tool: filesystem
action: write
parameters:
path: "examples/outputs/control_flow_while_loop/result.txt"
content: |
# Number Guessing Results
Target number: {{ target_number }}
Total attempts: {{ guessing_loop.iterations | default(0) }}
Success: {{ guessing_loop.completed | default(false) }}
dependencies:
- guessing_loop
outputs:
target: "{{ target_number }}"
attempts: "{{ guessing_loop.iterations | default(0) }}"
result_file: "{{ final_result.filepath }}"