-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththe-forge.yaml
More file actions
631 lines (546 loc) · 24.7 KB
/
the-forge.yaml
File metadata and controls
631 lines (546 loc) · 24.7 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# the-forge.yaml — Constitutional Development Lifecycle
#
# Merged from aegis-examples and aegis-orchestrator reference implementations.
#
# Full FSM — all blueprint phases:
#
# REQUIREMENTS ──always──► ARCHITECTURE ──always──► ARCH_APPROVAL
# ▲ │
# │ input_equals: revise ◄───┤
# │ input_equals: approve
# ▼
# TEST_DESIGN ──always──► TEST_APPROVAL
# ▲ │
# │ input_equals: revise ◄────────────────────────── ┤
# │ input_equals: approve
# ▼
# ◄── on_failure ─── IMPLEMENTATION ◄──────── score_below 0.8 ──┐
# │ │
# │ on_success │
# ▼ │
# ◄── exit_code_non_zero ── TEST ── exit_code_zero ──► AUDIT ────┘
# │ consensus >= 0.8
# ▼
# FINAL_APPROVAL (Human)
# ◄── input_equals: revise ─────────────────────────── │
# DEPLOYMENT_REJECTED ◄─ input_equals: reject ─── │
# │ input_equals: approve
# ▼
# DEPLOY ──► LEARN ──► (complete)
#
# Blueprint phases (ai-forge-blueprint.md §4):
# ANALYZING → REQUIREMENTS
# AWAITING_ARCH_APPROVAL→ ARCHITECTURE + ARCH_APPROVAL
# AWAITING_TEST_APPROVAL→ TEST_DESIGN + TEST_APPROVAL
# CODING → IMPLEMENTATION + TEST (loop on test failure)
# AUDITING → AUDIT (ReviewerAI + CriticAI + SecurityAI in parallel)
# AWAITING_FINAL_APPROVAL→ FINAL_APPROVAL
# COMPLETE → DEPLOY + LEARN (CuratorAI)
#
# Required workflow inputs:
# task — High-level description of what to build or implement.
# test_command — Shell command to run automated tests
# (e.g. "python -m pytest /workspace/tests/ -v").
#
# Optional inputs:
# project_name — Human-readable project name (shown in prompts and deploy env).
# context — Additional background forwarded to RequirementsAI.
#
# Usage:
# POST /v1/workflows/executions
# {
# "workflow_name": "the-forge",
# "input": {
# "task": "Implement a thread-safe LRU cache in Python with full test coverage",
# "test_command": "python -m pytest /workspace/tests/ -v",
# "project_name": "my-project"
# }
# }
#
# Human gates (signal API):
# POST /v1/workflows/executions/<execution_id>/signal
# { "response": "approve" | "revise", "feedback": "optional guidance" }
# Final approval:
# { "response": "approve" | "revise" | "reject", "feedback": "..." }
#
# FSM:
# REQUIREMENTS
# └──always──► ARCHITECTURE
# └──always──► ARCH_APPROVAL (Human gate)
# ├──input_equals: approve──► TEST_DESIGN
# └──input_equals: revise──► ARCHITECTURE (loop)
# └──always──► TEST_APPROVAL (Human gate)
# ├──input_equals: approve──► IMPLEMENTATION
# └──input_equals: revise──► TEST_DESIGN (loop)
# └──on_success──► TEST (System)
# │
# ◄── exit_code_non_zero ──────────────────────────── ┘
# │ exit_code_zero
# ▼
# AUDIT (ParallelAgents)
# ◄── score_below 0.8 ─────────────────────────────── ┤ (loop → IMPLEMENTATION)
# │ consensus >= 0.8
# ▼
# FINAL_APPROVAL (Human gate)
# ├──input_equals: approve──► DEPLOY
# ├──input_equals: revise──► IMPLEMENTATION (loop)
# └──input_equals: reject──► DEPLOYMENT_REJECTED
# └──on_success──► LEARN (CuratorAI)
#
# This workflow demonstrates:
# - 7 specialized agents working in sequence
# - 3 human-in-the-loop approval gates (arch, test, final)
# - Parallel execution of code reviewers (code quality, design critique, security audit)
# - Gradient validation at each stage
# - CuratorAI constitutional learning at the end
# - Shared persistent /workspace volume across all agent states
apiVersion: 100monkeys.ai/v1
kind: Workflow
metadata:
name: "the-forge"
version: "1.0.0"
description: |-
Full constitutional development lifecycle.
RequirementsAI → ArchitectAI → [human gate] → TesterAI → [human gate] →
CoderAI → automated tests → parallel audit (ReviewerAI + CriticAI + SecurityAI)
→ [human gate] → deploy → CuratorAI constitutional learning.
labels:
category: "development"
pattern: "constitutional-pipeline"
requires-human: "true"
stability: "production"
spec:
context:
review_threshold: 0.8
# Shared ephemeral workspace — all agent and system states mount /workspace.
storage:
workspace:
storage_class: "ephemeral"
ttl_hours: 6
size_limit: "2Gi"
initial_state: REQUIREMENTS
states:
# ==========================================================================
# Phase 1: ANALYZING
# RequirementsAI decomposes the task into formal requirements and acceptance
# criteria.
# ==========================================================================
REQUIREMENTS:
kind: Agent
agent: "requirements-analyst"
isolation: docker
volumes:
- volume: "{{workflow.storage.workspace}}"
mount_path: "/workspace"
access_mode: "read-write"
input: |-
# Development Task
{{workflow.task}}
{{#if workflow.context}}
# Additional Context
{{workflow.context}}
{{/if}}
Analyse this task and produce a comprehensive requirements specification.
Include:
1. Functional requirements (numbered list)
2. Non-functional requirements (performance, security, maintainability)
3. Acceptance criteria (testable, specific)
4. Edge cases and failure modes
5. External dependencies and integration points
Write the specification to /workspace/requirements.md.
timeout: 3m
transitions:
- condition: on_success
target: ARCHITECTURE
- condition: on_failure
target: FAILED
# ==========================================================================
# Phase 2a: AWAITING_ARCH_APPROVAL — design
# ArchitectAI designs the technical solution against the requirements.
# CriticAI runs implicitly as the adversarial inner-loop judge during the
# agent's own execution cycle.
# ==========================================================================
ARCHITECTURE:
kind: Agent
agent: "architect-agent"
isolation: docker
volumes:
- volume: "{{workflow.storage.workspace}}"
mount_path: "/workspace"
access_mode: "read-write"
input: |-
# Requirements Specification
{{REQUIREMENTS.output}}
Design a complete technical architecture for this project. Produce:
1. High-level system design with component diagram (Mermaid.js)
2. Component breakdown and responsibilities
3. Data models and schemas
4. API contracts / interfaces
5. Technology choices with rationale
6. File structure: list every file to create or modify
7. Step-by-step implementation instructions for the CoderAI
8. Acceptance criteria the automated tests must satisfy
Write the architecture to /workspace/architecture.md.
timeout: 5m
transitions:
- condition: on_success
target: ARCH_APPROVAL
- condition: on_failure
target: FAILED
# ==========================================================================
# Phase 2b: AWAITING_ARCH_APPROVAL — human gate
# Creator reviews the architecture and diagrams before any tests are written.
# ==========================================================================
ARCH_APPROVAL:
kind: Human
prompt: |-
# The Forge — Architecture Approval
## Task
{{workflow.task}}
## Requirements
{{REQUIREMENTS.output}}
## Architecture Design
{{ARCHITECTURE.output}}
---
Review the architecture above. The TesterAI will write test cases based
on this design before any implementation code is written (TDD).
- Type **"approve"** to proceed to test design
- Type **"revise"** to send the architecture back for rework
(add feedback below to guide the revision)
timeout: 3600s
default_response: "revise"
transitions:
- condition: input_equals
value: "approve"
target: TEST_DESIGN
- condition: input_equals
value: "revise"
target: ARCHITECTURE
feedback: "{{human.feedback}}"
# ==========================================================================
# Phase 3a: AWAITING_TEST_APPROVAL — test generation
# TesterAI writes the full test suite *before* implementation (strict TDD).
# ==========================================================================
TEST_DESIGN:
kind: Agent
agent: "tester-agent"
isolation: docker
volumes:
- volume: "{{workflow.storage.workspace}}"
mount_path: "/workspace"
access_mode: "read-write"
input: |-
# Requirements
{{REQUIREMENTS.output}}
# Architecture
{{ARCHITECTURE.output}}
Generate a comprehensive test suite that the CoderAI must make pass.
This follows strict TDD — tests are written before the implementation.
Produce:
1. Unit tests for each component (with full test code, not pseudo-code)
2. Integration test scenarios
3. Edge case and negative tests
4. Test data setup / teardown
5. Coverage targets (aim for ≥ 90% line and branch coverage)
Write all test files to /workspace/tests/ using the project's test runner
convention. The test command that will be used is:
{{workflow.test_command}}
Also write /workspace/test-strategy.md summarising the strategy.
timeout: 5m
transitions:
- condition: on_success
target: TEST_APPROVAL
- condition: on_failure
target: FAILED
# ==========================================================================
# Phase 3b: AWAITING_TEST_APPROVAL — human gate
# Creator approves the test suite before CoderAI writes a single line of
# implementation code.
# ==========================================================================
TEST_APPROVAL:
kind: Human
prompt: |-
# The Forge — Test Suite Approval
## Task
{{workflow.task}}
## Architecture
{{ARCHITECTURE.output}}
## Proposed Test Suite
{{TEST_DESIGN.output}}
---
The CoderAI will now write implementation code solely to make these
tests pass. No implementation exists yet.
- Type **"approve"** to proceed to implementation
- Type **"revise"** to send the test suite back for rework
timeout: 3600s
default_response: "revise"
transitions:
- condition: input_equals
value: "approve"
target: IMPLEMENTATION
- condition: input_equals
value: "revise"
target: TEST_DESIGN
feedback: "{{human.feedback}}"
# ==========================================================================
# Phase 4: CODING — implementation
# CoderAI writes the implementation to make the approved test suite pass.
# After writing code the pipeline immediately runs the tests (next state).
# If tests fail, or the audit panel rejects, feedback loops back here.
# ==========================================================================
IMPLEMENTATION:
kind: Agent
agent: "coder-agent"
isolation: docker
volumes:
- volume: "{{workflow.storage.workspace}}"
mount_path: "/workspace"
access_mode: "read-write"
input: |-
# Requirements
{{REQUIREMENTS.output}}
# Architecture
{{ARCHITECTURE.output}}
# Test Suite (you must make these tests pass)
{{TEST_DESIGN.output}}
{{#if state.feedback}}
# Previous Attempt Failed
{{state.feedback}}
Fix the issues described above. The tests are already written — do not
modify them. Only change implementation files.
{{/if}}
Write production-ready implementation code to /workspace/ following the
architecture specification. Include:
- Complete, runnable implementation (every file listed in the architecture)
- Proper error handling and input validation
- Inline documentation (docstrings / JSDoc)
- All code required to make the test suite pass
Do NOT modify files under /workspace/tests/.
timeout: 15m
transitions:
- condition: on_success
target: TEST
- condition: on_failure
target: FAILED
# ==========================================================================
# Phase 4 (continued): CODING — Secure Execution Environment test run
# Automated tests verify the implementation. Zero exit code advances to
# the audit panel. Non-zero loops back to IMPLEMENTATION with test output.
# ==========================================================================
TEST:
kind: System
command: "{{workflow.test_command}}"
workdir: /workspace
timeout: 10m
transitions:
- condition: exit_code_zero
target: AUDIT
- condition: exit_code_non_zero
target: IMPLEMENTATION
feedback: |-
The automated test suite failed. Fix the implementation to make all
tests pass. Do NOT modify test files.
Test output (stderr):
{{TEST.output.stderr}}
stdout:
{{TEST.output.stdout}}
# ==========================================================================
# Phase 5: AUDITING
# Three specialist agents audit in parallel once tests pass:
# ReviewerAI (The Guardian) — constitutional conformance audit
# CriticAI (The Adversary) — adversarial design & logic critique
# SecurityAI (The Sentinel) — OWASP Top 10 / SAST security audit
#
# Weighted-average consensus >= 0.8 advances to FINAL_APPROVAL.
# Below threshold loops back to IMPLEMENTATION with all three reports.
# ==========================================================================
AUDIT:
kind: ParallelAgents
agents:
- agent: "code-reviewer-agent"
input: |-
Perform a constitutional conformance audit of the implementation.
Check:
- Adherence to architectural patterns from the design plan
- Naming conventions and code style
- Correctness against every acceptance criterion
- Completeness (every file in the architecture is present)
- Error handling and edge case coverage
Requirements:
{{REQUIREMENTS.output}}
Architecture design:
{{ARCHITECTURE.output}}
Implementation (workspace snapshot):
{{IMPLEMENTATION.output}}
Respond with JSON: { "score": 0.0–1.0, "confidence": 0.0–1.0,
"reasoning": "...", "suggestions": [...] }
weight: 1.5
timeout_seconds: 600
- agent: "critic-agent"
input: |-
You are an adversarial reviewer. Find every flaw in this implementation.
Look for:
- Logical inconsistencies or incorrect algorithm choices
- Scalability and performance problems
- Over-engineering or unnecessary complexity
- Failure to meet the stated requirements
- Missing edge cases not caught by the test suite
Requirements:
{{REQUIREMENTS.output}}
Architecture design:
{{ARCHITECTURE.output}}
Implementation:
{{IMPLEMENTATION.output}}
Test results (all passing):
{{TEST.output.stdout}}
Respond with JSON: { "score": 0.0–1.0, "confidence": 0.0–1.0,
"reasoning": "...", "suggestions": [...] }
weight: 1.0
timeout_seconds: 600
- agent: "security-auditor-agent"
input: |-
Perform a security audit (SAST + dependency risk assessment).
Check for:
- OWASP Top 10 vulnerabilities (injection, XSS, broken auth, etc.)
- Sensitive data exposure or insecure storage
- Insecure deserialization
- Hardcoded secrets or credentials
- Dependency vulnerabilities (list any known CVEs)
- Missing input validation or sanitisation
Implementation:
{{IMPLEMENTATION.output}}
Respond with JSON: { "score": 0.0–1.0, "confidence": 0.0–1.0,
"reasoning": "...", "suggestions": [...], "cve_risks": [...] }
weight: 1.2
timeout_seconds: 900
consensus:
strategy: weighted_average
threshold: 0.8
min_agreement_confidence: 0.65
min_judges_required: 2
confidence_weighting:
agreement_factor: 0.7
self_confidence_factor: 0.3
timeout: 25m
transitions:
- condition: consensus
threshold: 0.8
agreement: 0.65
target: FINAL_APPROVAL
- condition: score_below
threshold: 0.8
target: IMPLEMENTATION
feedback: |-
Audit panel rejected the implementation
(consensus score: {{AUDIT.consensus.score}}, confidence: {{AUDIT.consensus.confidence}}).
Constitutional audit (score: {{AUDIT.agents.0.output.score}}):
{{AUDIT.agents.0.output}}
Adversarial critique (score: {{AUDIT.agents.1.output.score}}):
{{AUDIT.agents.1.output}}
Security audit (score: {{AUDIT.agents.2.output.score}}):
{{AUDIT.agents.2.output}}
Fix all identified issues and ensure the test suite still passes.
# ==========================================================================
# Phase 6: AWAITING_FINAL_APPROVAL — human gate
# Creator reviews the full pipeline output and makes the deployment decision.
# "revise" loops back to IMPLEMENTATION with their feedback.
# ==========================================================================
FINAL_APPROVAL:
kind: Human
prompt: |-
# The Forge — Final Approval
## Task
{{workflow.task}}
## Requirements
{{REQUIREMENTS.output}}
## Architecture
{{ARCHITECTURE.output}}
## Test Results (all passing)
{{TEST.output.stdout}}
## Audit Results
### Constitutional Review (score: {{AUDIT.agents.0.output.score}})
{{AUDIT.agents.0.output}}
### Adversarial Critique (score: {{AUDIT.agents.1.output.score}})
{{AUDIT.agents.1.output}}
### Security Audit (score: {{AUDIT.agents.2.output.score}})
{{AUDIT.agents.2.output}}
### Consensus Score: {{AUDIT.consensus.score}} / 1.0
---
All automated checks passed. Make the final deployment decision:
- Type **"approve"** — deploy to production
- Type **"revise"** — return to implementation with your feedback
- Type **"reject"** — cancel this deployment permanently
timeout: 3600s
default_response: "reject"
transitions:
- condition: input_equals
value: "approve"
target: DEPLOY
- condition: input_equals
value: "revise"
target: IMPLEMENTATION
feedback: "{{human.feedback}}"
- condition: input_equals
value: "reject"
target: DEPLOYMENT_REJECTED
# ==========================================================================
# Phase 7: COMPLETE — deploy
# ==========================================================================
DEPLOY:
kind: System
command: "echo"
env:
MESSAGE: "The Forge pipeline complete — deployment approved"
PROJECT: "{{default input.project_name 'the-forge'}}"
CONSENSUS_SCORE: "{{AUDIT.consensus.score}}"
transitions:
- condition: always
target: LEARN
# ==========================================================================
# Phase 8: COMPLETE — CuratorAI constitutional learning
# Analyses the approved diff for patterns that should update the Project
# Constitution, making future agents more aligned with team standards.
# ==========================================================================
LEARN:
kind: Agent
agent: "curator-agent"
isolation: docker
volumes:
- volume: "{{workflow.storage.workspace}}"
mount_path: "/workspace"
access_mode: "read-only"
input: |-
# Constitutional Learning — Post-Deployment Analysis
## Task that was implemented
{{workflow.task}}
## Final approved implementation
{{IMPLEMENTATION.output}}
## Audit scores
- Constitutional review: {{AUDIT.agents.0.output.score}}
- Adversarial critique: {{AUDIT.agents.1.output.score}}
- Security audit: {{AUDIT.agents.2.output.score}}
- Weighted consensus: {{AUDIT.consensus.score}}
Analyse the approved implementation for patterns, conventions, or
architectural decisions that deviate from or enrich the current Project
Constitution. For each pattern identified, propose a specific, actionable
update to the constitution that would make future agents more aligned
with this team's standards.
Write proposed constitution updates to /workspace/constitution-proposals.md.
timeout: 5m
transitions: [] # Terminal — pipeline complete
# ==========================================================================
# Terminal error states
# ==========================================================================
DEPLOYMENT_REJECTED:
kind: System
command: "echo"
env:
MESSAGE: "Deployment rejected by human reviewer — pipeline terminated"
CONSENSUS_SCORE: "{{AUDIT.consensus.score}}"
transitions: [] # Terminal
FAILED:
kind: System
command: "echo"
env:
MESSAGE: "The Forge pipeline encountered an unrecoverable agent failure"
transitions: [] # Terminal