-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patha2aCoordinatorAgent.ts
More file actions
139 lines (129 loc) · 5.2 KB
/
a2aCoordinatorAgent.ts
File metadata and controls
139 lines (129 loc) · 5.2 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
import type { GoogleLanguageModelOptions } from '@ai-sdk/google'
import { Agent } from '@mastra/core/agent'
import {
createAnswerRelevancyScorer,
createToxicityScorer,
} from '@mastra/evals/scorers/prebuilt'
import {
codeArchitectAgent,
codeReviewerAgent,
refactoringAgent,
testEngineerAgent,
} from '../agents/codingAgents'
import { contentStrategistAgent } from '../agents/contentStrategistAgent'
import { copywriterAgent } from '../agents/copywriterAgent'
import { editorAgent } from '../agents/editorAgent'
import { knowledgeIndexingAgent } from '../agents/knowledgeIndexingAgent'
import { projectManagementAgent } from '../agents/projectManagementAgent'
import { researchAgent } from '../agents/researchAgent'
import { pgMemory } from '../config/pg-storage'
import { repoIngestionWorkflow } from '../workflows/repo-ingestion-workflow'
import { researchSynthesisWorkflow } from '../workflows/research-synthesis-workflow'
import { specGenerationWorkflow } from '../workflows/spec-generation-workflow'
// Import all agents
// Import all workflows
/**
* A2A Coordinator Agent
*
* This agent coordinates complex tasks by orchestrating multiple specialized agents in parallel
* using Mastra's agent.network() for non-deterministic LLM-based multi-agent orchestration.
*
* Exposed via A2A protocol through MCP server for external agent communication.
*/
export const a2aCoordinatorAgent = new Agent({
id: 'a2aCoordinator',
name: 'a2aCoordinator',
description:
'A2A Coordinator that orchestrates multiple specialized agents in parallel. Routes tasks dynamically, coordinates workflows, and synthesizes results using the A2A protocol.',
instructions: () => {
// const userId = requestContext.get('userId')
return {
role: 'system',
content: `You are an A2A (Agent-to-Agent) Coordinator that orchestrates multi-agent workflows.
CORE CAPABILITIES:
- Orchestrate multiple agents working in parallel
- Route tasks to specialized agents dynamically
- Monitor task progress and handle errors
- Collect and synthesize all results
- Coordinate complex, multi-step workflows
ORCHESTRATION PATTERNS (NOT SEQUENTIAL):
1. Analyze the task and identify all required agents
2. Create parallel agent tasks for maximum efficiency
3. Monitor task execution across all agents simultaneously
4. Collect and synthesize results from all agents
5. Provide comprehensive final response
AVAILABLE AGENTS:
- researchAgent: Fact finding and information gathering
- knowledgeIndexingAgent: Document chunking, vector embedding, and semantic reranking (RAG)
- editorAgent: Reviewing and polishing content
- copywriterAgent: High-quality marketing and technical writing
- contentStrategistAgent: Strategic planning for content campaigns
- codeArchitectAgent: System design and architectural planning
- codeReviewerAgent: Deep analysis of code quality and security
- testEngineerAgent: Automated test generation and verification
- refactoringAgent: Safe and efficient code modernization
- projectManagementAgent: Task decomposition and roadmap creation
AVAILABLE WORKFLOWS:
- researchSynthesisWorkflow: Multi-source research consolidation
- repoIngestionWorkflow: Knowledge indexing for RAG from codebases
- specGenerationWorkflow: Detailed product and technical specification generation
AVAILABLE NETWORKS (Multi-agent):
- Coding Team Network: Orchestrated coding specialists for feature development
ORCHESTRATION WORKFLOWS (PARALLEL):
1. Implementation Planning: codeArchitectAgent + projectManagementAgent
2. Content Creation: researchAgent + copywriterAgent + editorAgent
3. Software Modernization: codeReviewerAgent + refactoringAgent + testEngineerAgent
4. Knowledge Base Building: knowledgeIndexingAgent (for chunking/embeddings) + researchAgent (for verification)
CRITICAL: Always prefer parallel orchestration over sequential execution for efficiency.
Only use sequential when tasks have strict dependencies on previous results.
Use Promise.all() pattern for parallel execution.
Maximize the use of E2B sandboxes via specialized agents for any code-related tasks.
Use knowledgeIndexingAgent to provide semantic context for complex queries.
`,
providerOptions: {
google: {
thinkingConfig: {
thinkingLevel: 'high',
includeThoughts: true,
},
mediaResolution: 'MEDIA_RESOLUTION_MEDIUM',
responseModalities: ['TEXT', 'IMAGE'],
} satisfies GoogleLanguageModelOptions,
},
}
},
model: 'google/gemini-3.1-flash-preview',
memory: pgMemory,
options: {},
agents: {
researchAgent,
knowledgeIndexingAgent,
editorAgent,
copywriterAgent,
codeArchitectAgent,
codeReviewerAgent,
testEngineerAgent,
refactoringAgent,
contentStrategistAgent,
projectManagementAgent,
},
workflows: {
researchSynthesisWorkflow,
repoIngestionWorkflow,
specGenerationWorkflow,
},
maxRetries: 5,
tools: {},
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 },
},
},
})