language-operator 0.1.61 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/persona.md +9 -0
  3. data/.claude/commands/task.md +46 -1
  4. data/.rubocop.yml +13 -0
  5. data/.rubocop_custom/use_ux_helper.rb +44 -0
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile.lock +12 -1
  8. data/Makefile +26 -7
  9. data/Makefile.common +50 -0
  10. data/bin/aictl +8 -1
  11. data/components/agent/Gemfile +1 -1
  12. data/components/agent/bin/langop-agent +7 -0
  13. data/docs/README.md +58 -0
  14. data/docs/{dsl/best-practices.md → best-practices.md} +4 -4
  15. data/docs/cli-reference.md +274 -0
  16. data/docs/{dsl/constraints.md → constraints.md} +5 -5
  17. data/docs/how-agents-work.md +156 -0
  18. data/docs/installation.md +218 -0
  19. data/docs/quickstart.md +299 -0
  20. data/docs/understanding-generated-code.md +265 -0
  21. data/docs/using-tools.md +457 -0
  22. data/docs/webhooks.md +509 -0
  23. data/examples/ux_helpers_demo.rb +296 -0
  24. data/lib/language_operator/agent/base.rb +11 -1
  25. data/lib/language_operator/agent/executor.rb +23 -6
  26. data/lib/language_operator/agent/safety/safe_executor.rb +41 -39
  27. data/lib/language_operator/agent/task_executor.rb +346 -63
  28. data/lib/language_operator/agent/web_server.rb +110 -14
  29. data/lib/language_operator/agent/webhook_authenticator.rb +39 -5
  30. data/lib/language_operator/agent.rb +88 -2
  31. data/lib/language_operator/cli/base_command.rb +17 -11
  32. data/lib/language_operator/cli/command_loader.rb +72 -0
  33. data/lib/language_operator/cli/commands/agent/base.rb +837 -0
  34. data/lib/language_operator/cli/commands/agent/code_operations.rb +102 -0
  35. data/lib/language_operator/cli/commands/agent/helpers/cluster_llm_client.rb +116 -0
  36. data/lib/language_operator/cli/commands/agent/helpers/code_parser.rb +115 -0
  37. data/lib/language_operator/cli/commands/agent/helpers/synthesis_watcher.rb +96 -0
  38. data/lib/language_operator/cli/commands/agent/learning.rb +289 -0
  39. data/lib/language_operator/cli/commands/agent/lifecycle.rb +102 -0
  40. data/lib/language_operator/cli/commands/agent/logs.rb +125 -0
  41. data/lib/language_operator/cli/commands/agent/workspace.rb +327 -0
  42. data/lib/language_operator/cli/commands/cluster.rb +129 -84
  43. data/lib/language_operator/cli/commands/install.rb +1 -1
  44. data/lib/language_operator/cli/commands/model/base.rb +215 -0
  45. data/lib/language_operator/cli/commands/model/test.rb +165 -0
  46. data/lib/language_operator/cli/commands/persona.rb +16 -34
  47. data/lib/language_operator/cli/commands/quickstart.rb +3 -2
  48. data/lib/language_operator/cli/commands/status.rb +40 -67
  49. data/lib/language_operator/cli/commands/system/base.rb +44 -0
  50. data/lib/language_operator/cli/commands/system/exec.rb +147 -0
  51. data/lib/language_operator/cli/commands/system/helpers/llm_synthesis.rb +183 -0
  52. data/lib/language_operator/cli/commands/system/helpers/pod_manager.rb +212 -0
  53. data/lib/language_operator/cli/commands/system/helpers/template_loader.rb +57 -0
  54. data/lib/language_operator/cli/commands/system/helpers/template_validator.rb +174 -0
  55. data/lib/language_operator/cli/commands/system/schema.rb +92 -0
  56. data/lib/language_operator/cli/commands/system/synthesis_template.rb +151 -0
  57. data/lib/language_operator/cli/commands/system/synthesize.rb +224 -0
  58. data/lib/language_operator/cli/commands/system/validate_template.rb +130 -0
  59. data/lib/language_operator/cli/commands/tool/base.rb +271 -0
  60. data/lib/language_operator/cli/commands/tool/install.rb +255 -0
  61. data/lib/language_operator/cli/commands/tool/search.rb +69 -0
  62. data/lib/language_operator/cli/commands/tool/test.rb +115 -0
  63. data/lib/language_operator/cli/commands/use.rb +29 -6
  64. data/lib/language_operator/cli/errors/handler.rb +20 -17
  65. data/lib/language_operator/cli/errors/suggestions.rb +3 -5
  66. data/lib/language_operator/cli/errors/thor_errors.rb +55 -0
  67. data/lib/language_operator/cli/formatters/code_formatter.rb +4 -11
  68. data/lib/language_operator/cli/formatters/log_formatter.rb +8 -15
  69. data/lib/language_operator/cli/formatters/progress_formatter.rb +6 -8
  70. data/lib/language_operator/cli/formatters/status_formatter.rb +26 -7
  71. data/lib/language_operator/cli/formatters/table_formatter.rb +47 -36
  72. data/lib/language_operator/cli/formatters/value_formatter.rb +75 -0
  73. data/lib/language_operator/cli/helpers/cluster_context.rb +5 -3
  74. data/lib/language_operator/cli/helpers/kubeconfig_validator.rb +2 -1
  75. data/lib/language_operator/cli/helpers/label_utils.rb +97 -0
  76. data/lib/language_operator/{ux/concerns/provider_helpers.rb → cli/helpers/provider_helper.rb} +10 -29
  77. data/lib/language_operator/cli/helpers/schedule_builder.rb +21 -1
  78. data/lib/language_operator/cli/helpers/user_prompts.rb +19 -11
  79. data/lib/language_operator/cli/helpers/ux_helper.rb +538 -0
  80. data/lib/language_operator/{ux/concerns/input_validation.rb → cli/helpers/validation_helper.rb} +13 -66
  81. data/lib/language_operator/cli/main.rb +50 -40
  82. data/lib/language_operator/cli/templates/tools/generic.yaml +3 -0
  83. data/lib/language_operator/cli/wizards/agent_wizard.rb +12 -20
  84. data/lib/language_operator/cli/wizards/model_wizard.rb +271 -0
  85. data/lib/language_operator/cli/wizards/quickstart_wizard.rb +8 -34
  86. data/lib/language_operator/client/base.rb +28 -0
  87. data/lib/language_operator/client/config.rb +4 -1
  88. data/lib/language_operator/client/mcp_connector.rb +1 -1
  89. data/lib/language_operator/config/cluster_config.rb +3 -2
  90. data/lib/language_operator/config.rb +38 -11
  91. data/lib/language_operator/constants/kubernetes_labels.rb +80 -0
  92. data/lib/language_operator/constants.rb +13 -0
  93. data/lib/language_operator/dsl/http.rb +127 -10
  94. data/lib/language_operator/dsl.rb +153 -6
  95. data/lib/language_operator/errors.rb +50 -0
  96. data/lib/language_operator/kubernetes/client.rb +11 -6
  97. data/lib/language_operator/kubernetes/resource_builder.rb +58 -84
  98. data/lib/language_operator/templates/schema/agent_dsl_openapi.yaml +1 -1
  99. data/lib/language_operator/templates/schema/agent_dsl_schema.json +1 -1
  100. data/lib/language_operator/type_coercion.rb +118 -34
  101. data/lib/language_operator/utils/secure_path.rb +74 -0
  102. data/lib/language_operator/utils.rb +7 -0
  103. data/lib/language_operator/validators.rb +54 -2
  104. data/lib/language_operator/version.rb +1 -1
  105. data/synth/001/Makefile +10 -2
  106. data/synth/001/agent.rb +16 -15
  107. data/synth/001/output.log +27 -10
  108. data/synth/002/Makefile +10 -2
  109. data/synth/003/Makefile +1 -1
  110. data/synth/003/README.md +205 -133
  111. data/synth/003/agent.optimized.rb +66 -0
  112. data/synth/003/agent.synthesized.rb +41 -0
  113. metadata +111 -35
  114. data/docs/dsl/agent-reference.md +0 -604
  115. data/docs/dsl/mcp-integration.md +0 -1177
  116. data/docs/dsl/webhooks.md +0 -932
  117. data/docs/dsl/workflows.md +0 -744
  118. data/lib/language_operator/cli/commands/agent.rb +0 -1712
  119. data/lib/language_operator/cli/commands/model.rb +0 -366
  120. data/lib/language_operator/cli/commands/system.rb +0 -1259
  121. data/lib/language_operator/cli/commands/tool.rb +0 -654
  122. data/lib/language_operator/cli/formatters/optimization_formatter.rb +0 -226
  123. data/lib/language_operator/cli/helpers/pastel_helper.rb +0 -24
  124. data/lib/language_operator/learning/adapters/base_adapter.rb +0 -149
  125. data/lib/language_operator/learning/adapters/jaeger_adapter.rb +0 -221
  126. data/lib/language_operator/learning/adapters/signoz_adapter.rb +0 -435
  127. data/lib/language_operator/learning/adapters/tempo_adapter.rb +0 -239
  128. data/lib/language_operator/learning/optimizer.rb +0 -319
  129. data/lib/language_operator/learning/pattern_detector.rb +0 -260
  130. data/lib/language_operator/learning/task_synthesizer.rb +0 -288
  131. data/lib/language_operator/learning/trace_analyzer.rb +0 -285
  132. data/lib/language_operator/templates/task_synthesis.tmpl +0 -98
  133. data/lib/language_operator/ux/base.rb +0 -81
  134. data/lib/language_operator/ux/concerns/README.md +0 -155
  135. data/lib/language_operator/ux/concerns/headings.rb +0 -90
  136. data/lib/language_operator/ux/create_agent.rb +0 -255
  137. data/lib/language_operator/ux/create_model.rb +0 -267
  138. data/lib/language_operator/ux/quickstart.rb +0 -594
  139. data/synth/003/agent.rb +0 -41
  140. data/synth/003/output.log +0 -68
  141. /data/docs/{architecture/agent-runtime.md → agent-internals.md} +0 -0
  142. /data/docs/{dsl/chat-endpoints.md → chat-endpoints.md} +0 -0
  143. /data/docs/{dsl/SCHEMA_VERSION.md → schema-versioning.md} +0 -0
@@ -0,0 +1,299 @@
1
+ # Quickstart Guide
2
+
3
+ Get your first Language Operator agent running in 5 minutes.
4
+
5
+ ## Before You Begin
6
+
7
+ - Install aictl: `gem install language-operator`
8
+ - Have Kubernetes cluster access
9
+ - Set up API keys for your preferred LLM provider
10
+
11
+ ## Step 1: Initial Setup
12
+
13
+ Run the interactive setup wizard:
14
+
15
+ ```bash
16
+ aictl quickstart
17
+ ```
18
+
19
+ The wizard will guide you through:
20
+ 1. Cluster configuration
21
+ 2. Language Operator installation
22
+ 3. Model setup (OpenAI, Anthropic, or local)
23
+ 4. Creating your first agent
24
+
25
+ ## Step 2: Manual Setup (Alternative)
26
+
27
+ If you prefer step-by-step setup:
28
+
29
+ ### Configure Your Cluster
30
+
31
+ ```bash
32
+ # Create cluster configuration
33
+ aictl cluster create my-cluster
34
+
35
+ # Switch to it
36
+ aictl use my-cluster
37
+
38
+ # Check connectivity
39
+ aictl status
40
+ ```
41
+
42
+ ### Install Language Operator
43
+
44
+ ```bash
45
+ aictl install
46
+ ```
47
+
48
+ Wait for installation to complete, then verify:
49
+
50
+ ```bash
51
+ aictl status
52
+ ```
53
+
54
+ ### Create a Model
55
+
56
+ ```bash
57
+ # For OpenAI (set OPENAI_API_KEY first)
58
+ aictl model create gpt4 --provider openai --model gpt-4-turbo
59
+
60
+ # For Anthropic (set ANTHROPIC_API_KEY first)
61
+ aictl model create claude --provider anthropic --model claude-3-sonnet
62
+
63
+ # Verify model
64
+ aictl model list
65
+ ```
66
+
67
+ ## Step 3: Create Your First Agent
68
+
69
+ ### Simple Scheduled Agent
70
+
71
+ Create an agent that runs daily:
72
+
73
+ ```bash
74
+ aictl agent create daily-reporter
75
+ ```
76
+
77
+ You'll be prompted to describe what the agent should do. Try:
78
+ > "Generate a daily summary of system status and send it via email"
79
+
80
+ ### Check Agent Status
81
+
82
+ ```bash
83
+ # List all agents
84
+ aictl agent list
85
+
86
+ # Get detailed info
87
+ aictl agent inspect daily-reporter
88
+
89
+ # View logs
90
+ aictl agent logs daily-reporter -f
91
+ ```
92
+
93
+ ## Step 4: Understanding What Was Created
94
+
95
+ ### View Generated Code
96
+
97
+ ```bash
98
+ # Open agent workspace
99
+ aictl agent workspace daily-reporter
100
+ ```
101
+
102
+ This shows the synthesized agent definition that Language Operator created from your description.
103
+
104
+ ### Example Generated Agent
105
+
106
+ ```ruby
107
+ agent "daily-reporter" do
108
+ description "Generate a daily summary of system status and send it via email"
109
+
110
+ mode :scheduled
111
+ schedule "0 8 * * *" # 8 AM daily
112
+
113
+ task :collect_system_status do |inputs|
114
+ # AI-synthesized task to gather system information
115
+ { status: "healthy", uptime: "99.9%", alerts: [] }
116
+ end
117
+
118
+ task :generate_report do |inputs|
119
+ # AI-synthesized task to create report
120
+ status = inputs[:status]
121
+ { report: "Daily Status: #{status}" }
122
+ end
123
+
124
+ main do |inputs|
125
+ status = collect_system_status
126
+ report = generate_report(status)
127
+ report
128
+ end
129
+
130
+ output do |outputs|
131
+ # AI-synthesized output handling
132
+ puts "Report generated: #{outputs[:report]}"
133
+ end
134
+
135
+ constraints do
136
+ timeout "10m"
137
+ daily_budget 100 # $1.00 max per day
138
+ end
139
+ end
140
+ ```
141
+
142
+ ## Step 5: Experiment with Different Agent Types
143
+
144
+ ### Webhook Agent
145
+
146
+ Create an agent that responds to GitHub webhooks:
147
+
148
+ ```bash
149
+ aictl agent create github-responder
150
+ ```
151
+
152
+ Description: "Respond to GitHub pull request webhooks with automated code reviews"
153
+
154
+ ### Chat Agent
155
+
156
+ Create a conversational agent:
157
+
158
+ ```bash
159
+ aictl agent create support-bot
160
+ ```
161
+
162
+ Description: "Provide customer support through a chat interface"
163
+
164
+ ### Autonomous Agent
165
+
166
+ Create an agent that runs continuously:
167
+
168
+ ```bash
169
+ aictl agent create system-monitor
170
+ ```
171
+
172
+ Description: "Continuously monitor system health and alert on issues"
173
+
174
+ ## Step 6: Monitor and Manage
175
+
176
+ ### View All Agents
177
+
178
+ ```bash
179
+ aictl agent list
180
+ ```
181
+
182
+ ### Check Agent Logs
183
+
184
+ ```bash
185
+ # Follow logs in real-time
186
+ aictl agent logs daily-reporter -f
187
+
188
+ # View recent logs
189
+ aictl agent logs daily-reporter --since 1h
190
+ ```
191
+
192
+ ### Monitoring Agents
193
+
194
+ Monitor your agent's execution and performance:
195
+
196
+ ```bash
197
+ # View detailed agent information
198
+ aictl agent inspect daily-reporter
199
+
200
+ # Check recent execution logs
201
+ aictl agent logs daily-reporter --since 1h
202
+ ```
203
+
204
+ ## Common Patterns
205
+
206
+ ### Scheduled Reporting
207
+
208
+ ```ruby
209
+ agent "weekly-metrics" do
210
+ description "Generate weekly performance metrics"
211
+ schedule "0 9 * * 1" # Mondays at 9 AM
212
+
213
+ # Tasks will be synthesized based on description
214
+ end
215
+ ```
216
+
217
+ ### Event Response
218
+
219
+ ```ruby
220
+ agent "incident-responder" do
221
+ description "Respond to system incidents"
222
+ mode :reactive
223
+
224
+ webhook "/alerts/critical" do
225
+ method :post
226
+ end
227
+ end
228
+ ```
229
+
230
+ ### Continuous Monitoring
231
+
232
+ ```ruby
233
+ agent "health-monitor" do
234
+ description "Monitor application health continuously"
235
+ mode :autonomous
236
+
237
+ constraints do
238
+ requests_per_minute 2
239
+ daily_budget 500 # $5 max per day
240
+ end
241
+ end
242
+ ```
243
+
244
+ ## Troubleshooting
245
+
246
+ ### Agent Not Starting
247
+
248
+ ```bash
249
+ # Check agent status
250
+ aictl agent inspect my-agent
251
+
252
+ # View detailed logs
253
+ aictl agent logs my-agent
254
+
255
+ # Check cluster status
256
+ aictl status
257
+ ```
258
+
259
+ ### High Costs
260
+
261
+ Agents use LLM APIs which have costs. Monitor usage:
262
+
263
+ ```bash
264
+ # Check agent configuration
265
+ aictl agent inspect my-agent
266
+
267
+ # Look for budget constraints
268
+ # Adjust constraints if needed
269
+ ```
270
+
271
+ ### Connection Issues
272
+
273
+ ```bash
274
+ # Test cluster connectivity
275
+ kubectl get nodes
276
+
277
+ # Check Language Operator status
278
+ kubectl get pods -n language-operator
279
+
280
+ # Verify model connectivity
281
+ aictl model test my-model
282
+ ```
283
+
284
+ ## Next Steps
285
+
286
+ Now that you have a working agent:
287
+
288
+ 1. **[How Agents Work](how-agents-work.md)** - Understand the synthesis process
289
+ 2. **[Understanding Generated Code](understanding-generated-code.md)** - Learn to read agent definitions
290
+ 3. **[Using Tools](using-tools.md)** - Connect agents to external services
291
+ 4. **[Constraints](constraints.md)** - Control costs and behavior
292
+ 5. **[Best Practices](best-practices.md)** - Production deployment patterns
293
+
294
+ ## Getting Help
295
+
296
+ - View command help: `aictl --help`
297
+ - Check specific commands: `aictl agent --help`
298
+ - Report issues: [GitHub Issues](https://github.com/language-operator/language-operator-gem/issues)
299
+ - Join discussions: [GitHub Discussions](https://github.com/language-operator/language-operator/discussions)
@@ -0,0 +1,265 @@
1
+ # Understanding Generated Code
2
+
3
+ When you create an agent with Language Operator, it generates Ruby code that defines how your agent works. This guide helps you read and understand that generated code.
4
+
5
+ ## Agent Structure Overview
6
+
7
+ Every synthesized agent has this basic structure:
8
+
9
+ ```ruby
10
+ agent "my-agent" do
11
+ # Agent metadata
12
+ description "What this agent does"
13
+ mode :scheduled
14
+ schedule "0 9 * * *" # 9 AM daily
15
+
16
+ # Task definitions (work units)
17
+ task :task_name,
18
+ instructions: "what to do",
19
+ inputs: { param: 'type' },
20
+ outputs: { result: 'type' }
21
+
22
+ # Main execution logic
23
+ main do |inputs|
24
+ result = execute_task(:task_name, inputs: inputs)
25
+ result
26
+ end
27
+
28
+ # Output handling
29
+ output do |outputs|
30
+ # What to do with results
31
+ end
32
+
33
+ # Optional constraints
34
+ constraints do
35
+ timeout "10m"
36
+ daily_budget 5.00
37
+ end
38
+ end
39
+ ```
40
+
41
+ ## Agent Metadata
42
+
43
+ ### Description
44
+ Plain English description of what the agent does:
45
+
46
+ ```ruby
47
+ description "Monitors GitHub issues and alerts on critical bugs"
48
+ ```
49
+
50
+ ### Execution Mode
51
+ How the agent is triggered:
52
+
53
+ ```ruby
54
+ mode :scheduled # Runs on a schedule
55
+ mode :autonomous # Runs continuously
56
+ mode :reactive # Responds to webhooks/events
57
+ ```
58
+
59
+ ### Schedule (for scheduled agents)
60
+ Cron expression defining when to run:
61
+
62
+ ```ruby
63
+ schedule "0 9 * * *" # 9 AM daily
64
+ schedule "*/15 * * * *" # Every 15 minutes
65
+ schedule "0 0 * * 1" # Every Monday at midnight
66
+ ```
67
+
68
+ ## Task Definitions
69
+
70
+ Tasks are individual work units with clear contracts. They come in two types:
71
+
72
+ ### Task Definitions
73
+
74
+ Tasks are Ruby blocks that process inputs and return outputs:
75
+
76
+ ```ruby
77
+ task :analyze_logs do |inputs|
78
+ # Task implementation - this can be:
79
+ # 1. Simple Ruby code
80
+ # 2. Calls to AI for complex reasoning
81
+ # 3. MCP tool usage (when available)
82
+
83
+ logs = inputs[:logs] || []
84
+ critical_issues = logs.select { |log| log[:level] == 'ERROR' }
85
+
86
+ {
87
+ critical_issues: critical_issues,
88
+ summary: "Found #{critical_issues.length} critical issues"
89
+ }
90
+ end
91
+ ```
92
+
93
+ **Key parts:**
94
+ - Task name (`:analyze_logs`)
95
+ - Input parameter (`inputs` hash)
96
+ - Ruby block with implementation
97
+ - Return value (hash with results)
98
+
99
+ ### Task Evolution
100
+
101
+ Tasks can evolve from simple implementations to more sophisticated ones:
102
+
103
+ ```ruby
104
+ # Simple implementation
105
+ task :fetch_recent_logs do |inputs|
106
+ hours = inputs[:hours] || 24
107
+ since_time = Time.now - (hours * 3600)
108
+
109
+ # In a real implementation, this might call MCP tools
110
+ # or use AI synthesis for complex queries
111
+ { logs: [], since: since_time }
112
+ end
113
+ ```
114
+
115
+ ## Main Logic
116
+
117
+ The `main` block coordinates task execution and defines the agent's workflow:
118
+
119
+ ```ruby
120
+ main do |inputs|
121
+ # Task execution - tasks are called as methods
122
+ logs = fetch_recent_logs(hours: 24)
123
+ analysis = analyze_logs(logs: logs[:logs])
124
+
125
+ # Conditional logic
126
+ if analysis[:critical_issues].any?
127
+ send_alert(analysis)
128
+ end
129
+
130
+ # Return final result
131
+ analysis
132
+ end
133
+ ```
134
+
135
+ **Important concepts:**
136
+ - Tasks are called as method names
137
+ - Task results are returned as hashes
138
+ - Standard Ruby control flow (if/else, loops, variables)
139
+ - The return value becomes the agent's output
140
+ - Tasks can be chained together
141
+
142
+ ## Output Handling
143
+
144
+ Defines what happens with the agent's final result:
145
+
146
+ ### Neural Output
147
+ ```ruby
148
+ output instructions: "send results to team via Slack"
149
+ ```
150
+
151
+ ### Symbolic Output
152
+ ```ruby
153
+ output do |outputs|
154
+ execute_tool('slack', 'post_message', {
155
+ channel: '#alerts',
156
+ text: "Found #{outputs[:critical_issues].length} critical issues"
157
+ })
158
+ end
159
+ ```
160
+
161
+ ## Type System
162
+
163
+ Tasks use a simple type system for validation:
164
+
165
+ | Type | Description | Example |
166
+ |------|-------------|---------|
167
+ | `'string'` | Text data | `"hello world"` |
168
+ | `'integer'` | Whole numbers | `42` |
169
+ | `'number'` | Any number | `3.14` |
170
+ | `'boolean'` | True/false | `true` |
171
+ | `'array'` | List of items | `[1, 2, 3]` |
172
+ | `'hash'` | Key-value pairs | `{name: "Alice"}` |
173
+ | `'any'` | Any data type | anything |
174
+
175
+ ## Constraints
176
+
177
+ Optional limits on agent behavior:
178
+
179
+ ```ruby
180
+ constraints do
181
+ timeout "30m" # Maximum execution time
182
+ max_iterations 100 # For autonomous agents
183
+ daily_budget 10.00 # Maximum cost per day
184
+ memory_limit "512Mi" # Memory usage limit
185
+ end
186
+ ```
187
+
188
+ ## Learning Progression Example
189
+
190
+ Here's how a task evolves over time:
191
+
192
+ ### Initially (Neural)
193
+ ```ruby
194
+ task :calculate_metrics,
195
+ instructions: "calculate average response time and error rate from logs",
196
+ inputs: { logs: 'array' },
197
+ outputs: { avg_response_time: 'number', error_rate: 'number' }
198
+ ```
199
+
200
+ ### After Learning (Symbolic)
201
+ ```ruby
202
+ task :calculate_metrics,
203
+ inputs: { logs: 'array' },
204
+ outputs: { avg_response_time: 'number', error_rate: 'number' }
205
+ do |inputs|
206
+ response_times = inputs[:logs].map { |log| log['response_time'] }.compact
207
+ total_requests = inputs[:logs].length
208
+ error_count = inputs[:logs].count { |log| log['status'] >= 400 }
209
+
210
+ {
211
+ avg_response_time: response_times.sum / response_times.length.to_f,
212
+ error_rate: (error_count / total_requests.to_f) * 100
213
+ }
214
+ end
215
+ ```
216
+
217
+ ## Common Patterns
218
+
219
+ ### Error Handling
220
+ ```ruby
221
+ main do |inputs|
222
+ begin
223
+ result = execute_task(:risky_operation, inputs: inputs)
224
+ result
225
+ rescue => e
226
+ { error: e.message, success: false }
227
+ end
228
+ end
229
+ ```
230
+
231
+ ### Conditional Execution
232
+ ```ruby
233
+ main do |inputs|
234
+ data = execute_task(:fetch_data, inputs: inputs)
235
+
236
+ if data[:records].any?
237
+ execute_task(:process_records, inputs: data)
238
+ else
239
+ { message: "No records to process" }
240
+ end
241
+ end
242
+ ```
243
+
244
+ ### Parallel Task Execution
245
+ ```ruby
246
+ main do |inputs|
247
+ # Run multiple tasks in parallel
248
+ results = execute_parallel([
249
+ { name: :fetch_source1 },
250
+ { name: :fetch_source2 }
251
+ ])
252
+
253
+ # Merge results
254
+ execute_task(:merge_data, inputs: {
255
+ source1: results[0],
256
+ source2: results[1]
257
+ })
258
+ end
259
+ ```
260
+
261
+ ## Next Steps
262
+
263
+ - **[How Agents Work](how-agents-work.md)** - Understanding the synthesis process
264
+ - **[Agent Optimization](agent-optimization.md)** - How learning improves performance
265
+ - **[Using Tools](using-tools.md)** - How agents interact with external services