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,671 @@
1
+ # Constraints Reference
2
+
3
+ Complete reference for configuring agent constraints in the Language Operator DSL.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Time Constraints](#time-constraints)
9
+ - [Resource Constraints](#resource-constraints)
10
+ - [Budget Constraints](#budget-constraints)
11
+ - [Rate Limiting](#rate-limiting)
12
+ - [Content Filtering](#content-filtering)
13
+ - [Complete Examples](#complete-examples)
14
+
15
+ ## Overview
16
+
17
+ Constraints define limits on agent behavior and resource usage. They help:
18
+ - Prevent runaway costs
19
+ - Enforce rate limits
20
+ - Block inappropriate content
21
+ - Manage resource consumption
22
+ - Ensure timely execution
23
+
24
+ Define constraints in an agent's `constraints` block:
25
+
26
+ ```ruby
27
+ agent "my-agent" do
28
+ constraints do
29
+ timeout '30m'
30
+ daily_budget 1000
31
+ requests_per_minute 10
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## Time Constraints
37
+
38
+ ### Timeout
39
+
40
+ Maximum execution time for the entire agent workflow or autonomous loop iteration.
41
+
42
+ ```ruby
43
+ constraints do
44
+ timeout '30m' # 30 minutes
45
+ end
46
+ ```
47
+
48
+ **Format:**
49
+ - `'5m'` - 5 minutes
50
+ - `'2h'` - 2 hours
51
+ - `'30s'` - 30 seconds
52
+ - `'1h30m'` - 1 hour 30 minutes
53
+
54
+ **Default:** No timeout (runs indefinitely)
55
+
56
+ **Use cases:**
57
+ - Prevent hung workflows
58
+ - Enforce SLA requirements
59
+ - Manage computational costs
60
+
61
+ **Example:**
62
+
63
+ ```ruby
64
+ agent "time-sensitive-reporter" do
65
+ constraints do
66
+ timeout '15m' # Must complete within 15 minutes
67
+ end
68
+
69
+ workflow do
70
+ step :fetch_data do
71
+ tool 'slow_database_query'
72
+ timeout '5m' # Step-level timeout
73
+ end
74
+
75
+ step :analyze do
76
+ prompt "Analyze: {fetch_data.output}"
77
+ # Inherits remaining agent timeout
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
83
+ ### Max Iterations
84
+
85
+ Maximum number of iterations for autonomous agents or workflow loops.
86
+
87
+ ```ruby
88
+ constraints do
89
+ max_iterations 100
90
+ end
91
+ ```
92
+
93
+ **Default:** No limit
94
+
95
+ **Use cases:**
96
+ - Prevent infinite loops
97
+ - Control cost in autonomous mode
98
+ - Enforce bounded execution
99
+
100
+ **Example:**
101
+
102
+ ```ruby
103
+ agent "bounded-monitor" do
104
+ mode :autonomous
105
+
106
+ constraints do
107
+ max_iterations 50 # Stop after 50 checks
108
+ end
109
+
110
+ objectives [
111
+ "Check system status every 5 minutes",
112
+ "Alert if issues found"
113
+ ]
114
+ end
115
+ ```
116
+
117
+ ## Resource Constraints
118
+
119
+ ### Memory Limit
120
+
121
+ Maximum memory the agent process can use.
122
+
123
+ ```ruby
124
+ constraints do
125
+ memory '2Gi' # 2 Gigabytes
126
+ end
127
+ ```
128
+
129
+ **Format:**
130
+ - `'512Mi'` - 512 Megabytes
131
+ - `'2Gi'` - 2 Gigabytes
132
+ - `'100Mi'` - 100 Megabytes
133
+
134
+ **Default:** No memory limit (uses container/pod limits)
135
+
136
+ **Note:** This sets a soft limit. The Kubernetes pod should have matching resource limits.
137
+
138
+ **Example:**
139
+
140
+ ```ruby
141
+ agent "memory-intensive-processor" do
142
+ constraints do
143
+ memory '4Gi' # Allow up to 4GB
144
+ timeout '1h'
145
+ end
146
+
147
+ workflow do
148
+ step :process_large_dataset do
149
+ tool 'data_processor'
150
+ # May use significant memory
151
+ end
152
+ end
153
+ end
154
+ ```
155
+
156
+ ## Budget Constraints
157
+
158
+ Control costs by limiting LLM API spending.
159
+
160
+ ### Daily Budget
161
+
162
+ Maximum spending per day (in cents).
163
+
164
+ ```ruby
165
+ constraints do
166
+ daily_budget 1000 # $10.00 per day
167
+ end
168
+ ```
169
+
170
+ **Units:** Cents (100 = $1.00)
171
+
172
+ **Behavior:**
173
+ - Agent stops when daily budget exceeded
174
+ - Budget resets at midnight UTC
175
+ - Tracked across all LLM calls
176
+
177
+ ### Hourly Budget
178
+
179
+ Maximum spending per hour (in cents).
180
+
181
+ ```ruby
182
+ constraints do
183
+ hourly_budget 100 # $1.00 per hour
184
+ end
185
+ ```
186
+
187
+ **Units:** Cents
188
+
189
+ **Behavior:**
190
+ - Agent pauses when hourly budget exceeded
191
+ - Resumes at the next hour
192
+ - Useful for rate-limiting expensive operations
193
+
194
+ ### Token Budget
195
+
196
+ Maximum tokens to consume (input + output combined).
197
+
198
+ ```ruby
199
+ constraints do
200
+ token_budget 100000 # 100k tokens max
201
+ end
202
+ ```
203
+
204
+ **Units:** Tokens
205
+
206
+ **Behavior:**
207
+ - Tracks total tokens across all LLM calls
208
+ - Stops when budget exhausted
209
+ - Resets based on agent schedule
210
+
211
+ ### Combined Budget Constraints
212
+
213
+ ```ruby
214
+ agent "cost-controlled-agent" do
215
+ constraints do
216
+ daily_budget 2000 # $20/day maximum
217
+ hourly_budget 200 # $2/hour maximum
218
+ token_budget 500000 # 500k tokens maximum per day
219
+ end
220
+
221
+ # Agent will stop if ANY limit is reached
222
+ end
223
+ ```
224
+
225
+ **Example:**
226
+
227
+ ```ruby
228
+ agent "budget-conscious-analyst" do
229
+ description "Analyze data within strict budget limits"
230
+
231
+ mode :scheduled
232
+ schedule "0 9 * * *" # Daily at 9 AM
233
+
234
+ constraints do
235
+ timeout '30m'
236
+ daily_budget 500 # $5/day max
237
+ token_budget 100000 # 100k tokens max
238
+ end
239
+
240
+ workflow do
241
+ step :analyze do
242
+ prompt "Provide a concise analysis of today's sales data"
243
+ # Encouraged to be brief due to token budget
244
+ end
245
+ end
246
+ end
247
+ ```
248
+
249
+ ## Rate Limiting
250
+
251
+ Control request frequency to prevent abuse and manage costs.
252
+
253
+ ### Requests Per Minute
254
+
255
+ ```ruby
256
+ constraints do
257
+ requests_per_minute 10 # Max 10 LLM calls per minute
258
+ end
259
+ ```
260
+
261
+ **Behavior:**
262
+ - Enforced across all LLM API calls
263
+ - Agent pauses if limit exceeded
264
+ - Useful for staying within API quotas
265
+
266
+ ### Requests Per Hour
267
+
268
+ ```ruby
269
+ constraints do
270
+ requests_per_hour 100 # Max 100 LLM calls per hour
271
+ end
272
+ ```
273
+
274
+ ### Requests Per Day
275
+
276
+ ```ruby
277
+ constraints do
278
+ requests_per_day 1000 # Max 1000 LLM calls per day
279
+ end
280
+ ```
281
+
282
+ ### Rate Limit (Generic)
283
+
284
+ Alternative syntax for any time period:
285
+
286
+ ```ruby
287
+ constraints do
288
+ rate_limit requests: 60, period: '1h' # 60 requests per hour
289
+ end
290
+ ```
291
+
292
+ ### Combined Rate Limits
293
+
294
+ ```ruby
295
+ agent "rate-limited-agent" do
296
+ constraints do
297
+ requests_per_minute 5 # Burst protection
298
+ requests_per_hour 200 # Hourly cap
299
+ requests_per_day 2000 # Daily cap
300
+ end
301
+
302
+ # Agent respects all limits (most restrictive applies)
303
+ end
304
+ ```
305
+
306
+ **Example:**
307
+
308
+ ```ruby
309
+ agent "monitoring-agent" do
310
+ mode :autonomous
311
+
312
+ constraints do
313
+ requests_per_minute 2 # Check every 30 seconds max
314
+ requests_per_day 2880 # 2 per minute * 60 min * 24 hr
315
+ daily_budget 500 # $5/day budget
316
+ end
317
+
318
+ objectives [
319
+ "Monitor system health continuously",
320
+ "Alert on anomalies"
321
+ ]
322
+ end
323
+ ```
324
+
325
+ ## Content Filtering
326
+
327
+ Block or filter inappropriate content and topics.
328
+
329
+ ### Blocked Topics
330
+
331
+ Prevent the agent from processing certain topics:
332
+
333
+ ```ruby
334
+ constraints do
335
+ blocked_topics ['violence', 'illegal-activity', 'adult-content']
336
+ end
337
+ ```
338
+
339
+ **Behavior:**
340
+ - Agent rejects requests containing blocked topics
341
+ - Content moderation applied to inputs and outputs
342
+ - Logged for audit purposes
343
+
344
+ ### Blocked Patterns
345
+
346
+ Block content matching regex patterns:
347
+
348
+ ```ruby
349
+ constraints do
350
+ blocked_patterns [
351
+ /\b\d{3}-\d{2}-\d{4}\b/, # SSN pattern
352
+ /\b\d{16}\b/, # Credit card number
353
+ /password\s*[:=]/i # Password disclosure
354
+ ]
355
+ end
356
+ ```
357
+
358
+ **Behavior:**
359
+ - Regex matched against all inputs and outputs
360
+ - Request rejected if pattern found
361
+ - Helps prevent data leakage
362
+
363
+ ### Combined Content Filtering
364
+
365
+ ```ruby
366
+ agent "safe-agent" do
367
+ constraints do
368
+ blocked_topics [
369
+ 'violence',
370
+ 'hate-speech',
371
+ 'illegal-activity',
372
+ 'self-harm'
373
+ ]
374
+
375
+ blocked_patterns [
376
+ /\b\d{3}-\d{2}-\d{4}\b/, # SSN
377
+ /\b\d{16}\b/, # Credit card
378
+ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i # Email addresses
379
+ ]
380
+ end
381
+ end
382
+ ```
383
+
384
+ **Example:**
385
+
386
+ ```ruby
387
+ agent "customer-service-agent" do
388
+ description "Safe customer service assistant"
389
+
390
+ mode :reactive
391
+
392
+ persona <<~PERSONA
393
+ You are a helpful customer service representative.
394
+ Always maintain a professional and respectful tone.
395
+ PERSONA
396
+
397
+ constraints do
398
+ # Safety constraints
399
+ blocked_topics [
400
+ 'violence',
401
+ 'hate-speech',
402
+ 'illegal-activity'
403
+ ]
404
+
405
+ # PII protection
406
+ blocked_patterns [
407
+ /\b\d{3}-\d{2}-\d{4}\b/, # SSN
408
+ /\b\d{16}\b/, # Credit card
409
+ ]
410
+
411
+ # Rate limiting
412
+ requests_per_minute 30
413
+ requests_per_hour 500
414
+
415
+ # Budget
416
+ hourly_budget 100 # $1/hour
417
+ daily_budget 1000 # $10/day
418
+
419
+ # Time limits
420
+ timeout '5m'
421
+ end
422
+ end
423
+ ```
424
+
425
+ ## Complete Examples
426
+
427
+ ### Production ETL Agent
428
+
429
+ ```ruby
430
+ agent "production-etl" do
431
+ description "Production-grade ETL with comprehensive constraints"
432
+
433
+ mode :scheduled
434
+ schedule "0 2 * * *" # 2 AM daily
435
+
436
+ constraints do
437
+ # Time constraints
438
+ timeout '2h' # Must complete within 2 hours
439
+ max_iterations 10 # Max 10 retry attempts
440
+
441
+ # Resource constraints
442
+ memory '8Gi' # Allow 8GB memory for large datasets
443
+
444
+ # Budget constraints
445
+ daily_budget 2000 # $20/day maximum
446
+ token_budget 1000000 # 1M tokens max
447
+
448
+ # Rate limiting (avoid API throttling)
449
+ requests_per_minute 30
450
+ requests_per_hour 1000
451
+
452
+ # Content filtering
453
+ blocked_patterns [
454
+ /\b\d{3}-\d{2}-\d{4}\b/, # Prevent SSN in logs
455
+ /password\s*[:=]/i # Prevent password leakage
456
+ ]
457
+ end
458
+
459
+ workflow do
460
+ step :extract do
461
+ tool 'database_extract'
462
+ timeout '30m' # Step-level timeout
463
+ end
464
+
465
+ step :transform do
466
+ depends_on :extract
467
+ tool 'data_transform'
468
+ timeout '45m'
469
+ end
470
+
471
+ step :load do
472
+ depends_on :transform
473
+ tool 'warehouse_load'
474
+ timeout '30m'
475
+ retry_on_failure max_attempts: 3
476
+ end
477
+ end
478
+ end
479
+ ```
480
+
481
+ ### Cost-Optimized Analysis Agent
482
+
483
+ ```ruby
484
+ agent "frugal-analyst" do
485
+ description "Cost-optimized analysis with strict budgets"
486
+
487
+ mode :scheduled
488
+ schedule "0 9 * * 1-5" # Weekdays at 9 AM
489
+
490
+ constraints do
491
+ # Aggressive budget controls
492
+ daily_budget 100 # Only $1/day
493
+ hourly_budget 50 # $0.50/hour
494
+ token_budget 50000 # 50k tokens max
495
+
496
+ # Rate limits to spread requests
497
+ requests_per_minute 2 # Slow and steady
498
+ requests_per_hour 60
499
+
500
+ # Reasonable timeout
501
+ timeout '30m'
502
+ end
503
+
504
+ workflow do
505
+ step :analyze do
506
+ prompt "Provide a BRIEF analysis (under 200 words) of today's key metrics"
507
+ # Prompt emphasizes brevity to save tokens
508
+ end
509
+
510
+ step :distribute do
511
+ depends_on :analyze
512
+ tool 'send_email'
513
+ params(
514
+ to: 'team@company.com',
515
+ subject: 'Daily Brief',
516
+ body: '{analyze.output}'
517
+ )
518
+ end
519
+ end
520
+ end
521
+ ```
522
+
523
+ ### High-Throughput Webhook Handler
524
+
525
+ ```ruby
526
+ agent "webhook-processor" do
527
+ description "Handle high-volume webhook events"
528
+
529
+ mode :reactive
530
+
531
+ webhook "/api/events" do
532
+ method :post
533
+ authenticate { verify_api_key }
534
+ end
535
+
536
+ constraints do
537
+ # High throughput settings
538
+ requests_per_minute 120 # 2/second burst
539
+ requests_per_hour 5000 # 83/minute sustained
540
+ requests_per_day 50000 # Room for spikes
541
+
542
+ # Generous budget for high volume
543
+ hourly_budget 500 # $5/hour
544
+ daily_budget 10000 # $100/day
545
+
546
+ # Quick timeout per event
547
+ timeout '30s' # Process each event fast
548
+
549
+ # Memory for concurrent processing
550
+ memory '4Gi'
551
+
552
+ # Safety
553
+ blocked_topics ['spam', 'malicious-content']
554
+ end
555
+
556
+ on_webhook_event do |event|
557
+ # Process event quickly within 30s timeout
558
+ end
559
+ end
560
+ ```
561
+
562
+ ### Secure Customer Data Agent
563
+
564
+ ```ruby
565
+ agent "secure-data-processor" do
566
+ description "Process customer data with strong PII protection"
567
+
568
+ mode :scheduled
569
+ schedule "0 0 * * *" # Midnight daily
570
+
571
+ constraints do
572
+ # Time and resource limits
573
+ timeout '1h'
574
+ memory '4Gi'
575
+
576
+ # Budget
577
+ daily_budget 1000 # $10/day
578
+
579
+ # Comprehensive PII filtering
580
+ blocked_patterns [
581
+ # SSN
582
+ /\b\d{3}-\d{2}-\d{4}\b/,
583
+ # Credit card
584
+ /\b(?:\d{4}[-\s]?){3}\d{4}\b/,
585
+ # Phone numbers
586
+ /\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/,
587
+ # Email addresses
588
+ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i,
589
+ # IP addresses
590
+ /\b(?:\d{1,3}\.){3}\d{1,3}\b/,
591
+ # API keys (common formats)
592
+ /\b[A-Za-z0-9_-]{32,}\b/
593
+ ]
594
+
595
+ # Sensitive topics
596
+ blocked_topics [
597
+ 'medical-records',
598
+ 'financial-details',
599
+ 'authentication-credentials'
600
+ ]
601
+
602
+ # Rate limiting
603
+ requests_per_minute 10
604
+ end
605
+
606
+ workflow do
607
+ step :process_data do
608
+ tool 'data_anonymizer'
609
+ # Ensures PII is removed before analysis
610
+ end
611
+
612
+ step :analyze_anonymized do
613
+ depends_on :process_data
614
+ prompt "Analyze this anonymized data: {process_data.output}"
615
+ end
616
+ end
617
+ end
618
+ ```
619
+
620
+ ## Best Practices
621
+
622
+ ### Time Constraints
623
+
624
+ 1. **Always set timeouts for production** - Prevent indefinite hangs
625
+ 2. **Set realistic limits** - Allow enough time for completion
626
+ 3. **Use step-level timeouts** - Granular control over slow operations
627
+ 4. **Monitor timeout events** - Optimize workflows that frequently timeout
628
+
629
+ ### Resource Constraints
630
+
631
+ 1. **Match Kubernetes limits** - Ensure container resources align
632
+ 2. **Test with realistic data** - Verify memory limits are sufficient
633
+ 3. **Monitor resource usage** - Track actual consumption vs. limits
634
+
635
+ ### Budget Constraints
636
+
637
+ 1. **Start conservative** - Begin with low budgets, increase as needed
638
+ 2. **Use hourly + daily limits** - Prevent burst spending
639
+ 3. **Track costs** - Monitor actual spending vs. budgets
640
+ 4. **Set token budgets** - Prevent excessive LLM usage
641
+ 5. **Review monthly** - Adjust budgets based on actual costs
642
+
643
+ ### Rate Limiting
644
+
645
+ 1. **Layer limits** - Use minute, hour, and day limits together
646
+ 2. **Account for bursts** - Minute limit should allow reasonable bursts
647
+ 3. **Match API quotas** - Stay within provider rate limits
648
+ 4. **Monitor rejections** - Track how often limits are hit
649
+
650
+ ### Content Filtering
651
+
652
+ 1. **Block sensitive patterns** - Always filter PII (SSN, credit cards, etc.)
653
+ 2. **Use broad patterns** - Catch variations (with/without dashes, etc.)
654
+ 3. **Test filters** - Verify patterns match intended content
655
+ 4. **Log blocks** - Audit what content is being filtered
656
+ 5. **Review regularly** - Update patterns as new risks emerge
657
+
658
+ ### Combined Constraints
659
+
660
+ 1. **Use multiple constraint types** - Defense in depth
661
+ 2. **Make budgets compatible** - Ensure daily budget allows hourly * 24
662
+ 3. **Test limits** - Verify constraints work as expected
663
+ 4. **Document rationale** - Explain why specific limits were chosen
664
+ 5. **Monitor violations** - Track which constraints are hit most often
665
+
666
+ ## See Also
667
+
668
+ - [Agent Reference](agent-reference.md) - Complete agent DSL reference
669
+ - [Workflows](workflows.md) - Workflow definition guide
670
+ - [Best Practices](best-practices.md) - Production deployment patterns
671
+ - [Webhooks](webhooks.md) - Reactive agent configuration