Back to Prompt Library
implementation

Real-time Trend Analysis & Storage

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

Linked challenge: Real-time Market Trend Agent

Format
Code-aware
Lines
26
Sections
5
Linked challenge
Real-time Market Trend Agent

Prompt source

Original prompt text with formatting preserved for inspection.

26 lines
5 sections
No variables
1 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');
```

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.