Prompt Content
Extend your Mastra AI project. Implement a workflow where the 'CodeGenerator' agent receives a feature description (e.g., 'a function to sort a list of dictionaries by a key'). It should then use Claude Sonnet 4 to generate the Python function code and corresponding unit tests. Implement a custom tool that allows the agent to 'save_file(filename, content)' to a mock file system. The agent should invoke this tool twice: once for the function, once for the tests. Ensure it follows PEP8 where possible.
```typescript
// Example of a custom tool
const saveFileTool = createTool({
id: 'save_file',
description: 'Saves content to a specified file.',
schema: {
type: 'object',
properties: {
filename: { type: 'string' },
content: { type: 'string' },
},
required: ['filename', 'content'],
},
async execute({ filename, content }) {
console.log(`Saving ${filename}...`);
// Simulate file save, e.g., write to a local temp dir or in-memory map
return `File ${filename} saved successfully.`;
},
});
codeGenerator.addTool(saveFileTool);
// ... Workflow to use the tool
```Try this prompt
Open the workspace to execute this prompt with free credits, or use your own API keys for unlimited usage.
Related Prompts
Explore similar prompts from our community
Usage Tips
Copy the prompt and paste it into your preferred AI tool (Claude, ChatGPT, Gemini)
Customize placeholder values with your specific requirements and context
For best results, provide clear examples and test different variations