Skip to main content
Loading navigation
Back to prompt library

Real-time Trend Analysis & Storage

Linked challenge: Real-time Market Trend Agent

Prompt source

implementation26 lines5 sectionsNo variables1 code block
Implement a continuous loop or event listener where the `MarketMonitorAgent` is triggered by new simulated DAU data for 'Threads' and 'X'. For each update:
1. The agent should use `fetchDauData` to get the latest numbers.
2. Analyze the data using `Mistral Large 2` to determine if a 'positive_shift', 'negative_shift', or 'stable' trend exists.
3. If a significant shift is detected, use `storeTrendInPinecone` to save the trend and its explanation to Pinecone. This should relate to the `TrendDetection` evaluation task.

```typescript
// ... (previous MarketMonitorAgent setup)

async function analyzePlatformTrend(platform: string) {
  console.log(`Running analysis for ${platform}...`);
  const result = await MarketMonitorAgent.run({
    prompt: `Analyze the latest DAU data for ${platform} and identify any significant trends or shifts. Use the fetchDauData tool. If a significant trend is found, store it in Pinecone using storeTrendInPinecone.`, 
    context: {
      platform: platform // Provide context for the agent to use in its tools
    },
    // Mastra AI can allow specifying a 'goal' or 'workflow'
  });

  console.log(`Analysis for ${platform} completed:`, result);
  // You would extract the trend_change, magnitude, explanation from result.response
  // and log it or pass it to an evaluation function.
}

// Simulate new data arrival for evaluation
// In a real system, this would be an event or scheduled task.
// For evaluation, you might call analyzePlatformTrend with specific simulated data points.
// Example of a simulated data stream trigger:
// analyzePlatformTrend('Threads');
// analyzePlatformTrend('X');
```