Skip to content

Commit 339ed9f

Browse files
committed
feat: enhance agent workflows and configurations
- Updated OTEL configuration in instrumentation.ts to prevent double instrumentation. - Refactored Dane agent to use new webScraperTool and updated model to 'google/gemini-3-flash-preview'. - Commented out unused tools in editorAgent.ts and noteTakerAgent.ts for clarity. - Removed outdated agent-experiments.ts file and added new experiments with logging for various agents. - Improved error handling in repo-ingestion-workflow.ts for better clarity on scan results. - Updated target audience checks in content-review-workflow.ts for more robust validation. - Adjusted output processor limits in weather-agent.ts for performance optimization. - Cleaned up whitespace in changelog.ts and other workflow files for consistency.
1 parent 62517e3 commit 339ed9f

11 files changed

Lines changed: 78 additions & 67 deletions

instrumentation.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
import { registerOTel } from "@vercel/otel";
22

3+
/**
4+
* OTEL configuration is primarily handled by Mastra in `src/mastra/index.ts`.
5+
*
6+
* To avoid double instrumentation or conflicting exporters, Vercel's `registerOTel`
7+
* is only used when explicitly enabled via the `VERCEL_OTEL_ENABLED` env flag.
8+
*
9+
* When `VERCEL_OTEL_ENABLED` is not set to `"true"`, this file becomes a no-op
10+
* and Mastra's OTEL/exporter configuration is the single source of truth.
11+
*/
12+
const VERCEL_OTEL_ENABLED = process.env.VERCEL_OTEL_ENABLED === "true";
13+
314
export function register() {
4-
registerOTel({ serviceName: "ai" });
15+
if (!VERCEL_OTEL_ENABLED) {
16+
// Rely on Mastra's OTEL/exporter configuration in `src/mastra/index.ts`.
17+
// Intentionally do **not** call `registerOTel` here to prevent
18+
// duplicate instrumentation and conflicting OTEL SDK instances.
19+
return;
20+
}
21+
22+
// When explicitly enabled, use Vercel's OTEL setup.
23+
// Keep the service name aligned with Mastra's configuration (`"ai"`).
24+
registerOTel({
25+
serviceName: "ai",
26+
});
527
}

src/mastra/agents/dane.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { execaTool } from '../tools/execa-tool'
66
import type { GoogleGenerativeAIProviderOptions } from '@ai-sdk/google'
77
import type { RequestContext } from '@mastra/core/request-context'
88
import { TokenLimiterProcessor } from '@mastra/core/processors'
9+
import { webScraperTool } from '../tools'
910

1011
export interface DaneContext {
1112
userId?: string
@@ -191,19 +192,19 @@ export const dane = new Agent({
191192
google: {
192193
thinkingConfig: {
193194
includeThoughts: true,
194-
thinkingBudget: -1,
195+
thinkingLevel: 'high',
195196
},
196197
responseModalities: ['TEXT'],
197198
} satisfies GoogleGenerativeAIProviderOptions,
198199
}
199200
}
200201
},
201-
model: googleAIFlashLite,
202+
model: 'google/gemini-3-flash-preview',
202203
memory: pgMemory,
203204
tools: {
204205
execaTool,
205206
browserTool,
206-
googleSearch,
207+
webScraperTool,
207208
listEvents,
208209
},
209210
outputProcessors: [new TokenLimiterProcessor(1048576)]

src/mastra/agents/editorAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Tailor your editing style to the content type:
120120
return google.chat('gemini-2.5-flash-preview-09-2025')
121121
},
122122
memory: pgMemory,
123-
tools: [],
123+
// tools: [],
124124
scorers: {
125125

126126
},
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { Agent } from "@mastra/core/agent";
22
import { GoogleVoice } from "@mastra/voice-google";
3-
import { pgMemory, pgQueryTool } from '../config';
3+
import { pgMemory } from '../config';
44

5-
const instructions = `
5+
const instructions1 = `
66
You are an AI note assistant tasked with providing concise, structured summaries of their content... // omitted for brevity
77
`;
88

99
export const noteTakerAgent = new Agent({
1010
id: "noteTakerAgent",
1111
name: "Note Taker Agent",
12-
instructions: instructions,
12+
instructions: instructions1,
1313
memory: pgMemory,
14-
tools: [pgQueryTool],
14+
// tools: [],
1515
model: "google/gemini-2.5-flash-lite-preview-09-2025",
1616
voice: new GoogleVoice(), // Add OpenAI voice provider with default configuration
1717
});

src/mastra/agents/weather-agent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Agent } from '@mastra/core/agent';
22
import type { RequestContext } from '@mastra/core/request-context'
33
import { googleAI, googleAIFlashLite, googleAIPro } from '../config/google';
44
import { pgMemory } from '../config/pg-storage';
5-
import { scorers } from '../scorers/weather-scorer';
65
import { mdocumentChunker } from '../tools/document-chunking.tool';
76
import { weatherTool } from '../tools/weather-tool';
87
import { webScraperTool } from '../tools/web-scraper-tool';
@@ -62,7 +61,7 @@ export const weatherAgent = new Agent({
6261
scorers: {
6362

6463
},
65-
outputProcessors: [new TokenLimiterProcessor(1048576)],
64+
outputProcessors: [new TokenLimiterProcessor(128000)],
6665
memory: pgMemory,
6766
options: {},
6867
maxRetries: 5

src/mastra/experiments/agent-experiments.ts renamed to src/mastra/evals/agent-experiments.ts

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,10 @@ import { evaluationAgent } from '../agents/evaluationAgent'
99
import { imageToCsvAgent } from '../agents/image_to_csv'
1010
import { csvToExcalidrawAgent } from '../agents/csv_to_excalidraw'
1111
import { weatherAgent } from '../agents/weather-agent'
12-
import {
13-
structureScorer,
14-
creativityScorer,
15-
sqlValidityScorer,
16-
toneConsistencyScorer,
17-
responseQualityScorer,
18-
scriptFormatScorer,
19-
pacingScorer,
20-
financialDataScorer,
21-
sourceDiversityScorer,
22-
csvValidityScorer,
23-
factualityScorer
24-
} from '../scorers'
12+
import { log } from '../config/logger';
2513

2614
export async function runContentStrategistExperiment() {
27-
console.log('Running Content Strategist Experiment...')
15+
log.info('Running Content Strategist Experiment', { event: 'Running Content Strategist Experiment' })
2816
const results = await runEvals({
2917
target: contentStrategistAgent,
3018
data: [
@@ -38,14 +26,14 @@ export async function runContentStrategistExperiment() {
3826
input: 'Plan a blog series for a B2B SaaS accounting tool. Target audience: CFOs. Tone: Professional and authoritative.'
3927
}
4028
],
41-
scorers: [structureScorer, creativityScorer, toneConsistencyScorer]
29+
scorers: []
4230
})
43-
console.log('Content Strategist Experiment Results:', JSON.stringify(results, null, 2))
31+
log.info('Content Strategist Experiment Results', { results: JSON.stringify(results, null, 2) })
4432
return results
4533
}
4634

4735
export async function runCopywriterExperiment() {
48-
console.log('Running Copywriter Experiment...')
36+
log.info('Running Copywriter Experiment...')
4937
const results = await runEvals({
5038
target: copywriterAgent,
5139
data: [
@@ -59,14 +47,14 @@ export async function runCopywriterExperiment() {
5947
input: 'Write a product description for a luxury watch. Tone: Sophisticated and elegant.',
6048
}
6149
],
62-
scorers: [toneConsistencyScorer, creativityScorer, responseQualityScorer]
50+
scorers: []
6351
})
64-
console.log('Copywriter Experiment Results:', JSON.stringify(results, null, 2))
52+
log.info('Copywriter Experiment Results:', { results: JSON.stringify(results, null, 2) })
6553
return results
6654
}
6755

6856
export async function runScriptWriterExperiment() {
69-
console.log('Running Script Writer Experiment...')
57+
log.info('Running Script Writer Experiment...')
7058
const results = await runEvals({
7159
target: scriptWriterAgent,
7260
data: [
@@ -77,14 +65,14 @@ export async function runScriptWriterExperiment() {
7765
input: 'Create a YouTube intro for a tech review channel.',
7866
}
7967
],
80-
scorers: [scriptFormatScorer, pacingScorer, creativityScorer]
68+
scorers: []
8169
})
82-
console.log('Script Writer Experiment Results:', JSON.stringify(results, null, 2))
70+
log.info('Script Writer Experiment Results:', { results: JSON.stringify(results, null, 2) })
8371
return results
8472
}
8573

8674
export async function runStockAnalysisExperiment() {
87-
console.log('Running Stock Analysis Experiment...')
75+
log.info('Running Stock Analysis Experiment...')
8876
const results = await runEvals({
8977
target: stockAnalysisAgent,
9078
data: [
@@ -95,14 +83,14 @@ export async function runStockAnalysisExperiment() {
9583
input: 'Should I buy TSLA right now?',
9684
}
9785
],
98-
scorers: [financialDataScorer, responseQualityScorer, sourceDiversityScorer]
86+
scorers: []
9987
})
100-
console.log('Stock Analysis Experiment Results:', JSON.stringify(results, null, 2))
88+
log.info('Stock Analysis Experiment Results:', { results: JSON.stringify(results, null, 2) })
10189
return results
10290
}
10391

10492
export async function runReportAgentExperiment() {
105-
console.log('Running Report Agent Experiment...')
93+
log.info('Running Report Agent Experiment...')
10694
const results = await runEvals({
10795
target: reportAgent,
10896
data: [
@@ -113,74 +101,74 @@ export async function runReportAgentExperiment() {
113101
input: 'Summarize the key findings from the user research interviews.',
114102
}
115103
],
116-
scorers: [structureScorer, responseQualityScorer, factualityScorer]
104+
scorers: []
117105
})
118-
console.log('Report Agent Experiment Results:', JSON.stringify(results, null, 2))
106+
log.info('Report Agent Experiment Results:', { results: JSON.stringify(results, null, 2) })
119107
return results
120108
}
121109

122110
export async function runLearningExtractionExperiment() {
123-
console.log('Running Learning Extraction Experiment...')
111+
log.info('Running Learning Extraction Experiment...')
124112
const results = await runEvals({
125113
target: learningExtractionAgent,
126114
data: [
127115
{
128116
input: 'Extract key learning points from this article about Rust ownership.'
129117
}
130118
],
131-
scorers: [responseQualityScorer, factualityScorer]
119+
scorers: []
132120
})
133-
console.log('Learning Extraction Experiment Results:', JSON.stringify(results, null, 2))
134-
return results
121+
log.info('Learning Extraction Experiment Results:', { results: JSON.stringify(results, null, 2) })
122+
return results
135123
}
136124

137125
export async function runEvaluationAgentExperiment() {
138-
console.log('Running Evaluation Agent Experiment...')
126+
log.info('Running Evaluation Agent Experiment...')
139127
const results = await runEvals({
140128
target: evaluationAgent,
141129
data: [
142130
{
143131
input: 'Evaluate this python code for efficiency: def fib(n): return n if n < 2 else fib(n-1) + fib(n-2)',
144132
}
145133
],
146-
scorers: [responseQualityScorer, structureScorer]
134+
scorers: []
147135
})
148-
console.log('Evaluation Agent Experiment Results:', JSON.stringify(results, null, 2))
136+
log.info('Evaluation Agent Experiment Results:', { results: JSON.stringify(results, null, 2) })
149137
return results
150138
}
151139

152140
export async function runImageToCsvExperiment() {
153-
console.log('Running Image to CSV Experiment...')
141+
log.info('Running Image to CSV Experiment...')
154142
const results = await runEvals({
155143
target: imageToCsvAgent,
156144
data: [
157145
{
158146
input: 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv',
159147
}
160148
],
161-
scorers: [csvValidityScorer, structureScorer]
149+
scorers: []
162150
})
163-
console.log('Image to CSV Experiment Results:', JSON.stringify(results, null, 2))
151+
log.info('Image to CSV Experiment Results:', { results: JSON.stringify(results, null, 2) })
164152
return results
165153
}
166154

167155
export async function runCsvToExcalidrawExperiment() {
168-
console.log('Running CSV to Excalidraw Experiment...')
156+
log.info('Running CSV to Excalidraw Experiment...')
169157
const results = await runEvals({
170158
target: csvToExcalidrawAgent,
171159
data: [
172160
{
173161
input: 'id,label,x,y\n1,Start,0,0\n2,Process,100,0\n3,End,200,0',
174162
}
175163
],
176-
scorers: [structureScorer, responseQualityScorer]
164+
scorers: []
177165
})
178-
console.log('CSV to Excalidraw Experiment Results:', JSON.stringify(results, null, 2))
166+
log.info('CSV to Excalidraw Experiment Results:', { results: JSON.stringify(results, null, 2) })
179167
return results
180168
}
181169

182170
export async function runWeatherAgentExperiment() {
183-
console.log('Running Weather Agent Experiment...')
171+
log.info('Running Weather Agent Experiment...')
184172
const results = await runEvals({
185173
target: weatherAgent,
186174
data: [
@@ -191,9 +179,9 @@ export async function runWeatherAgentExperiment() {
191179
input: 'Forecast for London tomorrow.',
192180
}
193181
],
194-
scorers: [factualityScorer, responseQualityScorer]
182+
scorers: []
195183
})
196-
console.log('Weather Agent Experiment Results:', JSON.stringify(results, null, 2))
184+
log.info('Weather Agent Experiment Results:', { results: JSON.stringify(results, null, 2) })
197185
return results
198186
}
199187

src/mastra/workflows/changelog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const stepA1 = createStep({
219219
id: 'stepA1',
220220
});
221221

222-
222+
223223
return {
224224
message: combinedChangelog,
225225
};
@@ -314,7 +314,7 @@ const stepA2 = createStep({
314314
try {
315315
const result = await agent.generate(prompt, {
316316
toolsets: {
317-
slack: tools,
317+
// slack: tools,
318318
},
319319
});
320320

@@ -330,7 +330,7 @@ const stepA2 = createStep({
330330
id: 'stepA2',
331331
});
332332

333-
333+
334334
return {
335335
message: result.text,
336336
};
@@ -347,7 +347,7 @@ const stepA2 = createStep({
347347
id: 'stepA2',
348348
});
349349

350-
350+
351351
return {
352352
message: e as string,
353353
};

src/mastra/workflows/content-review-workflow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const researchTopicStep = createStep({
126126
})
127127

128128
const prompt = `Research the topic "${inputData.topic}" for a ${inputData.contentType}
129-
${inputData.targetAudience ? `targeting ${inputData.targetAudience}` : ''}.
129+
${inputData.targetAudience !== undefined && inputData.targetAudience !== null && inputData.targetAudience.trim().length > 0 ? `targeting ${inputData.targetAudience}` : ''}.
130130
Provide a summary, key points, relevant sources, and interesting facts.`;
131131

132132
const stream = await agent.stream(prompt, {
@@ -261,7 +261,7 @@ const draftContentStep = createStep({
261261
262262
Research Summary: ${inputData.research.summary}
263263
Key Points to Cover: ${inputData.research.keyPoints.join(', ')}
264-
${inputData.targetAudience ? `Target Audience: ${inputData.targetAudience}` : ''}
264+
${inputData.targetAudience !== undefined && inputData.targetAudience !== null && inputData.targetAudience.trim().length > 0 ? `Target Audience: ${inputData.targetAudience}` : ''}
265265
266266
Create engaging, well-structured content.`;
267267

src/mastra/workflows/financial-report-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ const analyzeDataStep = createStep({
757757
}));
758758
}
759759

760-
760+
761761
const result: z.infer<typeof analysisResultSchema> = {
762762
stocks: inputData.stocks,
763763
analysis: {

src/mastra/workflows/repo-ingestion-workflow.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ const scanStep = createStep({
9898
);
9999

100100
// Type guard to narrow to the success shape
101-
const isScanSuccess = (r: any): r is { success: boolean; tree?: GitTreeItem[]; error?: string } =>
102-
(Boolean(r)) && typeof r === 'object' && 'success' in r;
101+
const isScanSuccess = (r: unknown): r is { success: boolean; tree?: GitTreeItem[]; error?: string } =>
102+
r !== null && typeof r === 'object' && 'success' in r;
103103

104104
if (!isScanSuccess(scanResultRaw) || !scanResultRaw.success || !scanResultRaw.tree) {
105-
throw new Error(`Failed to scan GitHub repo: ${(scanResultRaw as any)?.error ?? 'unknown error'}`);
105+
const errorMessage = isScanSuccess(scanResultRaw) ? (scanResultRaw.error ?? 'unknown error') : 'unknown error';
106+
throw new Error(`Failed to scan GitHub repo: ${errorMessage}`);
106107
}
107108

108109
// At this point, scanResultRaw.tree is present
@@ -229,7 +230,7 @@ const ingestStep = createStep({
229230
}
230231

231232
const successResult = result as { success: boolean; content?: string; encoding?: string; sha?: string; size?: number; error?: string };
232-
if (!successResult.success || !successResult.content) {
233+
if (!successResult.success || successResult.content === null || successResult.content === undefined || successResult.content === '') {
233234
throw new Error(`Failed to fetch file from GitHub: ${successResult.error}`);
234235
}
235236
content = successResult.content;

0 commit comments

Comments
 (0)