feat: add workflow templates for research patterns

Implemented workflow templates based on Anthropic research:

- parallel-review.md: Parallel execution of security + performance reviews
- evaluator-optimizer.md: Iterative improvement loop (code-skeptic → the-fixer)
- chain-of-thought.md: Sequential step decomposition with gates

Each template includes:
- Pattern overview and implementation
- Execution flow diagram
- Benefits and configuration
- Usage examples

Related: Issues #21, #22 - Patterns from research
Milestone: #47 Cognitive Enhancement
This commit is contained in:
¨NW¨
2026-04-05 02:09:40 +01:00
parent 348c47fa6f
commit fbc1f6122f
3 changed files with 272 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
# Chain of Thought Workflow
Implements CoT prompting pattern for complex task decomposition.
## Overview
Chain of Thought (CoT) decomposes complex tasks into sequential steps with validation gates.
## Pattern
```python
def chain_of_thought(task):
"""
Sequential steps with validation.
From Anthropic: "Prompt chaining decomposes a task into
a sequence of steps, where each LLM call processes the
output of the previous one."
"""
steps = [
{"prompt": "Understand requirements", "gate": validate_requirements},
{"prompt": "Design architecture", "gate": validate_architecture},
{"prompt": "Write tests", "gate": validate_tests},
{"prompt": "Implement code", "gate": validate_code},
{"prompt": "Review quality", "gate": validate_quality}
]
result = None
for step in steps:
# Generate output
result = generate(step["prompt"], context=result)
# Validate at gate
if not step["gate"](result):
raise ValidationError(f"Gate failed: {step['prompt']}")
return result
```
## Execution Flow
```
[Task: Implement Feature]
[Step 1: Understand] ──gate──→ [Valid?]
↓ Yes ↓ No
[Step 2: Design] ←───────── [Refine]
↓ gate
[Step 3: Tests]
↓ gate
[Step 4: Implement]
↓ gate
[Step 5: Review]
↓ gate
[Complete]
```
## Benefits
- **Traceable**: Clear steps with outputs
- **Validated**: Gate checks prevent errors
- **Modifiable**: Easy to add/remove steps
## Usage
```
/workflow chain-of-thought --task "Implement user authentication"
```
## Example Prompts
```
Step 1 Prompt:
"Analyze the requirements for user authentication.
List:
1. Functional requirements
2. Non-functional requirements
3. Security considerations
4. Edge cases"
Step 2 Prompt:
"Design the architecture for user authentication based on:
- Requirements: {step1_output}
Include:
- Database schema
- API endpoints
- Security measures"
```

View File

@@ -0,0 +1,103 @@
# Evaluator-Optimizer Workflow
Implements the Evaluator-Optimizer pattern from Anthropic research.
## Overview
Iterative improvement loop: evaluator reviews, optimizer improves, repeat until convergence.
## Pattern
```python
def evaluator_optimizer_loop(code, max_iterations=3):
"""
Evaluator-Optimizer pattern for code review.
From Anthropic: "One LLM call generates a response while
another provides evaluation and feedback in a loop."
"""
for iteration in range(max_iterations):
# Evaluator reviews
evaluation = Task(
subagent_type="code-skeptic",
prompt=code
)
if evaluation.verdict == "APPROVED":
return {"success": True, "iterations": iteration}
# Optimizer fixes
fixes = Task(
subagent_type="the-fixer",
issues=evaluation.issues,
code=code
)
code = apply_fixes(code, fixes)
return {"success": False, "iterations": max_iterations}
```
## Execution Flow
```
[Code Submitted]
[Evaluator: code-skeptic]
┌─────────────────────┐
│ │
│ [APPROVED] ──Yes──→ [PASS]
│ │
│ [CHANGES] ──No───→ [Optimizer: the-fixer]
│ │
│ ↓
│ [Apply Fixes]
│ │
│ ↓
│ [Iterations < Max?]
│ Yes No
│ ↓ ↓
│ [Loop] [Escalate]
└─────────────────────┘
```
## Benefits
- **Convergence Guarantee**: Maximum iterations prevent infinite loops
- **Quality Improvement**: Each iteration improves code
- **Iterative Feedback**: Evaluators teach optimizers
## Configuration
```yaml
# .kilo/config/evaluator-optimizer.yaml
iteration_loops:
code_review:
evaluator: code-skeptic
optimizer: the-fixer
max_iterations: 3
convergence: all_issues_resolved
security_review:
evaluator: security-auditor
optimizer: the-fixer
max_iterations: 2
convergence: no_critical_vulnerabilities
```
## Usage
```
/workflow evaluator-optimizer --issue 42 --max-iterations 3
```
## Scoring
| Iterations | Score Impact |
|------------|--------------|
| 1 | Perfect (10/10) |
| 2 | Good (8/10) |
| 3 | Acceptable (7/10) |
| >3 | Poor (triggers prompt-optimizer) |

View File

@@ -0,0 +1,80 @@
# Parallel Review Workflow
Implements the Parallelization pattern from Anthropic research.
## Overview
Run security and performance reviews in parallel to reduce latency by ~50%.
## Pattern
```python
async def parallel_review(code_context):
"""
Parallel execution of independent review agents.
From Anthropic: "Parallelization is effective when divided
subtasks can be parallelized for speed."
"""
tasks = [
Task(subagent_type="security-auditor", prompt=code_context),
Task(subagent_type="performance-engineer", prompt=code_context)
]
results = await asyncio.gather(*tasks)
return aggregate_results(results)
```
## Execution Flow
```
[Code Complete]
┌─────────────────────────────┐
│ Parallel Execution │
│ ┌───────────┐ ┌──────────┐ │
│ │ Security │ │ Perform- │ │
│ │ Auditor │ │ ance │ │
│ └───────────┘ └──────────┘ │
└─────────────────────────────┘
[Aggregate Results]
[Issues Found?] ──Yes──→ [The Fixer]
↓ No
[Proceed to Release]
```
## Benefits
- **Latency Reduction**: Reviews run simultaneously
- **Independent Analysis**: No bias between reviewers
- **Faster Feedback**: Combined results in one pass
## Usage
```
/workflow parallel-review --issue 42
```
## Configuration
```yaml
# .kilo/config/parallel-review.yaml
parallel_review:
agents:
- security-auditor
- performance-engineer
timeout_minutes: 15
aggregate_strategy: merge_issues
proceed_on_partial_failure: false
```
## Implementation
See `.kilo/commands/workflow.md` Step 6 for code.