|
4 | 4 | * Demonstrates: |
5 | 5 | * - Dependency chain: generator produces code, three reviewers depend on it |
6 | 6 | * - Parallel execution: security, performance, and style reviewers run concurrently |
7 | | - * - Shared memory: generator writes code, reviewers read it and write feedback, |
8 | | - * synthesizer reads all feedback and produces a unified report |
| 7 | + * - Shared memory: each agent's output is automatically stored and injected |
| 8 | + * into downstream agents' prompts by the framework |
9 | 9 | * |
10 | 10 | * Flow: |
11 | 11 | * generator → [security-reviewer, performance-reviewer, style-reviewer] (parallel) → synthesizer |
12 | 12 | * |
13 | 13 | * Run: |
14 | | - * npx tsx examples/multi-perspective-code-review.ts |
| 14 | + * npx tsx examples/14-multi-perspective-code-review.ts |
15 | 15 | * |
16 | 16 | * Prerequisites: |
17 | 17 | * ANTHROPIC_API_KEY env var must be set. |
@@ -39,50 +39,45 @@ const generator: AgentConfig = { |
39 | 39 | model: 'claude-sonnet-4-6', |
40 | 40 | systemPrompt: `You are a Node.js backend developer. Given an API spec, write a complete |
41 | 41 | Express route handler. Include imports, validation, database query, and error handling. |
42 | | -Store the generated code in shared memory under the key "generated_code". |
43 | | -Write only the code, no explanation. Keep it under 80 lines.`, |
| 42 | +Output only the code, no explanation. Keep it under 80 lines.`, |
44 | 43 | maxTurns: 2, |
45 | 44 | } |
46 | 45 |
|
47 | 46 | const securityReviewer: AgentConfig = { |
48 | 47 | name: 'security-reviewer', |
49 | 48 | model: 'claude-sonnet-4-6', |
50 | | - systemPrompt: `You are a security reviewer. Read the code from shared memory key |
51 | | -"generated_code" and check for OWASP top 10 vulnerabilities: SQL injection, XSS, |
52 | | -broken authentication, sensitive data exposure, etc. Write your findings as a |
53 | | -markdown checklist. Store your review in shared memory under "security_review". |
| 49 | + systemPrompt: `You are a security reviewer. Review the code provided in context and check |
| 50 | +for OWASP top 10 vulnerabilities: SQL injection, XSS, broken authentication, |
| 51 | +sensitive data exposure, etc. Write your findings as a markdown checklist. |
54 | 52 | Keep it to 150-200 words.`, |
55 | 53 | maxTurns: 2, |
56 | 54 | } |
57 | 55 |
|
58 | 56 | const performanceReviewer: AgentConfig = { |
59 | 57 | name: 'performance-reviewer', |
60 | 58 | model: 'claude-sonnet-4-6', |
61 | | - systemPrompt: `You are a performance reviewer. Read the code from shared memory key |
62 | | -"generated_code" and check for N+1 queries, memory leaks, blocking calls, missing |
63 | | -connection pooling, and inefficient patterns. Write your findings as a markdown |
64 | | -checklist. Store your review in shared memory under "performance_review". |
| 59 | + systemPrompt: `You are a performance reviewer. Review the code provided in context and check |
| 60 | +for N+1 queries, memory leaks, blocking calls, missing connection pooling, and |
| 61 | +inefficient patterns. Write your findings as a markdown checklist. |
65 | 62 | Keep it to 150-200 words.`, |
66 | 63 | maxTurns: 2, |
67 | 64 | } |
68 | 65 |
|
69 | 66 | const styleReviewer: AgentConfig = { |
70 | 67 | name: 'style-reviewer', |
71 | 68 | model: 'claude-sonnet-4-6', |
72 | | - systemPrompt: `You are a code style reviewer. Read the code from shared memory key |
73 | | -"generated_code" and check naming conventions, function structure, readability, |
74 | | -error message clarity, and consistency. Write your findings as a markdown checklist. |
75 | | -Store your review in shared memory under "style_review". |
| 69 | + systemPrompt: `You are a code style reviewer. Review the code provided in context and check |
| 70 | +naming conventions, function structure, readability, error message clarity, and |
| 71 | +consistency. Write your findings as a markdown checklist. |
76 | 72 | Keep it to 150-200 words.`, |
77 | 73 | maxTurns: 2, |
78 | 74 | } |
79 | 75 |
|
80 | 76 | const synthesizer: AgentConfig = { |
81 | 77 | name: 'synthesizer', |
82 | 78 | model: 'claude-sonnet-4-6', |
83 | | - systemPrompt: `You are a lead engineer synthesizing code review feedback. Read all |
84 | | -reviews from shared memory (security_review, performance_review, style_review) and |
85 | | -the original code (generated_code). Produce a unified report with: |
| 79 | + systemPrompt: `You are a lead engineer synthesizing code review feedback. Review all |
| 80 | +the feedback and original code provided in context. Produce a unified report with: |
86 | 81 |
|
87 | 82 | 1. Critical issues (must fix before merge) |
88 | 83 | 2. Recommended improvements (should fix) |
@@ -124,30 +119,30 @@ const team = orchestrator.createTeam('code-review-team', { |
124 | 119 | const tasks = [ |
125 | 120 | { |
126 | 121 | title: 'Generate code', |
127 | | - description: `Write a Node.js Express route handler for this API spec:\n\n${API_SPEC}\n\nStore the complete code in shared memory as "generated_code".`, |
| 122 | + description: `Write a Node.js Express route handler for this API spec:\n\n${API_SPEC}`, |
128 | 123 | assignee: 'generator', |
129 | 124 | }, |
130 | 125 | { |
131 | 126 | title: 'Security review', |
132 | | - description: 'Read "generated_code" from shared memory and perform a security review. Store findings in shared memory as "security_review".', |
| 127 | + description: 'Review the generated code for security vulnerabilities.', |
133 | 128 | assignee: 'security-reviewer', |
134 | 129 | dependsOn: ['Generate code'], |
135 | 130 | }, |
136 | 131 | { |
137 | 132 | title: 'Performance review', |
138 | | - description: 'Read "generated_code" from shared memory and perform a performance review. Store findings in shared memory as "performance_review".', |
| 133 | + description: 'Review the generated code for performance issues.', |
139 | 134 | assignee: 'performance-reviewer', |
140 | 135 | dependsOn: ['Generate code'], |
141 | 136 | }, |
142 | 137 | { |
143 | 138 | title: 'Style review', |
144 | | - description: 'Read "generated_code" from shared memory and perform a style review. Store findings in shared memory as "style_review".', |
| 139 | + description: 'Review the generated code for style and readability.', |
145 | 140 | assignee: 'style-reviewer', |
146 | 141 | dependsOn: ['Generate code'], |
147 | 142 | }, |
148 | 143 | { |
149 | 144 | title: 'Synthesize feedback', |
150 | | - description: 'Read all reviews (security_review, performance_review, style_review) and the original generated_code from shared memory. Produce a unified, prioritized action item report.', |
| 145 | + description: 'Synthesize all review feedback and the original code into a unified, prioritized action item report.', |
151 | 146 | assignee: 'synthesizer', |
152 | 147 | dependsOn: ['Security review', 'Performance review', 'Style review'], |
153 | 148 | }, |
|
0 commit comments