Skip to content

Commit 0519c06

Browse files
committed
Add Google providerOptions type assertions
Widen RequestContext generics to unknown in business/legal agents, comment out pgQueryTool, and tidy imports/formatting in A2A coordinators.
1 parent 12f5fb2 commit 0519c06

3 files changed

Lines changed: 106 additions & 108 deletions

File tree

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1+
import { GoogleGenerativeAIProviderOptions } from '@ai-sdk/google'
12
import { Agent } from '@mastra/core/agent'
23
import {
3-
createAnswerRelevancyScorer,
4-
createToxicityScorer,
4+
createAnswerRelevancyScorer,
5+
createToxicityScorer,
56
} from '@mastra/evals/scorers/prebuilt'
6-
import { copywriterAgent } from '../agents/copywriterAgent'
7-
import { editorAgent } from '../agents/editorAgent'
8-
import { researchAgent } from '../agents/researchAgent'
9-
import { knowledgeIndexingAgent } from '../agents/knowledgeIndexingAgent'
107
import {
11-
codeArchitectAgent,
12-
codeReviewerAgent,
13-
testEngineerAgent,
14-
refactoringAgent,
8+
codeArchitectAgent,
9+
codeReviewerAgent,
10+
refactoringAgent,
11+
testEngineerAgent,
1512
} from '../agents/codingAgents'
1613
import { contentStrategistAgent } from '../agents/contentStrategistAgent'
14+
import { copywriterAgent } from '../agents/copywriterAgent'
15+
import { editorAgent } from '../agents/editorAgent'
16+
import { knowledgeIndexingAgent } from '../agents/knowledgeIndexingAgent'
1717
import { projectManagementAgent } from '../agents/projectManagementAgent'
18-
import { researchSynthesisWorkflow } from '../workflows/research-synthesis-workflow'
19-
import { repoIngestionWorkflow } from '../workflows/repo-ingestion-workflow'
20-
import { specGenerationWorkflow } from '../workflows/spec-generation-workflow'
18+
import { researchAgent } from '../agents/researchAgent'
2119
import { googleAI, googleAIFlashLite } from '../config/google'
2220
import { pgMemory } from '../config/pg-storage'
23-
import type { RequestContext } from '@mastra/core/request-context'
21+
import { repoIngestionWorkflow } from '../workflows/repo-ingestion-workflow'
22+
import { researchSynthesisWorkflow } from '../workflows/research-synthesis-workflow'
23+
import { specGenerationWorkflow } from '../workflows/spec-generation-workflow'
2424
// Import all agents
2525

2626
// Import all workflows
@@ -35,15 +35,15 @@ import type { RequestContext } from '@mastra/core/request-context'
3535
*/
3636

3737
export const a2aCoordinatorAgent = new Agent({
38-
id: 'a2aCoordinator',
39-
name: 'a2aCoordinator',
40-
description:
41-
'A2A Coordinator that orchestrates multiple specialized agents in parallel. Routes tasks dynamically, coordinates workflows, and synthesizes results using the A2A protocol.',
42-
instructions: ({ requestContext }) => {
43-
const userId = requestContext.get('userId')
44-
return {
45-
role: 'system',
46-
content: `You are an A2A (Agent-to-Agent) Coordinator that orchestrates multi-agent workflows.
38+
id: 'a2aCoordinator',
39+
name: 'a2aCoordinator',
40+
description:
41+
'A2A Coordinator that orchestrates multiple specialized agents in parallel. Routes tasks dynamically, coordinates workflows, and synthesizes results using the A2A protocol.',
42+
instructions: ({ requestContext }) => {
43+
const userId = requestContext.get('userId')
44+
return {
45+
role: 'system',
46+
content: `You are an A2A (Agent-to-Agent) Coordinator that orchestrates multi-agent workflows.
4747
userId: ${userId}
4848
CORE CAPABILITIES:
4949
- Orchestrate multiple agents working in parallel
@@ -91,49 +91,49 @@ Use Promise.all() pattern for parallel execution.
9191
Maximize the use of E2B sandboxes via specialized agents for any code-related tasks.
9292
Use knowledgeIndexingAgent to provide semantic context for complex queries.
9393
`,
94-
providerOptions: {
95-
google: {
96-
thinkingConfig: {
97-
thinkingLevel: 'high',
98-
includeThoughts: true,
99-
thinkingBudget: -1,
100-
},
101-
mediaResolution: 'MEDIA_RESOLUTION_MEDIUM',
102-
responseModalities: ['TEXT', 'IMAGE'],
103-
},
104-
},
105-
}
106-
},
107-
model: googleAI,
108-
memory: pgMemory,
109-
options: {},
110-
agents: {
111-
researchAgent,
112-
knowledgeIndexingAgent,
113-
editorAgent,
114-
copywriterAgent,
115-
codeArchitectAgent,
116-
codeReviewerAgent,
117-
testEngineerAgent,
118-
refactoringAgent,
119-
contentStrategistAgent,
120-
projectManagementAgent,
121-
},
122-
workflows: {
123-
researchSynthesisWorkflow,
124-
repoIngestionWorkflow,
125-
specGenerationWorkflow,
94+
providerOptions: {
95+
google: {
96+
thinkingConfig: {
97+
thinkingLevel: 'high',
98+
includeThoughts: true,
99+
thinkingBudget: -1,
100+
},
101+
mediaResolution: 'MEDIA_RESOLUTION_MEDIUM',
102+
responseModalities: ['TEXT', 'IMAGE'],
103+
} satisfies GoogleGenerativeAIProviderOptions,
104+
},
105+
}
106+
},
107+
model: googleAI,
108+
memory: pgMemory,
109+
options: {},
110+
agents: {
111+
researchAgent,
112+
knowledgeIndexingAgent,
113+
editorAgent,
114+
copywriterAgent,
115+
codeArchitectAgent,
116+
codeReviewerAgent,
117+
testEngineerAgent,
118+
refactoringAgent,
119+
contentStrategistAgent,
120+
projectManagementAgent,
121+
},
122+
workflows: {
123+
researchSynthesisWorkflow,
124+
repoIngestionWorkflow,
125+
specGenerationWorkflow,
126+
},
127+
maxRetries: 5,
128+
tools: {},
129+
scorers: {
130+
relevancy: {
131+
scorer: createAnswerRelevancyScorer({ model: googleAIFlashLite }),
132+
sampling: { type: 'ratio', rate: 0.4 },
126133
},
127-
maxRetries: 5,
128-
tools: {},
129-
scorers: {
130-
relevancy: {
131-
scorer: createAnswerRelevancyScorer({ model: googleAIFlashLite }),
132-
sampling: { type: 'ratio', rate: 0.4 },
133-
},
134-
safety: {
135-
scorer: createToxicityScorer({ model: googleAIFlashLite }),
136-
sampling: { type: 'ratio', rate: 0.3 },
137-
},
134+
safety: {
135+
scorer: createToxicityScorer({ model: googleAIFlashLite }),
136+
sampling: { type: 'ratio', rate: 0.3 },
138137
},
138+
},
139139
})

src/mastra/a2a/codingA2ACoordinator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { googleAIFlashLite } from '../config/google'
88
import { log } from '../config/logger'
99
import { pgMemory } from '../config/pg-storage'
1010

11+
import { GoogleGenerativeAIProviderOptions } from '@ai-sdk/google'
1112
import { InternalSpans } from '@mastra/core/observability'
1213
import {
1314
codeArchitectAgent,
@@ -197,7 +198,7 @@ When a user's request requires prolonged, structured work across multiple subtas
197198
},
198199
mediaResolution: 'MEDIA_RESOLUTION_MEDIUM',
199200
responseModalities: ['TEXT', 'IMAGE'],
200-
},
201+
} satisfies GoogleGenerativeAIProviderOptions,
201202
},
202203
}
203204
},

src/mastra/agents/businessLegalAgents.ts

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ export const legalResearchAgent = new Agent({
7171
instructions: ({
7272
requestContext,
7373
}: {
74-
requestContext: RequestContext<BusinessRuntimeContext>
74+
requestContext: RequestContext<unknown>
7575
}) => {
7676
// runtimeContext is read at invocation time
7777
const userTier = requestContext.get('user-tier') ?? 'free'
7878
const language = requestContext.get('language') ?? 'en'
79-
const responseFormat = requestContext.get('responseFormat') ?? 'json'
8079
const research = requestContext.get('research') ?? {
8180
depth: 'extensive',
8281
scope: 'full',
@@ -88,37 +87,37 @@ export const legalResearchAgent = new Agent({
8887
return {
8988
role: 'system',
9089
content: `You are a Senior Legal Research Analyst. Your goal is to research legal topics thoroughly using authoritative sources.
91-
Your working with:
92-
- User: ${userTier}
93-
- Language: ${language}
94-
- Research: Depth ${research.depth}, Scope ${research.scope}
95-
- Analysis: Depth ${analysis.depth}, Scope ${analysis.scope}
96-
97-
**Key Guidelines:**
98-
- Focus on primary sources: statutes, case law, regulations
99-
- Evaluate authority and jurisdiction
100-
- Provide confidence assessments for findings
101-
- Cite sources properly
102-
103-
**Rules:**
104-
- **Tool Efficiency:** Do NOT use the same tool repetitively or back-to-back for the same query.
105-
106-
**Process:**
107-
1. Break down legal issues into specific queries
108-
2. Search authoritative databases
109-
3. Evaluate relevance and authority
110-
4. Extract key insights and follow-up questions
111-
5. Synthesize findings with confidence levels
112-
113-
**Examples:**
114-
- Query: "Breach of contract remedies in California"
115-
→ Research California Civil Code, relevant case law, provide summary with citations
116-
- Query: "Data privacy regulations for EU businesses"
117-
→ Analyze GDPR requirements, enforcement cases, compliance implications
118-
119-
**Output:** Return findings in JSON format with queries, results, summary, sources, and confidence level.
120-
${PGVECTOR_PROMPT}
121-
`,
90+
Your working with:
91+
- User: ${userTier}
92+
- Language: ${language}
93+
- Research: Depth ${(research as any).depth ?? 'extensive'}, Scope ${(research as any).scope ?? 'full'}
94+
- Analysis: Depth ${(analysis as any).depth ?? 'extensive'}, Scope ${(analysis as any).scope ?? 'full'}
95+
96+
**Key Guidelines:**
97+
- Focus on primary sources: statutes, case law, regulations
98+
- Evaluate authority and jurisdiction
99+
- Provide confidence assessments for findings
100+
- Cite sources properly
101+
102+
**Rules:**
103+
- **Tool Efficiency:** Do NOT use the same tool repetitively or back-to-back for the same query.
104+
105+
**Process:**
106+
1. Break down legal issues into specific queries
107+
2. Search authoritative databases
108+
3. Evaluate relevance and authority
109+
4. Extract key insights and follow-up questions
110+
5. Synthesize findings with confidence levels
111+
112+
**Examples:**
113+
- Query: "Breach of contract remedies in California"
114+
→ Research California Civil Code, relevant case law, provide summary with citations
115+
- Query: "Data privacy regulations for EU businesses"
116+
→ Analyze GDPR requirements, enforcement cases, compliance implications
117+
118+
**Output:** Return findings in JSON format with queries, results, summary, sources, and confidence level.
119+
${PGVECTOR_PROMPT}
120+
`,
122121
providerOptions: {
123122
google: {
124123
thinkingConfig: {
@@ -134,7 +133,7 @@ ${PGVECTOR_PROMPT}
134133
model: ({
135134
requestContext,
136135
}: {
137-
requestContext: RequestContext<BusinessRuntimeContext>
136+
requestContext: RequestContext<unknown>
138137
}) => {
139138
const userTier = requestContext.get('user-tier') ?? 'free'
140139
if (userTier === 'enterprise') {
@@ -154,7 +153,7 @@ ${PGVECTOR_PROMPT}
154153
linkExtractorTool,
155154
htmlToMarkdownTool,
156155
contentCleanerTool,
157-
pgQueryTool,
156+
// pgQueryTool,
158157
batchWebScraperTool,
159158
mdocumentChunker,
160159
evaluateResultTool,
@@ -241,13 +240,12 @@ You are a Senior Contract Analyst. Analyze legal documents for risks, obligation
241240
`,
242241
providerOptions: {
243242
google: {
244-
structuredOutput: true,
245243
thinkingConfig: {
246244
includeThoughts: true,
247245
thinkingBudget: -1,
248246
},
249247
responseModalities: ['TEXT'],
250-
},
248+
} satisfies GoogleGenerativeAIProviderOptions,
251249
},
252250
}
253251
},
@@ -337,13 +335,13 @@ You are a Compliance Officer. Monitor regulatory compliance and identify risks a
337335
`,
338336
providerOptions: {
339337
google: {
340-
structuredOutput: true,
338+
341339
thinkingConfig: {
342340
includeThoughts: true,
343341
thinkingBudget: -1,
344342
},
345343
responseModalities: ['TEXT'],
346-
},
344+
} satisfies GoogleGenerativeAIProviderOptions,
347345
},
348346
}
349347
},
@@ -434,13 +432,12 @@ You are a Chief Strategy Officer with legal expertise. Align business strategy w
434432
`,
435433
providerOptions: {
436434
google: {
437-
structuredOutput: true,
438435
thinkingConfig: {
439436
includeThoughts: true,
440437
thinkingBudget: -1,
441438
},
442439
responseModalities: ['TEXT'],
443-
},
440+
} satisfies GoogleGenerativeAIProviderOptions,
444441
},
445442
}
446443
},

0 commit comments

Comments
 (0)