Back to Prompt Library
implementation
Mastra AI Agent Core Definition and Tools
Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.
Linked challenge: AI-Powered Productivity Agent for Enterprise Cost Optimization
Format
Code-aware
Lines
49
Sections
7
Linked challenge
AI-Powered Productivity Agent for Enterprise Cost Optimization
Prompt source
Original prompt text with formatting preserved for inspection.
49 lines
7 sections
No variables
1 code block
Using Mastra AI, define a primary `ProductivityOptimizerAgent`. This agent should be capable of:
1. Retrieving documents from a RAG system.
2. Analyzing structured and unstructured data using an LLM (Phi-3).
3. Triggering external automation workflows via Lyzr.
Provide the TypeScript code for the Mastra AI agent initialization, including defining these tool interfaces. Assume Phi-3 is accessible via `phi3.generate(prompt)` and Lyzr tools are accessible via a `lyzrClient.triggerWorkflow(name, params)`.
```typescript
import { createAgent, createTool } from '@mastra-ai/core';
const phi3Tool = createTool('phi3_analyzer', {
description: 'Analyzes data using the Phi-3 LLM.',
input: { type: 'string', name: 'prompt' },
output: { type: 'string' },
handler: async ({ prompt }) => {
// Simulate Phi-3 API call via Oracle OCI Generative AI
return `Analysis result for: ${prompt} (simulated by Phi-3)`;
},
});
const ragTool = createTool('rag_retriever', {
description: 'Retrieves relevant documents from a vector database.',
input: { type: 'string', name: 'query' },
output: { type: 'array', items: { type: 'string' } },
handler: async ({ query }) => {
// Simulate RAG query to Pinecone/Chroma
return [`Doc related to ${query}`];
},
});
const lyzrWorkflowTool = createTool('lyzr_workflow_trigger', {
description: 'Triggers an automation workflow in Lyzr.',
input: {
type: 'object',
properties: {
workflowName: { type: 'string' },
parameters: { type: 'object' },
},
},
output: { type: 'boolean' },
handler: async ({ workflowName, parameters }) => {
// Simulate Lyzr API call
console.log(`Triggering Lyzr workflow: ${workflowName} with params:`, parameters);
return true;
},
});
const ProductivityOptimizerAgent = createAgent({
id: 'productivity_optimizer',
model: 'phi-3',
tools: [phi3Tool, ragTool, lyzrWorkflowTool],
// ... define initial state and goals
});
export { ProductivityOptimizerAgent };
```Adaptation plan
Keep the source stable, then change the prompt in a predictable order so the next run is easier to evaluate.
Keep stable
Hold the task contract and output shape stable so generated implementations remain comparable.
Tune next
Update libraries, interfaces, and environment assumptions to match the stack you actually run.
Verify after
Test failure handling, edge cases, and any code paths that depend on hidden context or secrets.