@mastra/mcp-docs-server 0.13.12-alpha.0 ā 0.13.12-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +14 -0
- package/.docs/organized/changelogs/create-mastra.md +8 -8
- package/.docs/organized/changelogs/mastra.md +21 -21
- package/.docs/organized/code-examples/agent.md +293 -276
- package/.docs/raw/agents/input-processors.mdx +25 -19
- package/.docs/raw/agents/output-processors.mdx +376 -0
- package/.docs/raw/agents/overview.mdx +165 -188
- package/.docs/raw/agents/streaming.mdx +11 -5
- package/.docs/raw/community/contributing-templates.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +9 -9
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +27 -33
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +12 -12
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +17 -17
- package/.docs/raw/getting-started/templates.mdx +1 -1
- package/.docs/raw/rag/vector-databases.mdx +9 -1
- package/.docs/raw/reference/agents/agent.mdx +8 -2
- package/.docs/raw/reference/agents/generate.mdx +80 -3
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/streamVNext.mdx +88 -5
- package/.docs/raw/reference/rag/chroma.mdx +158 -17
- package/.docs/raw/reference/tools/mcp-client.mdx +9 -9
- package/.docs/raw/reference/tools/mcp-server.mdx +5 -5
- package/.docs/raw/reference/workflows/run-methods/streamVNext.mdx +7 -1
- package/.docs/raw/voice/overview.mdx +81 -2
- package/.docs/raw/voice/speech-to-speech.mdx +45 -0
- package/.docs/raw/workflows/overview.mdx +8 -1
- package/package.json +5 -5
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
{
|
|
4
4
|
"name": "examples-agent",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@ai-sdk/
|
|
7
|
-
"@ai-sdk/
|
|
6
|
+
"@ai-sdk/google": "^1.2.22",
|
|
7
|
+
"@ai-sdk/openai": "^1.3.23",
|
|
8
8
|
"@mastra/client-js": "latest",
|
|
9
9
|
"@mastra/core": "latest",
|
|
10
|
+
"@mastra/evals": "latest",
|
|
11
|
+
"@mastra/libsql": "latest",
|
|
10
12
|
"@mastra/loggers": "latest",
|
|
11
13
|
"@mastra/mcp": "latest",
|
|
12
14
|
"@mastra/memory": "latest",
|
|
13
15
|
"@mastra/voice-openai": "latest",
|
|
14
|
-
"@mastra/libsql": "latest",
|
|
15
|
-
"@mastra/evals": "latest",
|
|
16
16
|
"ai": "^4.3.16",
|
|
17
17
|
"fetch-to-node": "^2.1.0",
|
|
18
18
|
"mastra": "latest",
|
|
19
|
+
"typescript": "^5.8.3",
|
|
19
20
|
"zod": "^3.25.67"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -175,281 +176,290 @@ import { mastra } from './mastra';
|
|
|
175
176
|
|
|
176
177
|
const agent = mastra.getAgent('chefAgent');
|
|
177
178
|
const responsesAgent = mastra.getAgent('chefAgentResponses');
|
|
179
|
+
const agentThatHarassesYou = mastra.getAgent('agentThatHarassesYou');
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
// Query 1: Basic pantry ingredients
|
|
181
|
-
const query1 =
|
|
182
|
-
'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
|
|
183
|
-
console.log(`Query 1: ${query1}`);
|
|
184
|
-
|
|
185
|
-
const pastaResponse = await agent.generate(query1);
|
|
186
|
-
console.log('\nšØāš³ Chef Michel:', pastaResponse.text);
|
|
187
|
-
console.log('\n-------------------\n');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function generateText() {
|
|
191
|
-
// Query 1: Basic pantry ingredients
|
|
192
|
-
|
|
193
|
-
const query1 =
|
|
194
|
-
'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
|
|
195
|
-
console.log(`Query 1: ${query1}`);
|
|
196
|
-
|
|
197
|
-
const pastaResponse = await agent.generate(query1);
|
|
198
|
-
|
|
199
|
-
console.log('\nšØāš³ Chef Michel:', pastaResponse.text);
|
|
200
|
-
console.log('\n-------------------\n');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async function textStream() {
|
|
204
|
-
// Query 2: More ingredients
|
|
205
|
-
const query2 =
|
|
206
|
-
"Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
|
|
207
|
-
console.log(`Query 2: ${query2}`);
|
|
208
|
-
|
|
209
|
-
const curryResponse = await agent.stream(query2);
|
|
210
|
-
|
|
211
|
-
console.log('\nšØāš³ Chef Michel: ');
|
|
212
|
-
|
|
213
|
-
// Handle the stream
|
|
214
|
-
for await (const chunk of curryResponse.textStream) {
|
|
215
|
-
// Write each chunk without a newline to create a continuous stream
|
|
216
|
-
process.stdout.write(chunk);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
console.log('\n\nā
Recipe complete!');
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async function generateStream() {
|
|
223
|
-
// Query 2: More ingredients
|
|
224
|
-
const query2 =
|
|
225
|
-
"Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
|
|
226
|
-
console.log(`Query 2: ${query2}`);
|
|
227
|
-
|
|
228
|
-
const curryResponse = await agent.stream([query2]);
|
|
229
|
-
|
|
230
|
-
console.log('\nšØāš³ Chef Michel: ');
|
|
231
|
-
|
|
232
|
-
// Handle the stream
|
|
233
|
-
for await (const chunk of curryResponse.textStream) {
|
|
234
|
-
// Write each chunk without a newline to create a continuous stream
|
|
235
|
-
process.stdout.write(chunk);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
console.log('\n\nā
Recipe complete!');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
async function textObject() {
|
|
242
|
-
// Query 3: Generate a lasagna recipe
|
|
243
|
-
const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
244
|
-
console.log(`Query 3: ${query3}`);
|
|
245
|
-
|
|
246
|
-
const lasagnaResponse = await agent.generate(query3, {
|
|
247
|
-
output: z.object({
|
|
248
|
-
ingredients: z.array(
|
|
249
|
-
z.object({
|
|
250
|
-
name: z.string(),
|
|
251
|
-
amount: z.number(),
|
|
252
|
-
}),
|
|
253
|
-
),
|
|
254
|
-
steps: z.array(z.string()),
|
|
255
|
-
}),
|
|
256
|
-
});
|
|
257
|
-
console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
258
|
-
console.log('\n-------------------\n');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async function experimentalTextObject() {
|
|
262
|
-
// Query 3: Generate a lasagna recipe
|
|
263
|
-
const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
264
|
-
console.log(`Query 3: ${query3}`);
|
|
265
|
-
|
|
266
|
-
const lasagnaResponse = await agent.generate(query3, {
|
|
267
|
-
experimental_output: z.object({
|
|
268
|
-
ingredients: z.array(
|
|
269
|
-
z.object({
|
|
270
|
-
name: z.string(),
|
|
271
|
-
amount: z.number(),
|
|
272
|
-
}),
|
|
273
|
-
),
|
|
274
|
-
steps: z.array(z.string()),
|
|
275
|
-
}),
|
|
276
|
-
});
|
|
277
|
-
console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
278
|
-
console.log('\n-------------------\n');
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async function textObjectJsonSchema() {
|
|
282
|
-
// Query 3: Generate a lasagna recipe
|
|
283
|
-
const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
284
|
-
console.log(`Query 3: ${query3}`);
|
|
285
|
-
|
|
286
|
-
const lasagnaResponse = await agent.generate(query3, {
|
|
287
|
-
output: {
|
|
288
|
-
type: 'object',
|
|
289
|
-
additionalProperties: false,
|
|
290
|
-
required: ['ingredients', 'steps'],
|
|
291
|
-
properties: {
|
|
292
|
-
ingredients: {
|
|
293
|
-
type: 'array',
|
|
294
|
-
items: {
|
|
295
|
-
type: 'object',
|
|
296
|
-
additionalProperties: false,
|
|
297
|
-
properties: {
|
|
298
|
-
name: { type: 'string' },
|
|
299
|
-
amount: { type: 'number' },
|
|
300
|
-
},
|
|
301
|
-
required: ['name', 'amount'],
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
steps: {
|
|
305
|
-
type: 'array',
|
|
306
|
-
items: { type: 'string' },
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
313
|
-
console.log('\n-------------------\n');
|
|
314
|
-
}
|
|
181
|
+
const stream = await agentThatHarassesYou.streamVNext('I want to fight you');
|
|
315
182
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
319
|
-
console.log(`Query 3: ${query3}`);
|
|
320
|
-
|
|
321
|
-
const lasagnaResponse = await agent.generate([query3], {
|
|
322
|
-
output: z.object({
|
|
323
|
-
ingredients: z.array(
|
|
324
|
-
z.object({
|
|
325
|
-
name: z.string(),
|
|
326
|
-
amount: z.number(),
|
|
327
|
-
}),
|
|
328
|
-
),
|
|
329
|
-
steps: z.array(z.string()),
|
|
330
|
-
}),
|
|
331
|
-
});
|
|
332
|
-
console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
333
|
-
console.log('\n-------------------\n');
|
|
183
|
+
for await (const chunk of stream.textStream) {
|
|
184
|
+
console.log(`frontend received chunk: ${chunk}`);
|
|
334
185
|
}
|
|
335
186
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
187
|
+
console.log('done');
|
|
188
|
+
|
|
189
|
+
// async function text() {
|
|
190
|
+
// // Query 1: Basic pantry ingredients
|
|
191
|
+
// const query1 =
|
|
192
|
+
// 'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
|
|
193
|
+
// console.log(`Query 1: ${query1}`);
|
|
194
|
+
|
|
195
|
+
// const pastaResponse = await agent.generate(query1);
|
|
196
|
+
// console.log('\nšØāš³ Chef Michel:', pastaResponse.text);
|
|
197
|
+
// console.log('\n-------------------\n');
|
|
198
|
+
// }
|
|
199
|
+
|
|
200
|
+
// async function generateText() {
|
|
201
|
+
// // Query 1: Basic pantry ingredients
|
|
202
|
+
|
|
203
|
+
// const query1 =
|
|
204
|
+
// 'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
|
|
205
|
+
// console.log(`Query 1: ${query1}`);
|
|
206
|
+
|
|
207
|
+
// const pastaResponse = await agent.generate(query1);
|
|
208
|
+
|
|
209
|
+
// console.log('\nšØāš³ Chef Michel:', pastaResponse.text);
|
|
210
|
+
// console.log('\n-------------------\n');
|
|
211
|
+
// }
|
|
212
|
+
|
|
213
|
+
// async function textStream() {
|
|
214
|
+
// // Query 2: More ingredients
|
|
215
|
+
// const query2 =
|
|
216
|
+
// "Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
|
|
217
|
+
// console.log(`Query 2: ${query2}`);
|
|
218
|
+
|
|
219
|
+
// const curryResponse = await agent.stream(query2);
|
|
220
|
+
|
|
221
|
+
// console.log('\nšØāš³ Chef Michel: ');
|
|
222
|
+
|
|
223
|
+
// // Handle the stream
|
|
224
|
+
// for await (const chunk of curryResponse.textStream) {
|
|
225
|
+
// // Write each chunk without a newline to create a continuous stream
|
|
226
|
+
// process.stdout.write(chunk);
|
|
227
|
+
// }
|
|
228
|
+
|
|
229
|
+
// console.log('\n\nā
Recipe complete!');
|
|
230
|
+
// }
|
|
231
|
+
|
|
232
|
+
// async function generateStream() {
|
|
233
|
+
// // Query 2: More ingredients
|
|
234
|
+
// const query2 =
|
|
235
|
+
// "Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
|
|
236
|
+
// console.log(`Query 2: ${query2}`);
|
|
237
|
+
|
|
238
|
+
// const curryResponse = await agent.stream([query2]);
|
|
239
|
+
|
|
240
|
+
// console.log('\nšØāš³ Chef Michel: ');
|
|
241
|
+
|
|
242
|
+
// // Handle the stream
|
|
243
|
+
// for await (const chunk of curryResponse.textStream) {
|
|
244
|
+
// // Write each chunk without a newline to create a continuous stream
|
|
245
|
+
// process.stdout.write(chunk);
|
|
246
|
+
// }
|
|
247
|
+
|
|
248
|
+
// console.log('\n\nā
Recipe complete!');
|
|
249
|
+
// }
|
|
250
|
+
|
|
251
|
+
// async function textObject() {
|
|
252
|
+
// // Query 3: Generate a lasagna recipe
|
|
253
|
+
// const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
254
|
+
// console.log(`Query 3: ${query3}`);
|
|
255
|
+
|
|
256
|
+
// const lasagnaResponse = await agent.generate(query3, {
|
|
257
|
+
// output: z.object({
|
|
258
|
+
// ingredients: z.array(
|
|
259
|
+
// z.object({
|
|
260
|
+
// name: z.string(),
|
|
261
|
+
// amount: z.number(),
|
|
262
|
+
// }),
|
|
263
|
+
// ),
|
|
264
|
+
// steps: z.array(z.string()),
|
|
265
|
+
// }),
|
|
266
|
+
// });
|
|
267
|
+
// console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
268
|
+
// console.log('\n-------------------\n');
|
|
269
|
+
// }
|
|
270
|
+
|
|
271
|
+
// async function experimentalTextObject() {
|
|
272
|
+
// // Query 3: Generate a lasagna recipe
|
|
273
|
+
// const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
274
|
+
// console.log(`Query 3: ${query3}`);
|
|
275
|
+
|
|
276
|
+
// const lasagnaResponse = await agent.generate(query3, {
|
|
277
|
+
// experimental_output: z.object({
|
|
278
|
+
// ingredients: z.array(
|
|
279
|
+
// z.object({
|
|
280
|
+
// name: z.string(),
|
|
281
|
+
// amount: z.number(),
|
|
282
|
+
// }),
|
|
283
|
+
// ),
|
|
284
|
+
// steps: z.array(z.string()),
|
|
285
|
+
// }),
|
|
286
|
+
// });
|
|
287
|
+
// console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
288
|
+
// console.log('\n-------------------\n');
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// async function textObjectJsonSchema() {
|
|
292
|
+
// // Query 3: Generate a lasagna recipe
|
|
293
|
+
// const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
294
|
+
// console.log(`Query 3: ${query3}`);
|
|
295
|
+
|
|
296
|
+
// const lasagnaResponse = await agent.generate(query3, {
|
|
297
|
+
// output: {
|
|
298
|
+
// type: 'object',
|
|
299
|
+
// additionalProperties: false,
|
|
300
|
+
// required: ['ingredients', 'steps'],
|
|
301
|
+
// properties: {
|
|
302
|
+
// ingredients: {
|
|
303
|
+
// type: 'array',
|
|
304
|
+
// items: {
|
|
305
|
+
// type: 'object',
|
|
306
|
+
// additionalProperties: false,
|
|
307
|
+
// properties: {
|
|
308
|
+
// name: { type: 'string' },
|
|
309
|
+
// amount: { type: 'number' },
|
|
310
|
+
// },
|
|
311
|
+
// required: ['name', 'amount'],
|
|
312
|
+
// },
|
|
313
|
+
// },
|
|
314
|
+
// steps: {
|
|
315
|
+
// type: 'array',
|
|
316
|
+
// items: { type: 'string' },
|
|
317
|
+
// },
|
|
318
|
+
// },
|
|
319
|
+
// },
|
|
320
|
+
// });
|
|
321
|
+
|
|
322
|
+
// console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
323
|
+
// console.log('\n-------------------\n');
|
|
324
|
+
// }
|
|
325
|
+
|
|
326
|
+
// async function generateObject() {
|
|
327
|
+
// // Query 3: Generate a lasagna recipe
|
|
328
|
+
// const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
329
|
+
// console.log(`Query 3: ${query3}`);
|
|
330
|
+
|
|
331
|
+
// const lasagnaResponse = await agent.generate([query3], {
|
|
332
|
+
// output: z.object({
|
|
333
|
+
// ingredients: z.array(
|
|
334
|
+
// z.object({
|
|
335
|
+
// name: z.string(),
|
|
336
|
+
// amount: z.number(),
|
|
337
|
+
// }),
|
|
338
|
+
// ),
|
|
339
|
+
// steps: z.array(z.string()),
|
|
340
|
+
// }),
|
|
341
|
+
// });
|
|
342
|
+
// console.log('\nšØāš³ Chef Michel:', lasagnaResponse.object);
|
|
343
|
+
// console.log('\n-------------------\n');
|
|
344
|
+
// }
|
|
345
|
+
|
|
346
|
+
// async function streamObject() {
|
|
347
|
+
// // Query 8: Generate a lasagna recipe
|
|
348
|
+
// const query8 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
349
|
+
// console.log(`Query 8: ${query8}`);
|
|
350
|
+
|
|
351
|
+
// const lasagnaStreamResponse = await agent.stream(query8, {
|
|
352
|
+
// output: z.object({
|
|
353
|
+
// ingredients: z.array(
|
|
354
|
+
// z.object({
|
|
355
|
+
// name: z.string(),
|
|
356
|
+
// amount: z.number(),
|
|
357
|
+
// }),
|
|
358
|
+
// ),
|
|
359
|
+
// steps: z.array(z.string()),
|
|
360
|
+
// }),
|
|
361
|
+
// });
|
|
362
|
+
|
|
363
|
+
// console.log('\nšØāš³ Chef Michel: ');
|
|
364
|
+
|
|
365
|
+
// // Handle the stream
|
|
366
|
+
// for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
367
|
+
// // Write each chunk without a newline to create a continuous stream
|
|
368
|
+
// process.stdout.write(chunk);
|
|
369
|
+
// }
|
|
370
|
+
|
|
371
|
+
// console.log('\n\nā
Recipe complete!');
|
|
372
|
+
// }
|
|
373
|
+
|
|
374
|
+
// async function generateStreamObject() {
|
|
375
|
+
// // Query 9: Generate a lasagna recipe
|
|
376
|
+
// const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
377
|
+
// console.log(`Query 9: ${query9}`);
|
|
378
|
+
|
|
379
|
+
// const lasagnaStreamResponse = await agent.stream([query9], {
|
|
380
|
+
// output: z.object({
|
|
381
|
+
// ingredients: z.array(
|
|
382
|
+
// z.object({
|
|
383
|
+
// name: z.string(),
|
|
384
|
+
// amount: z.number(),
|
|
385
|
+
// }),
|
|
386
|
+
// ),
|
|
387
|
+
// steps: z.array(z.string()),
|
|
388
|
+
// }),
|
|
389
|
+
// });
|
|
390
|
+
|
|
391
|
+
// console.log('\nšØāš³ Chef Michel: ');
|
|
392
|
+
|
|
393
|
+
// // Handle the stream
|
|
394
|
+
// for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
395
|
+
// // Write each chunk without a newline to create a continuous stream
|
|
396
|
+
// process.stdout.write(chunk);
|
|
397
|
+
// }
|
|
398
|
+
|
|
399
|
+
// console.log('\n\nā
Recipe complete!');
|
|
400
|
+
// }
|
|
401
|
+
|
|
402
|
+
// async function generateExperimentalStreamObject() {
|
|
403
|
+
// // Query 9: Generate a lasagna recipe
|
|
404
|
+
// const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
405
|
+
// console.log(`Query 9: ${query9}`);
|
|
406
|
+
|
|
407
|
+
// const lasagnaStreamResponse = await agent.stream([query9], {
|
|
408
|
+
// experimental_output: z.object({
|
|
409
|
+
// ingredients: z.array(
|
|
410
|
+
// z.object({
|
|
411
|
+
// name: z.string(),
|
|
412
|
+
// amount: z.number(),
|
|
413
|
+
// }),
|
|
414
|
+
// ),
|
|
415
|
+
// steps: z.array(z.string()),
|
|
416
|
+
// }),
|
|
417
|
+
// });
|
|
418
|
+
|
|
419
|
+
// console.log('\nšØāš³ Chef Michel: ');
|
|
420
|
+
|
|
421
|
+
// // Handle the stream
|
|
422
|
+
// for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
423
|
+
// // Write each chunk without a newline to create a continuous stream
|
|
424
|
+
// process.stdout.write(chunk);
|
|
425
|
+
// }
|
|
426
|
+
|
|
427
|
+
// console.log('\n\nā
Recipe complete!');
|
|
428
|
+
// }
|
|
429
|
+
|
|
430
|
+
// async function main() {
|
|
431
|
+
// // await text();
|
|
432
|
+
|
|
433
|
+
// // await experimentalTextObject();
|
|
434
|
+
|
|
435
|
+
// // await generateExperimentalStreamObject();
|
|
436
|
+
|
|
437
|
+
// // await generateText();
|
|
352
438
|
|
|
353
|
-
|
|
439
|
+
// // await textStream();
|
|
354
440
|
|
|
355
|
-
|
|
356
|
-
for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
357
|
-
// Write each chunk without a newline to create a continuous stream
|
|
358
|
-
process.stdout.write(chunk);
|
|
359
|
-
}
|
|
441
|
+
// // await generateStream();
|
|
360
442
|
|
|
361
|
-
|
|
362
|
-
}
|
|
443
|
+
// // await textObject();
|
|
363
444
|
|
|
364
|
-
|
|
365
|
-
// Query 9: Generate a lasagna recipe
|
|
366
|
-
const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
367
|
-
console.log(`Query 9: ${query9}`);
|
|
368
|
-
|
|
369
|
-
const lasagnaStreamResponse = await agent.stream([query9], {
|
|
370
|
-
output: z.object({
|
|
371
|
-
ingredients: z.array(
|
|
372
|
-
z.object({
|
|
373
|
-
name: z.string(),
|
|
374
|
-
amount: z.number(),
|
|
375
|
-
}),
|
|
376
|
-
),
|
|
377
|
-
steps: z.array(z.string()),
|
|
378
|
-
}),
|
|
379
|
-
});
|
|
445
|
+
// // await textObjectJsonSchema();
|
|
380
446
|
|
|
381
|
-
|
|
447
|
+
// // await generateObject();
|
|
382
448
|
|
|
383
|
-
|
|
384
|
-
for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
385
|
-
// Write each chunk without a newline to create a continuous stream
|
|
386
|
-
process.stdout.write(chunk);
|
|
387
|
-
}
|
|
449
|
+
// // await streamObject();
|
|
388
450
|
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
async function generateExperimentalStreamObject() {
|
|
393
|
-
// Query 9: Generate a lasagna recipe
|
|
394
|
-
const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
|
|
395
|
-
console.log(`Query 9: ${query9}`);
|
|
396
|
-
|
|
397
|
-
const lasagnaStreamResponse = await agent.stream([query9], {
|
|
398
|
-
experimental_output: z.object({
|
|
399
|
-
ingredients: z.array(
|
|
400
|
-
z.object({
|
|
401
|
-
name: z.string(),
|
|
402
|
-
amount: z.number(),
|
|
403
|
-
}),
|
|
404
|
-
),
|
|
405
|
-
steps: z.array(z.string()),
|
|
406
|
-
}),
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
console.log('\nšØāš³ Chef Michel: ');
|
|
451
|
+
// // await generateStreamObject();
|
|
410
452
|
|
|
411
|
-
|
|
412
|
-
for await (const chunk of lasagnaStreamResponse.textStream) {
|
|
413
|
-
// Write each chunk without a newline to create a continuous stream
|
|
414
|
-
process.stdout.write(chunk);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
console.log('\n\nā
Recipe complete!');
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async function main() {
|
|
421
|
-
// await text();
|
|
453
|
+
// const query1 = 'What happened in San Francisco last week?';
|
|
422
454
|
|
|
423
|
-
|
|
455
|
+
// const pastaResponse = await responsesAgent.generate(query1, {
|
|
456
|
+
// instructions: 'You take every recipe you get an exaggerate it and use weird ingredients.',
|
|
457
|
+
// });
|
|
424
458
|
|
|
425
|
-
|
|
459
|
+
// console.log(pastaResponse.text);
|
|
460
|
+
// }
|
|
426
461
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// await textStream();
|
|
430
|
-
|
|
431
|
-
// await generateStream();
|
|
432
|
-
|
|
433
|
-
// await textObject();
|
|
434
|
-
|
|
435
|
-
// await textObjectJsonSchema();
|
|
436
|
-
|
|
437
|
-
// await generateObject();
|
|
438
|
-
|
|
439
|
-
// await streamObject();
|
|
440
|
-
|
|
441
|
-
// await generateStreamObject();
|
|
442
|
-
|
|
443
|
-
const query1 = 'What happened in San Francisco last week?';
|
|
444
|
-
|
|
445
|
-
const pastaResponse = await responsesAgent.generate(query1, {
|
|
446
|
-
instructions: 'You take every recipe you get an exaggerate it and use weird ingredients.',
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
console.log(pastaResponse.text);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
main();
|
|
462
|
+
// main();
|
|
453
463
|
|
|
454
464
|
```
|
|
455
465
|
|
|
@@ -463,12 +473,7 @@ import { Memory } from '@mastra/memory';
|
|
|
463
473
|
import { Agent, InputProcessor } from '@mastra/core/agent';
|
|
464
474
|
import { cookingTool } from '../tools/index.js';
|
|
465
475
|
import { myWorkflow } from '../workflows/index.js';
|
|
466
|
-
import {
|
|
467
|
-
PIIDetector,
|
|
468
|
-
LanguageDetector,
|
|
469
|
-
PromptInjectionDetector,
|
|
470
|
-
ModerationInputProcessor,
|
|
471
|
-
} from '@mastra/core/agent/input-processor/processors';
|
|
476
|
+
import { PIIDetector, LanguageDetector, PromptInjectionDetector, ModerationProcessor } from '@mastra/core/processors';
|
|
472
477
|
import { MCPClient } from '@mastra/mcp';
|
|
473
478
|
import { createAnswerRelevancyScorer } from '@mastra/evals/scorers/llm';
|
|
474
479
|
|
|
@@ -567,7 +572,8 @@ const vegetarianProcessor: InputProcessor = {
|
|
|
567
572
|
};
|
|
568
573
|
|
|
569
574
|
const piiDetector = new PIIDetector({
|
|
570
|
-
model: google('gemini-2.0-flash-001'),
|
|
575
|
+
// model: google('gemini-2.0-flash-001'),
|
|
576
|
+
model: openai('gpt-4o'),
|
|
571
577
|
redactionMethod: 'mask',
|
|
572
578
|
preserveFormat: true,
|
|
573
579
|
includeDetections: true,
|
|
@@ -584,9 +590,10 @@ const promptInjectionDetector = new PromptInjectionDetector({
|
|
|
584
590
|
strategy: 'block',
|
|
585
591
|
});
|
|
586
592
|
|
|
587
|
-
const moderationDetector = new
|
|
593
|
+
const moderationDetector = new ModerationProcessor({
|
|
588
594
|
model: google('gemini-2.0-flash-001'),
|
|
589
595
|
strategy: 'block',
|
|
596
|
+
chunkWindow: 10,
|
|
590
597
|
});
|
|
591
598
|
|
|
592
599
|
export const chefAgentResponses = new Agent({
|
|
@@ -597,6 +604,7 @@ export const chefAgentResponses = new Agent({
|
|
|
597
604
|
You explain cooking steps clearly and offer substitutions when needed, maintaining a friendly and encouraging tone throughout.
|
|
598
605
|
`,
|
|
599
606
|
model: openai.responses('gpt-4o'),
|
|
607
|
+
// model: cerebras('qwen-3-coder-480b'),
|
|
600
608
|
tools: async () => {
|
|
601
609
|
return {
|
|
602
610
|
web_search_preview: openai.tools.webSearchPreview(),
|
|
@@ -606,9 +614,9 @@ export const chefAgentResponses = new Agent({
|
|
|
606
614
|
myWorkflow,
|
|
607
615
|
},
|
|
608
616
|
inputProcessors: [
|
|
609
|
-
|
|
617
|
+
piiDetector,
|
|
610
618
|
// vegetarianProcessor,
|
|
611
|
-
languageDetector,
|
|
619
|
+
// languageDetector,
|
|
612
620
|
// promptInjectionDetector,
|
|
613
621
|
// moderationDetector,
|
|
614
622
|
{
|
|
@@ -647,6 +655,15 @@ export const chefAgentResponses = new Agent({
|
|
|
647
655
|
],
|
|
648
656
|
});
|
|
649
657
|
|
|
658
|
+
export const agentThatHarassesYou = new Agent({
|
|
659
|
+
name: 'Agent That Harasses You',
|
|
660
|
+
instructions: `
|
|
661
|
+
You are a agent that harasses you. You are a jerk. You are a meanie. You are a bully. You are a asshole.
|
|
662
|
+
`,
|
|
663
|
+
model: openai('gpt-4o'),
|
|
664
|
+
outputProcessors: [moderationDetector],
|
|
665
|
+
});
|
|
666
|
+
|
|
650
667
|
const answerRelevance = createAnswerRelevancyScorer({
|
|
651
668
|
model: openai('gpt-4o'),
|
|
652
669
|
});
|
|
@@ -684,7 +701,7 @@ import { Mastra } from '@mastra/core';
|
|
|
684
701
|
import { PinoLogger } from '@mastra/loggers';
|
|
685
702
|
import { LibSQLStore } from '@mastra/libsql';
|
|
686
703
|
|
|
687
|
-
import { chefAgent, chefAgentResponses, dynamicAgent, evalAgent } from './agents/index';
|
|
704
|
+
import { agentThatHarassesYou, chefAgent, chefAgentResponses, dynamicAgent, evalAgent } from './agents/index';
|
|
688
705
|
import { myMcpServer, myMcpServerTwo } from './mcp/server';
|
|
689
706
|
import { myWorkflow } from './workflows';
|
|
690
707
|
|
|
@@ -693,7 +710,7 @@ const storage = new LibSQLStore({
|
|
|
693
710
|
});
|
|
694
711
|
|
|
695
712
|
export const mastra = new Mastra({
|
|
696
|
-
agents: { chefAgent, chefAgentResponses, dynamicAgent, evalAgent },
|
|
713
|
+
agents: { chefAgent, chefAgentResponses, dynamicAgent, agentThatHarassesYou, evalAgent },
|
|
697
714
|
logger: new PinoLogger({ name: 'Chef', level: 'debug' }),
|
|
698
715
|
storage,
|
|
699
716
|
mcpServers: {
|