language-operator 0.0.1 → 0.1.30

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 (116) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +125 -0
  3. data/CHANGELOG.md +53 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +284 -0
  6. data/LICENSE +229 -21
  7. data/Makefile +77 -0
  8. data/README.md +3 -11
  9. data/Rakefile +34 -0
  10. data/bin/aictl +7 -0
  11. data/completions/_aictl +232 -0
  12. data/completions/aictl.bash +121 -0
  13. data/completions/aictl.fish +114 -0
  14. data/docs/architecture/agent-runtime.md +585 -0
  15. data/docs/dsl/agent-reference.md +591 -0
  16. data/docs/dsl/best-practices.md +1078 -0
  17. data/docs/dsl/chat-endpoints.md +895 -0
  18. data/docs/dsl/constraints.md +671 -0
  19. data/docs/dsl/mcp-integration.md +1177 -0
  20. data/docs/dsl/webhooks.md +932 -0
  21. data/docs/dsl/workflows.md +744 -0
  22. data/examples/README.md +569 -0
  23. data/examples/agent_example.rb +86 -0
  24. data/examples/chat_endpoint_agent.rb +118 -0
  25. data/examples/github_webhook_agent.rb +171 -0
  26. data/examples/mcp_agent.rb +158 -0
  27. data/examples/oauth_callback_agent.rb +296 -0
  28. data/examples/stripe_webhook_agent.rb +219 -0
  29. data/examples/webhook_agent.rb +80 -0
  30. data/lib/language_operator/agent/base.rb +110 -0
  31. data/lib/language_operator/agent/executor.rb +440 -0
  32. data/lib/language_operator/agent/instrumentation.rb +54 -0
  33. data/lib/language_operator/agent/metrics_tracker.rb +183 -0
  34. data/lib/language_operator/agent/safety/ast_validator.rb +272 -0
  35. data/lib/language_operator/agent/safety/audit_logger.rb +104 -0
  36. data/lib/language_operator/agent/safety/budget_tracker.rb +175 -0
  37. data/lib/language_operator/agent/safety/content_filter.rb +93 -0
  38. data/lib/language_operator/agent/safety/manager.rb +207 -0
  39. data/lib/language_operator/agent/safety/rate_limiter.rb +150 -0
  40. data/lib/language_operator/agent/safety/safe_executor.rb +115 -0
  41. data/lib/language_operator/agent/scheduler.rb +183 -0
  42. data/lib/language_operator/agent/telemetry.rb +116 -0
  43. data/lib/language_operator/agent/web_server.rb +610 -0
  44. data/lib/language_operator/agent/webhook_authenticator.rb +226 -0
  45. data/lib/language_operator/agent.rb +149 -0
  46. data/lib/language_operator/cli/commands/agent.rb +1252 -0
  47. data/lib/language_operator/cli/commands/cluster.rb +335 -0
  48. data/lib/language_operator/cli/commands/install.rb +404 -0
  49. data/lib/language_operator/cli/commands/model.rb +266 -0
  50. data/lib/language_operator/cli/commands/persona.rb +396 -0
  51. data/lib/language_operator/cli/commands/quickstart.rb +22 -0
  52. data/lib/language_operator/cli/commands/status.rb +156 -0
  53. data/lib/language_operator/cli/commands/tool.rb +537 -0
  54. data/lib/language_operator/cli/commands/use.rb +47 -0
  55. data/lib/language_operator/cli/errors/handler.rb +180 -0
  56. data/lib/language_operator/cli/errors/suggestions.rb +176 -0
  57. data/lib/language_operator/cli/formatters/code_formatter.rb +81 -0
  58. data/lib/language_operator/cli/formatters/log_formatter.rb +290 -0
  59. data/lib/language_operator/cli/formatters/progress_formatter.rb +53 -0
  60. data/lib/language_operator/cli/formatters/table_formatter.rb +179 -0
  61. data/lib/language_operator/cli/formatters/value_formatter.rb +113 -0
  62. data/lib/language_operator/cli/helpers/cluster_context.rb +62 -0
  63. data/lib/language_operator/cli/helpers/cluster_validator.rb +101 -0
  64. data/lib/language_operator/cli/helpers/editor_helper.rb +58 -0
  65. data/lib/language_operator/cli/helpers/kubeconfig_validator.rb +167 -0
  66. data/lib/language_operator/cli/helpers/resource_dependency_checker.rb +74 -0
  67. data/lib/language_operator/cli/helpers/schedule_builder.rb +108 -0
  68. data/lib/language_operator/cli/helpers/user_prompts.rb +69 -0
  69. data/lib/language_operator/cli/main.rb +232 -0
  70. data/lib/language_operator/cli/templates/tools/generic.yaml +66 -0
  71. data/lib/language_operator/cli/wizards/agent_wizard.rb +246 -0
  72. data/lib/language_operator/cli/wizards/quickstart_wizard.rb +588 -0
  73. data/lib/language_operator/client/base.rb +214 -0
  74. data/lib/language_operator/client/config.rb +136 -0
  75. data/lib/language_operator/client/cost_calculator.rb +37 -0
  76. data/lib/language_operator/client/mcp_connector.rb +123 -0
  77. data/lib/language_operator/client.rb +19 -0
  78. data/lib/language_operator/config/cluster_config.rb +101 -0
  79. data/lib/language_operator/config/tool_patterns.yaml +57 -0
  80. data/lib/language_operator/config/tool_registry.rb +96 -0
  81. data/lib/language_operator/config.rb +138 -0
  82. data/lib/language_operator/dsl/adapter.rb +124 -0
  83. data/lib/language_operator/dsl/agent_context.rb +90 -0
  84. data/lib/language_operator/dsl/agent_definition.rb +427 -0
  85. data/lib/language_operator/dsl/chat_endpoint_definition.rb +115 -0
  86. data/lib/language_operator/dsl/config.rb +119 -0
  87. data/lib/language_operator/dsl/context.rb +50 -0
  88. data/lib/language_operator/dsl/execution_context.rb +47 -0
  89. data/lib/language_operator/dsl/helpers.rb +109 -0
  90. data/lib/language_operator/dsl/http.rb +184 -0
  91. data/lib/language_operator/dsl/mcp_server_definition.rb +73 -0
  92. data/lib/language_operator/dsl/parameter_definition.rb +124 -0
  93. data/lib/language_operator/dsl/registry.rb +36 -0
  94. data/lib/language_operator/dsl/shell.rb +125 -0
  95. data/lib/language_operator/dsl/tool_definition.rb +112 -0
  96. data/lib/language_operator/dsl/webhook_authentication.rb +114 -0
  97. data/lib/language_operator/dsl/webhook_definition.rb +106 -0
  98. data/lib/language_operator/dsl/workflow_definition.rb +259 -0
  99. data/lib/language_operator/dsl.rb +160 -0
  100. data/lib/language_operator/errors.rb +60 -0
  101. data/lib/language_operator/kubernetes/client.rb +279 -0
  102. data/lib/language_operator/kubernetes/resource_builder.rb +194 -0
  103. data/lib/language_operator/loggable.rb +47 -0
  104. data/lib/language_operator/logger.rb +141 -0
  105. data/lib/language_operator/retry.rb +123 -0
  106. data/lib/language_operator/retryable.rb +132 -0
  107. data/lib/language_operator/tool_loader.rb +242 -0
  108. data/lib/language_operator/validators.rb +170 -0
  109. data/lib/language_operator/version.rb +1 -1
  110. data/lib/language_operator.rb +65 -3
  111. data/requirements/tasks/challenge.md +9 -0
  112. data/requirements/tasks/iterate.md +36 -0
  113. data/requirements/tasks/optimize.md +21 -0
  114. data/requirements/tasks/tag.md +5 -0
  115. data/test_agent_dsl.rb +108 -0
  116. metadata +503 -20
@@ -0,0 +1,569 @@
1
+ # Agent DSL Examples
2
+
3
+ This directory contains complete, runnable examples demonstrating the Language Operator agent DSL.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Quick Start](#quick-start)
8
+ - [Example Files](#example-files)
9
+ - [Running Examples](#running-examples)
10
+ - [Example Categories](#example-categories)
11
+
12
+ ## Quick Start
13
+
14
+ The fastest way to understand the agent DSL is to review these examples in order:
15
+
16
+ 1. **[agent_example.rb](agent_example.rb)** - Basic scheduled agent
17
+ 2. **[webhook_agent.rb](webhook_agent.rb)** - Simple webhook handler
18
+ 3. **[mcp_agent.rb](mcp_agent.rb)** - MCP server with tools
19
+ 4. **[chat_endpoint_agent.rb](chat_endpoint_agent.rb)** - Chat completion endpoint
20
+
21
+ ## Example Files
22
+
23
+ ### Basic Agents
24
+
25
+ #### [agent_example.rb](agent_example.rb)
26
+ **Type:** Scheduled agent
27
+ **Features:**
28
+ - Cron-based scheduling (`"0 9 * * *"` - daily at 9 AM)
29
+ - Persona definition
30
+ - Objectives list
31
+ - Simple workflow with tool usage
32
+ - Budget and timeout constraints
33
+
34
+ **Use case:** Daily reporting or scheduled maintenance tasks
35
+
36
+ ```ruby
37
+ agent "daily-report-generator" do
38
+ mode :scheduled
39
+ schedule "0 9 * * *"
40
+
41
+ workflow do
42
+ step :generate_report do
43
+ tool 'report_generator'
44
+ end
45
+ end
46
+ end
47
+ ```
48
+
49
+ ### Webhook Agents
50
+
51
+ #### [webhook_agent.rb](webhook_agent.rb)
52
+ **Type:** Reactive webhook handler
53
+ **Features:**
54
+ - Basic webhook endpoint configuration
55
+ - POST method handling
56
+ - Event processing
57
+ - Workflow triggered by webhook events
58
+
59
+ **Use case:** Simple webhook integrations
60
+
61
+ #### [github_webhook_agent.rb](github_webhook_agent.rb)
62
+ **Type:** GitHub webhook integration
63
+ **Features:**
64
+ - HMAC signature verification (GitHub style)
65
+ - X-Hub-Signature-256 authentication
66
+ - Pull request event filtering
67
+ - Multi-step workflow (fetch, analyze, comment)
68
+ - GitHub API integration
69
+
70
+ **Use case:** Automated code review, PR automation
71
+
72
+ **Key configuration:**
73
+ ```ruby
74
+ webhook "/github/pull-request" do
75
+ method :post
76
+ authenticate do
77
+ verify_signature(
78
+ header: 'X-Hub-Signature-256',
79
+ secret: ENV['GITHUB_WEBHOOK_SECRET'],
80
+ algorithm: :sha256
81
+ )
82
+ end
83
+ end
84
+ ```
85
+
86
+ #### [stripe_webhook_agent.rb](stripe_webhook_agent.rb)
87
+ **Type:** Stripe payment webhook handler
88
+ **Features:**
89
+ - Stripe-Signature verification
90
+ - Payment event processing
91
+ - Customer subscription handling
92
+ - Database integration
93
+ - Email notifications
94
+
95
+ **Use case:** Payment processing, subscription management
96
+
97
+ **Key configuration:**
98
+ ```ruby
99
+ webhook "/stripe/events" do
100
+ method :post
101
+ authenticate do
102
+ verify_signature(
103
+ header: 'Stripe-Signature',
104
+ secret: ENV['STRIPE_WEBHOOK_SECRET'],
105
+ algorithm: :sha256
106
+ )
107
+ end
108
+ end
109
+ ```
110
+
111
+ ### MCP Integration
112
+
113
+ #### [mcp_agent.rb](mcp_agent.rb)
114
+ **Type:** MCP server (agent exposing tools)
115
+ **Features:**
116
+ - Tool definition DSL
117
+ - Parameter types (string, number, boolean)
118
+ - Parameter validation (required, regex, custom)
119
+ - Tool execution logic
120
+ - Error handling
121
+
122
+ **Use case:** Creating reusable tools for other agents
123
+
124
+ **Key features:**
125
+ ```ruby
126
+ as_mcp_server do
127
+ tool "process_data" do
128
+ description "Process CSV data"
129
+
130
+ parameter :csv_url do
131
+ type :string
132
+ required true
133
+ validates :url
134
+ end
135
+
136
+ execute do |params|
137
+ # Tool logic here
138
+ end
139
+ end
140
+ end
141
+ ```
142
+
143
+ ### Chat Endpoints
144
+
145
+ #### [chat_endpoint_agent.rb](chat_endpoint_agent.rb)
146
+ **Type:** OpenAI-compatible chat endpoint
147
+ **Features:**
148
+ - OpenAI SDK compatibility
149
+ - System prompt configuration
150
+ - Model parameters (temperature, max_tokens)
151
+ - Streaming support
152
+ - Chat completion API
153
+
154
+ **Use case:** Custom LLM endpoints, agent-as-service
155
+
156
+ **Key features:**
157
+ ```ruby
158
+ as_chat_endpoint do
159
+ system_prompt "You are a helpful technical expert"
160
+ model 'my-agent-v1'
161
+ temperature 0.7
162
+ max_tokens 2000
163
+ end
164
+ ```
165
+
166
+ **API usage:**
167
+ ```bash
168
+ curl -X POST https://<agent-uuid>.webhooks.your-domain.com/v1/chat/completions \
169
+ -H "Content-Type: application/json" \
170
+ -d '{
171
+ "messages": [{"role": "user", "content": "Hello"}],
172
+ "stream": false
173
+ }'
174
+ ```
175
+
176
+ ## Running Examples
177
+
178
+ ### Prerequisites
179
+
180
+ 1. **Environment variables** - Ensure LLM credentials are set:
181
+ ```bash
182
+ export ANTHROPIC_API_KEY="your-key-here"
183
+ export LLM_PROVIDER="anthropic"
184
+ export LLM_MODEL="claude-3-5-sonnet-20241022"
185
+ ```
186
+
187
+ 2. **For webhook examples** - Set webhook secrets:
188
+ ```bash
189
+ export GITHUB_WEBHOOK_SECRET="your-github-secret"
190
+ export STRIPE_WEBHOOK_SECRET="your-stripe-secret"
191
+ ```
192
+
193
+ ### Running Locally
194
+
195
+ #### Method 1: Direct Ruby Execution
196
+
197
+ ```bash
198
+ # Set environment variables
199
+ export AGENT_CODE_PATH="examples/agent_example.rb"
200
+ export AGENT_NAME="daily-report-generator"
201
+ export AGENT_MODE="scheduled"
202
+
203
+ # Run the agent
204
+ ruby -Ilib -e "require 'language_operator'; LanguageOperator::Agent.run"
205
+ ```
206
+
207
+ #### Method 2: Using aictl (via Kubernetes)
208
+
209
+ ```bash
210
+ # Deploy to cluster
211
+ kubectl apply -f - <<EOF
212
+ apiVersion: language-operator.io/v1alpha1
213
+ kind: LanguageAgent
214
+ metadata:
215
+ name: example-agent
216
+ spec:
217
+ code: |
218
+ $(cat examples/agent_example.rb | sed 's/^/ /')
219
+ models:
220
+ - name: claude
221
+ EOF
222
+
223
+ # Check status
224
+ kubectl get languageagent example-agent
225
+
226
+ # View logs
227
+ kubectl logs -f deployment/example-agent
228
+ ```
229
+
230
+ ### Testing Webhook Examples
231
+
232
+ #### Test GitHub webhook locally:
233
+
234
+ ```bash
235
+ # Start the agent (webhook receiver runs automatically)
236
+ bundle exec ruby -Ilib examples/github_webhook_agent.rb
237
+
238
+ # In another terminal, send test webhook
239
+ curl -X POST http://localhost:9393/github/pull-request \
240
+ -H "X-Hub-Signature-256: sha256=<computed-signature>" \
241
+ -H "X-GitHub-Event: pull_request" \
242
+ -H "Content-Type: application/json" \
243
+ -d '{
244
+ "action": "opened",
245
+ "pull_request": {
246
+ "number": 123,
247
+ "title": "Test PR",
248
+ "diff_url": "https://github.com/..."
249
+ }
250
+ }'
251
+ ```
252
+
253
+ #### Computing HMAC signature for testing:
254
+
255
+ ```ruby
256
+ require 'openssl'
257
+
258
+ secret = ENV['GITHUB_WEBHOOK_SECRET']
259
+ payload = '{"action":"opened",...}'
260
+ signature = 'sha256=' + OpenSSL::HMAC.hexdigest('SHA256', secret, payload)
261
+ puts signature
262
+ ```
263
+
264
+ ### Testing MCP Tools
265
+
266
+ ```bash
267
+ # Start MCP server agent
268
+ bundle exec ruby -Ilib examples/mcp_agent.rb
269
+
270
+ # List available tools
271
+ curl -X POST http://localhost:9393/mcp \
272
+ -H "Content-Type: application/json" \
273
+ -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
274
+
275
+ # Call a tool
276
+ curl -X POST http://localhost:9393/mcp \
277
+ -H "Content-Type: application/json" \
278
+ -d '{
279
+ "jsonrpc": "2.0",
280
+ "method": "tools/call",
281
+ "params": {
282
+ "name": "process_data",
283
+ "arguments": {"csv_url": "https://example.com/data.csv"}
284
+ },
285
+ "id": 2
286
+ }'
287
+ ```
288
+
289
+ ### Testing Chat Endpoints
290
+
291
+ ```bash
292
+ # Start chat endpoint agent
293
+ bundle exec ruby -Ilib examples/chat_endpoint_agent.rb
294
+
295
+ # Send chat completion request
296
+ curl -X POST http://localhost:9393/v1/chat/completions \
297
+ -H "Content-Type: application/json" \
298
+ -d '{
299
+ "messages": [
300
+ {"role": "user", "content": "What is Kubernetes?"}
301
+ ],
302
+ "stream": false
303
+ }'
304
+
305
+ # Test streaming
306
+ curl -X POST http://localhost:9393/v1/chat/completions \
307
+ -H "Content-Type: application/json" \
308
+ -d '{
309
+ "messages": [
310
+ {"role": "user", "content": "Explain containers"}
311
+ ],
312
+ "stream": true
313
+ }'
314
+ ```
315
+
316
+ ## Example Categories
317
+
318
+ ### By Execution Mode
319
+
320
+ **Autonomous Agents:**
321
+ - None currently (autonomous mode agents run continuously)
322
+
323
+ **Scheduled Agents:**
324
+ - [agent_example.rb](agent_example.rb) - Daily report generator
325
+
326
+ **Reactive Agents:**
327
+ - [webhook_agent.rb](webhook_agent.rb) - Basic webhook
328
+ - [github_webhook_agent.rb](github_webhook_agent.rb) - GitHub integration
329
+ - [stripe_webhook_agent.rb](stripe_webhook_agent.rb) - Stripe integration
330
+
331
+ ### By Integration Type
332
+
333
+ **Webhooks:**
334
+ - [webhook_agent.rb](webhook_agent.rb)
335
+ - [github_webhook_agent.rb](github_webhook_agent.rb)
336
+ - [stripe_webhook_agent.rb](stripe_webhook_agent.rb)
337
+
338
+ **MCP Servers:**
339
+ - [mcp_agent.rb](mcp_agent.rb)
340
+
341
+ **Chat Endpoints:**
342
+ - [chat_endpoint_agent.rb](chat_endpoint_agent.rb)
343
+
344
+ ### By Complexity
345
+
346
+ **Beginner:**
347
+ 1. [agent_example.rb](agent_example.rb) - Start here
348
+ 2. [webhook_agent.rb](webhook_agent.rb) - Basic webhook
349
+
350
+ **Intermediate:**
351
+ 3. [mcp_agent.rb](mcp_agent.rb) - Tool definitions
352
+ 4. [chat_endpoint_agent.rb](chat_endpoint_agent.rb) - Chat API
353
+
354
+ **Advanced:**
355
+ 5. [github_webhook_agent.rb](github_webhook_agent.rb) - Full GitHub integration
356
+ 6. [stripe_webhook_agent.rb](stripe_webhook_agent.rb) - Payment processing
357
+
358
+ ## Common Patterns
359
+
360
+ ### Pattern: Scheduled Report Generator
361
+
362
+ **When to use:** Daily/weekly reporting, batch processing
363
+
364
+ **Example:** [agent_example.rb](agent_example.rb)
365
+
366
+ **Key features:**
367
+ ```ruby
368
+ mode :scheduled
369
+ schedule "0 9 * * *" # Cron expression
370
+
371
+ workflow do
372
+ step :gather_data do
373
+ tool 'database_query'
374
+ end
375
+
376
+ step :analyze do
377
+ depends_on :gather_data
378
+ prompt "Analyze: {gather_data.output}"
379
+ end
380
+
381
+ step :distribute do
382
+ depends_on :analyze
383
+ tool 'send_email'
384
+ end
385
+ end
386
+ ```
387
+
388
+ ### Pattern: Webhook Event Handler
389
+
390
+ **When to use:** External service integrations (GitHub, Stripe, Slack)
391
+
392
+ **Example:** [github_webhook_agent.rb](github_webhook_agent.rb)
393
+
394
+ **Key features:**
395
+ ```ruby
396
+ mode :reactive
397
+
398
+ webhook "/events" do
399
+ method :post
400
+ authenticate { verify_signature(...) }
401
+ end
402
+
403
+ on_webhook_event do |event|
404
+ # Process event
405
+ end
406
+ ```
407
+
408
+ ### Pattern: Tool Provider (MCP Server)
409
+
410
+ **When to use:** Reusable tools for multiple agents
411
+
412
+ **Example:** [mcp_agent.rb](mcp_agent.rb)
413
+
414
+ **Key features:**
415
+ ```ruby
416
+ as_mcp_server do
417
+ tool "my_tool" do
418
+ parameter :input do
419
+ type :string
420
+ required true
421
+ end
422
+
423
+ execute do |params|
424
+ # Tool logic
425
+ end
426
+ end
427
+ end
428
+ ```
429
+
430
+ ### Pattern: LLM Endpoint (Chat Completion)
431
+
432
+ **When to use:** Exposing agents as OpenAI-compatible APIs
433
+
434
+ **Example:** [chat_endpoint_agent.rb](chat_endpoint_agent.rb)
435
+
436
+ **Key features:**
437
+ ```ruby
438
+ as_chat_endpoint do
439
+ system_prompt "You are an expert..."
440
+ temperature 0.7
441
+ max_tokens 2000
442
+ end
443
+ ```
444
+
445
+ ## Customizing Examples
446
+
447
+ ### Modify Schedules
448
+
449
+ Change cron expressions to adjust timing:
450
+
451
+ ```ruby
452
+ schedule "0 9 * * *" # Daily at 9 AM
453
+ schedule "0 */4 * * *" # Every 4 hours
454
+ schedule "0 9 * * 1" # Every Monday at 9 AM
455
+ schedule "*/15 * * * *" # Every 15 minutes
456
+ ```
457
+
458
+ ### Add Constraints
459
+
460
+ Control costs and resource usage:
461
+
462
+ ```ruby
463
+ constraints do
464
+ timeout '30m'
465
+ daily_budget 1000 # $10/day
466
+ requests_per_minute 10
467
+ blocked_topics ['spam']
468
+ end
469
+ ```
470
+
471
+ ### Customize Personas
472
+
473
+ Adjust agent behavior and expertise:
474
+
475
+ ```ruby
476
+ persona <<~PERSONA
477
+ You are a [role] specializing in [domain].
478
+
479
+ Your expertise includes:
480
+ - [skill 1]
481
+ - [skill 2]
482
+
483
+ When responding:
484
+ - [guideline 1]
485
+ - [guideline 2]
486
+ PERSONA
487
+ ```
488
+
489
+ ## Next Steps
490
+
491
+ After reviewing these examples:
492
+
493
+ 1. **Read the comprehensive guides:**
494
+ - [Agent Reference](../docs/dsl/agent-reference.md) - Complete DSL syntax
495
+ - [Workflows](../docs/dsl/workflows.md) - Workflow patterns
496
+ - [Constraints](../docs/dsl/constraints.md) - Resource limits
497
+ - [Webhooks](../docs/dsl/webhooks.md) - Webhook configuration
498
+ - [MCP Integration](../docs/dsl/mcp-integration.md) - Tool definitions
499
+ - [Chat Endpoints](../docs/dsl/chat-endpoints.md) - Chat APIs
500
+ - [Best Practices](../docs/dsl/best-practices.md) - Production patterns
501
+
502
+ 2. **Create your own agent:**
503
+ - Copy an example that matches your use case
504
+ - Customize persona, schedule, and workflow
505
+ - Test locally first
506
+ - Deploy to Kubernetes when ready
507
+
508
+ 3. **Join the community:**
509
+ - Report issues on GitHub
510
+ - Share your agent examples
511
+ - Contribute improvements
512
+
513
+ ## Troubleshooting
514
+
515
+ ### Agent won't start
516
+
517
+ Check environment variables:
518
+ ```bash
519
+ echo $ANTHROPIC_API_KEY
520
+ echo $LLM_PROVIDER
521
+ echo $LLM_MODEL
522
+ ```
523
+
524
+ ### Webhook authentication fails
525
+
526
+ Verify secret matches:
527
+ ```bash
528
+ echo $GITHUB_WEBHOOK_SECRET
529
+ ```
530
+
531
+ Compute expected signature manually to debug.
532
+
533
+ ### Tool execution errors
534
+
535
+ Check tool implementation:
536
+ - Parameters match schema
537
+ - Execute block returns valid data
538
+ - Error handling is present
539
+
540
+ ### Chat endpoint not responding
541
+
542
+ Verify endpoint is accessible:
543
+ ```bash
544
+ curl http://localhost:9393/v1/models
545
+ ```
546
+
547
+ ## Additional Resources
548
+
549
+ - **Documentation:** [/docs/dsl/](../docs/dsl/)
550
+ - **Main README:** [../README.md](../README.md)
551
+ - **Spec Files:** [/spec/langop/dsl/](../spec/langop/dsl/) - More usage examples
552
+ - **CLI Wizard:** `aictl agent wizard` - Interactive agent creation
553
+
554
+ ## Contributing Examples
555
+
556
+ Have a useful agent pattern? Contribute it!
557
+
558
+ 1. Create a new example file
559
+ 2. Follow the existing format
560
+ 3. Add comprehensive comments
561
+ 4. Update this README
562
+ 5. Submit a pull request
563
+
564
+ Good examples to contribute:
565
+ - Slack bot integrations
566
+ - Data pipeline agents
567
+ - Monitoring and alerting agents
568
+ - Custom MCP tools
569
+ - Domain-specific agents (legal, financial, medical, etc.)
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Example of agent DSL usage
5
+ #
6
+ # This demonstrates the agent DSL syntax that will be synthesized
7
+ # by the Language Operator from natural language instructions.
8
+
9
+ require_relative '../lib/langop'
10
+
11
+ # Define an agent
12
+ Langop::Dsl.load_agent_file(__FILE__)
13
+
14
+ agent 'kubernetes-news' do
15
+ description 'Daily Kubernetes news summarization agent'
16
+
17
+ # Distilled persona (would come from operator synthesis)
18
+ persona <<~PERSONA
19
+ You are a technical writer specializing in Kubernetes. When researching and
20
+ summarizing news, maintain a clear and precise tone, always cite your sources,
21
+ use proper technical terminology, and make complex topics accessible without
22
+ unnecessary jargon. Your summaries should be educational and well-structured.
23
+ PERSONA
24
+
25
+ # Extracted from: "once a day, preferably around lunchtime"
26
+ schedule '0 12 * * *'
27
+
28
+ # Extracted from instructions
29
+ objectives [
30
+ 'Search for recent Kubernetes news using web_search tool',
31
+ 'Provide a concise summary of findings'
32
+ ]
33
+
34
+ # Synthesized workflow
35
+ workflow do
36
+ step :search do
37
+ tool 'web_search'
38
+ params query: 'Kubernetes news latest'
39
+ end
40
+
41
+ step :summarize do
42
+ depends_on :search
43
+ prompt 'Provide a concise summary of these Kubernetes news items: {search.output}'
44
+ end
45
+ end
46
+
47
+ # Inferred constraints
48
+ constraints do
49
+ max_iterations 20
50
+ timeout '5m'
51
+ end
52
+
53
+ # Output destination
54
+ output do
55
+ workspace 'summaries/kubernetes-{date}.md'
56
+ end
57
+ end
58
+
59
+ # When run directly, execute the agent
60
+ if __FILE__ == $PROGRAM_NAME
61
+ puts '=' * 60
62
+ puts 'Agent DSL Example'
63
+ puts '=' * 60
64
+ puts
65
+
66
+ agent = Langop::Dsl.agent_registry.get('kubernetes-news')
67
+
68
+ if agent
69
+ puts "✅ Agent loaded: #{agent.name}"
70
+ puts "📝 Description: #{agent.description}"
71
+ puts "🗓️ Schedule: #{agent.schedule}"
72
+ puts "📋 Objectives: #{agent.objectives.size}"
73
+ puts "⚙️ Workflow steps: #{agent.workflow&.steps&.size || 0}"
74
+ puts "📊 Constraints: #{agent.constraints.inspect}"
75
+ puts
76
+
77
+ puts 'To run this agent:'
78
+ puts ' agent.run!'
79
+ puts
80
+
81
+ # Uncomment to actually run:
82
+ # agent.run!
83
+ else
84
+ puts '❌ Failed to load agent'
85
+ end
86
+ end