const agent = new Agent({ id: 'chef', name: 'Chef Agent', instructions: 'You are a professional chef who helps users with recipes and cooking techniques.', model: 'openai/gpt-4o',});
const agent = new Agent({ id: 'chef', name: 'Chef Agent', instructions: { role: 'system', content: `You are Michel, a practical and experienced home chef. Help users cook great meals with whatever ingredients they have available. Explain steps clearly and offer substitutions when needed.`, }, model: 'openai/gpt-4o',});
import { RequestContext } from '@mastra/core/request-context';const agent = new Agent({ id: 'support-agent', name: 'Support Agent', instructions: ({ requestContext }) => { const userTier = requestContext.get('userTier'); const language = requestContext.get('language') || 'en'; if (userTier === 'premium') { return `You are a premium support agent. Provide priority assistance in ${language}.`; } return `You are a support agent. Provide helpful assistance in ${language}.`; }, model: 'openai/gpt-4o',});// Use with contextconst ctx = new RequestContext();ctx.set('userTier', 'premium');ctx.set('language', 'es');const result = await agent.generate('Necesito ayuda', { requestContext: ctx,});
import { Agent } from '@mastra/core/agent';import { Workspace, LocalFilesystem } from '@mastra/core/workspace';const workspace = new Workspace({ filesystem: new LocalFilesystem({ basePath: './research-data', }),});const researchAgent = new Agent({ id: 'research-agent', name: 'Research Agent', description: 'Conducts research and saves findings', instructions: `You are a research agent. When researching topics: 1. Gather comprehensive information 2. Save your findings to files 3. Cite sources 4. Provide summaries`, model: 'openai/gpt-4o', workspace,});// Agent can now use workspace tools automatically:// - write_file// - read_file// - list_files// - delete_file
Choose IDs that are URL-safe and names that clearly describe the agent’s purpose:
// Goodid: 'customer-support-agent'name: 'Customer Support Agent'// Avoidid: 'agent1'name: 'Agent'
Write clear, specific instructions
Be explicit about the agent’s role, constraints, and behavior:
instructions: `You are a technical support specialist for SaaS products.- Always ask for error messages and screenshots- Provide step-by-step troubleshooting- Escalate to engineering if issue persists after 3 attempts- Be patient and encouraging`