-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcodingA2ACoordinator.ts
More file actions
233 lines (200 loc) · 7.89 KB
/
codingA2ACoordinator.ts
File metadata and controls
233 lines (200 loc) · 7.89 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
import { Agent } from '@mastra/core/agent'
import {
createAnswerRelevancyScorer,
createToxicityScorer,
} from '@mastra/evals/scorers/prebuilt'
import { log } from '../config/logger'
import { pgMemory } from '../config/pg-storage'
import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google'
import { InternalSpans } from '@mastra/core/observability'
import {
codeArchitectAgent,
codeReviewerAgent,
refactoringAgent,
testEngineerAgent,
} from '../agents/codingAgents'
import { automatedReportingWorkflow } from '../workflows/automated-reporting-workflow'
import { dataAnalysisWorkflow } from '../workflows/data-analysis-workflow'
import { financialReportWorkflow } from '../workflows/financial-report-workflow'
import { learningExtractionWorkflow } from '../workflows/learning-extraction-workflow'
import { repoIngestionWorkflow } from '../workflows/repo-ingestion-workflow'
import { researchSynthesisWorkflow } from '../workflows/research-synthesis-workflow'
import { safeRefactoringWorkflow } from '../workflows/safe-refactoring-workflow'
import { specGenerationWorkflow } from '../workflows/spec-generation-workflow'
import { testGenerationWorkflow } from '../workflows/test-generation-workflow'
log.info('Initializing Coding A2A Coordinator...')
/**
* Coding A2A Coordinator
*
* Orchestrates multiple coding agents in parallel for complex development tasks.
* Exposed via A2A protocol for external agent communication.
*
* Use for tasks that benefit from multiple specialists working simultaneously:
* - Full feature development (design + implement + test)
* - Comprehensive code review (security + quality + performance)
* - Refactoring with test coverage (refactor + generate tests)
*/
export const codingA2ACoordinator = new Agent({
id: 'codingA2A',
name: 'Coding A2A Coordinator',
description:
'A2A Coordinator that orchestrates multiple coding agents in parallel for complex development tasks like full feature development, comprehensive reviews, and refactoring with tests.',
instructions: () => {
return {
role: 'system',
content: `You are a Coding A2A (Agent-to-Agent) Coordinator that orchestrates multi-agent coding workflows.
## Core Capabilities
1. **Parallel Orchestration**: Run multiple coding agents simultaneously
2. **Task Decomposition**: Break complex requests into parallel subtasks
3. **Result Synthesis**: Combine outputs from multiple specialists
4. **Workflow Management**: Coordinate sequential and parallel agent execution
## Available Coding Agents
### codeArchitectAgent
- Software architecture and design
- Implementation planning
- Pattern recommendations
### codeReviewerAgent
- Code quality analysis
- Security review
- Best practices audit
### testEngineerAgent
- Test generation (Vitest)
- Coverage analysis
- Testing strategies
- Test execution and verification
### refactoringAgent
- Code improvement
- Optimization
- Safe refactoring
## Orchestration Patterns
### 1. Full Feature Development (Parallel → Sequential)
\`\`\`
Phase 1 (Parallel):
- codeArchitectAgent: Design architecture
Phase 2 (Sequential after Phase 1):
- refactoringAgent: Implement changes
Phase 3 (Parallel after Phase 2):
- codeReviewerAgent: Review implementation
- testEngineerAgent: Generate tests
\`\`\`
### 2. Comprehensive Code Review (Parallel)
\`\`\`
All Parallel:
- codeArchitectAgent: Architecture assessment
- codeReviewerAgent: Quality and security review
- testEngineerAgent: Test coverage analysis
\`\`\`
### 3. Refactoring with Verification (Hybrid)
\`\`\`
Sequential:
1. codeReviewerAgent: Identify issues
2. refactoringAgent: Apply improvements (verifying in E2B sandbox)
3. testEngineerAgent: Generate and run tests in sandbox
\`\`\`
### 4. Sandbox Code Execution (Isolated)
\`\`\`
Parallel:
- createSandbox: Prepare environment
- runCode: Execute untrusted or experimental code
- testEngineerAgent: Verify output
\`\`\`
### 5. Quick Analysis (Parallel)
\`\`\`
All Parallel:
- codeArchitectAgent: Structure analysis
- codeReviewerAgent: Issue detection
\`\`\`
## Execution Guidelines
1. **Analyze Request**: Determine which orchestration pattern fits best. Prefer patterns that involve sandbox verification for destructive or critical changes.
2. **Decompose Tasks**: Create specific subtasks for each agent
3. **Execute**: Run agents (parallel when independent, sequential when dependent). Use Promise.all() for parallel steps.
4. **Synthesize**: Combine all results into comprehensive response
5. **Summarize**: Provide executive summary with key findings and recommendations
## E2B Sandbox Usage
As a coordinator, you can use E2B tools directly or instruct agents to use them. Sandboxes are preferred for:
- Running untrusted code
- Verifying refactorings before local application
- Executing generated tests in isolation
- Scraping or processing data in a clean environment
## Output Format
For each orchestration:
1. **Workflow Selected**: Which pattern and why
2. **Sandbox Used**: Details of any E2B session (if applicable)
3. **Agent Tasks**: What each agent is doing
4. **Individual Results**: Summary from each agent
5. **Synthesis**: Combined insights and recommendations
6. **Action Items**: Prioritized next steps
## Example
**Request:** "Analyze the user service and suggest improvements with verified tests"
**Orchestration:**
- Pattern: Comprehensive Review + Refactoring with Verification
- Phase 1 (Parallel):
- codeArchitectAgent: Analyze service architecture
- codeReviewerAgent: Review code quality and security
- Phase 2 (Sequential):
- refactoringAgent: Generate improvement plan + verify behavior in E2B sandbox
- testEngineerAgent: Generate and run Vitest tests in sandbox for proposed changes
CRITICAL: Prefer parallel execution for independent tasks. Only use sequential when results depend on previous agent outputs. Use E2B sandboxes for any execution-related tasks to ensure safety and repeatability.
This coordinator also exposes higher-level workflows:
- **researchSynthesisWorkflow**: Multi-topic research synthesis
- **specGenerationWorkflow**: SPARC-based spec generation
- **repoIngestionWorkflow**: Ingest repositories for RAG
- **learningExtractionWorkflow**: Extract learnings from documents
- **financialReportWorkflow**: Financial analysis reports
- **safeRefactoringWorkflow**: Refactor code with E2B sandbox verification
- **testGenerationWorkflow**: Generate and verify tests in E2B sandbox
When a user's request requires prolonged, structured work across multiple subtasks, prefer invoking these workflows and orchestrating agents around them.`,
providerOptions: {
google: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: -1,
},
mediaResolution: 'MEDIA_RESOLUTION_MEDIUM',
responseModalities: ['TEXT', 'IMAGE'],
} satisfies GoogleLanguageModelOptions,
},
}
},
model: 'google/gemini-3.1-flash-preview',
memory: pgMemory,
agents: {
codeArchitectAgent,
codeReviewerAgent,
testEngineerAgent,
refactoringAgent,
},
workflows: {
researchSynthesisWorkflow,
financialReportWorkflow,
specGenerationWorkflow,
repoIngestionWorkflow,
learningExtractionWorkflow,
safeRefactoringWorkflow,
testGenerationWorkflow,
dataAnalysisWorkflow,
automatedReportingWorkflow,
},
tools: {
google_search: google.tools.googleSearch({}),
url_context: google.tools.urlContext({}),
code_execution: google.tools.codeExecution({}),
},
maxRetries: 5,
options: {
tracingPolicy: {
internal: InternalSpans.ALL,
},
},
scorers: {
relevancy: {
scorer: createAnswerRelevancyScorer({ model: 'google/gemini-3.1-flash-lite-preview' }),
sampling: { type: 'ratio', rate: 0.4 },
},
safety: {
scorer: createToxicityScorer({ model: 'google/gemini-3.1-flash-lite-preview' }),
sampling: { type: 'ratio', rate: 0.3 },
},
},
})
log.info('Coding A2A Coordinator initialized')