Based on Anthropic 'Building Effective Agents' and Lilian Weng's research: New Agents: - @planner: Task decomposition using CoT, ToT, Plan-Execute-Reflect - @reflector: Self-reflection using Reflexion pattern - @memory-manager: Memory systems (short/long/episodic) New Skills: - memory-systems: Memory architecture for autonomous agents - planning-patterns: CoT, ToT, ReAct, Reflexion patterns - tool-use: ACI design principles from Anthropic New Rules: - agent-patterns: Core patterns from research Updated AGENTS.md with new agent categories: - Cognitive Enhancement: planner, reflector, memory-manager - Improved workflow state machine with reflection loop Related: Issue #25 (Research Milestone)
85 lines
1.8 KiB
Markdown
85 lines
1.8 KiB
Markdown
# Agent Patterns Rules
|
|
|
|
Based on research from Anthropic, OpenAI, and Lilian Weng.
|
|
|
|
## Core Patterns (Anthropic)
|
|
|
|
### 1. Prompt Chaining
|
|
Sequential steps with validation gates.
|
|
```yaml
|
|
when: Task can be cleanly decomposed
|
|
example: Generate copy, then translate
|
|
gate: Validate each step before next
|
|
```
|
|
|
|
### 2. Routing
|
|
Classify input, route to specialized agent.
|
|
```yaml
|
|
when: Distinct categories, clear classification
|
|
example: Customer service routing (refunds, technical, general)
|
|
```
|
|
|
|
### 3. Parallelization
|
|
Run independent tasks simultaneously.
|
|
```yaml
|
|
when: Subtasks are independent
|
|
types:
|
|
- Sectioning: Break into parallel parts
|
|
- Voting: Multiple attempts, aggregate results
|
|
```
|
|
|
|
### 4. Orchestrator-Workers
|
|
Central controller delegates to workers.
|
|
```yaml
|
|
when: Subtasks dynamic, not pre-defined
|
|
example: Coding agent editing multiple files
|
|
```
|
|
|
|
### 5. Evaluator-Optimizer
|
|
Loop: generate, evaluate, improve.
|
|
```yaml
|
|
when: Clear criteria, iterative improves
|
|
example: Code review loop
|
|
```
|
|
|
|
## Memory Architecture (Lilian Weng)
|
|
|
|
### Components
|
|
- **Planning**: Task decomposition, self-reflection
|
|
- **Memory**: Short-term, long-term, episodic
|
|
- **Tool Use**: External APIs, code execution
|
|
|
|
### Memory Types
|
|
1. **Sensory**: Embeddings (milliseconds)
|
|
2. **Short-term**: Context window (~4000 tokens)
|
|
3. **Long-term**: Vector store (infinite)
|
|
4. **Episodic**: Experience log
|
|
|
|
## Tool Use Best Practices (Anthropic)
|
|
|
|
1. Give model "think" space before output
|
|
2. Keep formats close to internet patterns
|
|
3. Minimize formatting overhead
|
|
4. Invest in ACI like HCI
|
|
|
|
## ReAct Pattern
|
|
|
|
Interleave reasoning and action:
|
|
```
|
|
Thought: [reasoning]
|
|
Action: [tool call]
|
|
Observation: [result]
|
|
(Repeat until done)
|
|
```
|
|
|
|
## Reflexion Pattern
|
|
|
|
Learn from mistakes:
|
|
```
|
|
1. Take action
|
|
2. Check heuristic
|
|
3. Generate reflection
|
|
4. Update memory
|
|
5. Retry with lesson
|
|
```
|