Back to Prompt Library
implementation

Setup Mastra AI Agent with Qwen 3

Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.

Linked challenge: AI Market Trend & Strategy Advisor

Format
Code-aware
Lines
36
Sections
5
Linked challenge
AI Market Trend & Strategy Advisor

Prompt source

Original prompt text with formatting preserved for inspection.

36 lines
5 sections
No variables
1 code block
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
// });
```

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.