Skip to main content

Pattern Agent

Purpose

While the Temporal Agent quantifies what is changing, the Pattern Agent identifies why it matters. It detects behavioral signatures -- recurring cycles, cross-metric relationships, and clinically relevant indicators -- that statistical summaries alone do not surface. A rising stress trend becomes significantly more actionable when recognized as part of a stress-sleep feedback loop rather than reported as an isolated metric.

Value Proposition

  • Semantic labeling -- converts raw statistical observations into named behavioral patterns (e.g., stress_cycle, energy_depletion), enabling targeted interventions
  • Cross-metric reasoning -- identifies compound patterns spanning multiple metrics ("elevated stress co-occurring with sleep disturbance")
  • Early warning detection -- flags concerning trajectories (sustained decline, high-stress periods) before they reach critical thresholds
  • Recovery recognition -- identifies improvement trends and resilience indicators, reinforcing positive behavioral changes
  • Confidence-calibrated output -- reports lower confidence with sparse data rather than overstating conclusions

Processing Model

Pattern detection uses the same dual-mode architecture as temporal analysis:

  1. Algorithmic detection -- deterministic pattern matching based on trend directions, volatility thresholds, and statistical signatures
  2. Agent enhancement -- semantic recognition of behavioral patterns the algorithm cannot capture ("this combination of symptom timing and intensity is consistent with premenstrual symptom clustering")

Pattern Categories

CategoryPatternsSignificance
Behavioralreduced_engagement, activity_decline, routine_disruptionChanges in user interaction frequency, often a proxy for broader lifestyle shifts
Wellbeingstress_cycle, mood_volatility, sleep_mood_connectionCore health patterns linking multiple metrics into compound indicators
Cycle-Relatedpremenstrual_symptoms, cycle_regularity, symptom_clusteringMenstrual cycle patterns that contextualize other metric fluctuations
Recovery Signalsimprovement_trend, stabilization, resilience_indicatorsPositive trajectories indicating effective coping or intervention
Warning Signssustained_decline, high_stress_period, energy_depletionPatterns warranting attention or intervention before escalation

Pipeline Position

The pattern agent executes as Step 2, receiving temporal statistics as input context. Its detected patterns are consumed by the explanation agent when constructing the user-facing narrative.


Example Output

{
"matches": ["stress_cycle", "sleep_mood_connection", "reduced_engagement"],
"confidence": 0.72,
"detectedPatterns": [
{
"name": "stress_cycle",
"series": ["stress_level", "sleep_quality"],
"detail": "Stress peaks midweek consistently, coinciding with elevated sleep disturbance"
},
{
"name": "reduced_engagement",
"series": ["checkins_per_day"],
"detail": "Check-in frequency declined from 5/day to 2/day over the observed period"
}
]
}

Confidence calibration: With fewer than 5 days of data, confidence values are reduced and findings are framed as preliminary observations. This ensures users receive value from limited data without the output overstating its certainty.


Technical Reference

Identifiers

PropertyValue
Registry IDreasoning-engine-pattern-recognition-agent
Profile IDreasoning-pattern-recognition
Codesrc/mastra/agents/reasoning-engine/core/pattern.ts
AccessorgetPatternRecognitionAgent()

Output Schema

{
"matches": ["string[] - Pattern identifiers detected"],
"confidence": "number (0-1) - Overall detection confidence",
"detectedPatterns": [
{
"name": "string - Pattern identifier",
"series": ["string[] - Metrics involved"],
"detail": "string - Description of the detected pattern"
}
]
}

Default Prompt

"You identify meaningful patterns in wellbeing check-in data. Data tracks daily stress levels (1-5), mood states, sleep quality, energy (0-10), and cycle symptoms. You receive temporal stats (trend, volatility) and algorithmic pattern detections. Your role is to add semantic/contextual patterns the algorithm might miss. Return strictly JSON: { matches: string[], confidence: number, detectedPatterns?: Array<{name, series, detail}> }. With sparse data (< 5 days), reduce confidence but still report observable patterns."

Configuration

Update the prompt via Admin tools, SQL, or API targeting the reasoning-pattern-recognition profile.


Next Steps