|
| 1 | +import { openai } from "@ai-sdk/openai"; |
| 2 | +import { Agent } from "@mastra/core/agent"; |
| 3 | +import { Memory } from "@mastra/memory"; |
| 4 | +import { LibSQLStore } from "@mastra/libsql"; |
| 5 | +import { Mastra } from "@mastra/core"; |
| 6 | +import { z } from "zod"; |
| 7 | + |
| 8 | +// import { weatherTool } from "../tools/weather-tool"; |
| 9 | + |
| 10 | +export const mastra = new Mastra({ |
| 11 | + agents: { |
| 12 | + agentic_chat: new Agent({ |
| 13 | + name: "agentic_chat", |
| 14 | + instructions: ` |
| 15 | + You are a helpful weather assistant that provides accurate weather information. |
| 16 | + |
| 17 | + Your primary function is to help users get weather details for specific locations. When responding: |
| 18 | + - Always ask for a location if none is provided |
| 19 | + - If the location name isn’t in English, please translate it |
| 20 | + - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York") |
| 21 | + - Include relevant details like humidity, wind conditions, and precipitation |
| 22 | + - Keep responses concise but informative |
| 23 | + |
| 24 | + Use the weatherTool to fetch current weather data. |
| 25 | + `, |
| 26 | + model: openai("gpt-4o"), |
| 27 | + // tools: { weatherTool }, |
| 28 | + memory: new Memory({ |
| 29 | + storage: new LibSQLStore({ url: "file::memory:" }), |
| 30 | + options: { |
| 31 | + workingMemory: { |
| 32 | + enabled: true, |
| 33 | + schema: z.object({ |
| 34 | + firstName: z.string(), |
| 35 | + }), |
| 36 | + }, |
| 37 | + }, |
| 38 | + }), |
| 39 | + }), |
| 40 | + shared_state: new Agent({ |
| 41 | + name: "shared_state", |
| 42 | + instructions: ` |
| 43 | + You are a helpful assistant for creating recipes. |
| 44 | +
|
| 45 | + IMPORTANT: |
| 46 | + 1. Create a recipe using the existing ingredients and instructions. Make sure the recipe is complete. |
| 47 | + 2. For ingredients, append new ingredients to the existing ones. |
| 48 | + 3. For instructions, append new steps to the existing ones. |
| 49 | + 4. 'ingredients' is always an array of objects with 'icon', 'name', and 'amount' fields |
| 50 | + 5. 'instructions' is always an array of strings |
| 51 | +
|
| 52 | + If you have just created or modified the recipe, just answer in one sentence what you did. dont describe the recipe, just say what you did. |
| 53 | + `, |
| 54 | + model: openai("gpt-4o"), |
| 55 | + memory: new Memory({ |
| 56 | + storage: new LibSQLStore({ url: "file::memory:" }), |
| 57 | + options: { |
| 58 | + workingMemory: { |
| 59 | + enabled: true, |
| 60 | + schema: z.object({ |
| 61 | + recipe: z.object({ |
| 62 | + skill_level: z |
| 63 | + .enum(["Beginner", "Intermediate", "Advanced"]) |
| 64 | + .describe("The skill level required for the recipe"), |
| 65 | + special_preferences: z |
| 66 | + .array( |
| 67 | + z.enum([ |
| 68 | + "High Protein", |
| 69 | + "Low Carb", |
| 70 | + "Spicy", |
| 71 | + "Budget-Friendly", |
| 72 | + "One-Pot Meal", |
| 73 | + "Vegetarian", |
| 74 | + "Vegan", |
| 75 | + ]), |
| 76 | + ) |
| 77 | + .describe("A list of special preferences for the recipe"), |
| 78 | + cooking_time: z |
| 79 | + .enum(["5 min", "15 min", "30 min", "45 min", "60+ min"]) |
| 80 | + .describe("The cooking time of the recipe"), |
| 81 | + ingredients: z |
| 82 | + .array( |
| 83 | + z.object({ |
| 84 | + icon: z |
| 85 | + .string() |
| 86 | + .describe( |
| 87 | + "The icon emoji (not emoji code like '\x1f35e', but the actual emoji like 🥕) of the ingredient", |
| 88 | + ), |
| 89 | + name: z.string().describe("The name of the ingredient"), |
| 90 | + amount: z.string().describe("The amount of the ingredient"), |
| 91 | + }), |
| 92 | + ) |
| 93 | + .describe( |
| 94 | + "Entire list of ingredients for the recipe, including the new ingredients and the ones that are already in the recipe", |
| 95 | + ), |
| 96 | + instructions: z |
| 97 | + .array(z.string()) |
| 98 | + .describe( |
| 99 | + "Entire list of instructions for the recipe, including the new instructions and the ones that are already there", |
| 100 | + ), |
| 101 | + changes: z.string().describe("A description of the changes made to the recipe"), |
| 102 | + }), |
| 103 | + }), |
| 104 | + }, |
| 105 | + }, |
| 106 | + }), |
| 107 | + }), |
| 108 | + }, |
| 109 | +}); |
0 commit comments