Setup Mastra AI Agent with Qwen 3

implementationChallenge

Prompt Content

Initialize a Mastra AI project using TypeScript. Define a simple agent that uses Qwen 3 (via API call) to respond to basic queries. Create a custom tool, `fetchMarketData(category: string)`, that simulates fetching market data (e.g., return a JSON string for 'memory_chips' or 'ai_tools'). Integrate this tool into your Mastra agent. Show your `agent.ts` file setup.

```typescript
import { createAgent, Tool } from 'mastra';
import { QwenClient } from './qwen_client'; // Assume you have a client for Qwen API

const qwenClient = new QwenClient('YOUR_QWEN_API_KEY');

// Define a simulated tool to fetch market data
const fetchMarketData: Tool = {
  name: 'fetchMarketData',
  description: 'Fetches simulated market data for a given category (e.g., memory_chips, ai_tools).',
  inputSchema: { type: 'object', properties: { category: { type: 'string' } }, required: ['category'] },
  async handler(input: { category: string }): Promise<string> {
    if (input.category === 'memory_chips') {
      return JSON.stringify({
        'chip_production_2026': '100 units',
        'datacenter_demand_2026': '70%+ of total_production',
        'new_capacity_until_2027': 'little'
      });
    } else if (input.category === 'ai_tools') {
      return JSON.stringify({
        'adoption_rate': 'growing',
        'challenges': ['cost', 'integration'],
        'opportunities': ['automation', 'creativity']
      });
    } else {
      return JSON.stringify({ 'error': 'Category not found' });
    }
  },
};

// Your task: Create and export your Mastra agent, integrating Qwen 3 and fetchMarketData.
// export const marketAdvisorAgent = createAgent({
//   id: 'marketAdvisor',
//   llm: async (prompt) => qwenClient.generate(prompt),
//   tools: [fetchMarketData],
//   // ... further configuration for memory and behavior
// });
```

Try this prompt

Open the workspace to execute this prompt with free credits, or use your own API keys for unlimited usage.

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