Skip to main content

Correlation Agents

Purpose

Correlation analysis answers a fundamental analytical question: do these metrics move together? The step computes Pearson correlation coefficients for every pair of numeric datasets and produces interpretations that translate statistical relationships into actionable observations.

This is decomposed into two agents because correlation analysis requires two fundamentally different capabilities:

  1. Data preparation -- real-world datasets contain mixed types, missing values, and misaligned indices; these must be cleaned before mathematical computation is valid
  2. Interpretation -- a coefficient of -0.82 requires contextual translation for it to inform decisions

Value Proposition

  • Quantified relationships -- every cross-metric claim is backed by a computed coefficient, not speculation
  • Cascade identification -- detects chain effects (e.g., stress -> sleep -> energy) that reveal high-leverage intervention points
  • Data quality assurance -- the normalizer ensures mathematical validity before computation
  • Actionable output -- the analysis agent produces specific next steps, not abstract observations

Two-Agent Architecture

  1. Normalizer -- extracts numeric values, drops invalid entries ("N/A", null), and aligns arrays by index to produce clean datasets suitable for mathematical correlation
  2. Compute (deterministic, not an agent) -- calculates Pearson correlation coefficients for all dataset pairs
  3. Analysis -- interprets coefficients in context, classifying relationship strength and direction, and producing actionable recommendations

The Normalizer Agent

Responsibilities

  • Extract numeric values from mixed-type arrays
  • Drop non-numeric entries while maintaining alignment across datasets
  • Preserve dataset ordering
  • Report normalization outcomes (values dropped, alignment changes)

Example Transformation

Input (heterogeneous):

{
"datasets": [
{ "id": "stress", "data": [3.5, 4.0, "N/A", 3.2, 4.5] },
{ "id": "sleep", "data": [7, 6, 5, 7, 5] }
]
}

Output (normalized):

{
"normalized": [
{ "id": "stress", "values": [3.5, 4.0, 3.2, 4.5], "dimensions": 1 },
{ "id": "sleep", "values": [7, 6, 7, 5], "dimensions": 1 }
],
"summary": "Extracted 2 series with 4 aligned values each (dropped 1 non-numeric)"
}

Technical Details

PropertyValue
Registry IDreasoning-engine-correlation-normalizer-agent
Profile IDcorrelation-tool-normalizer
Codesrc/mastra/agents/reasoning-engine/correlation/normalizer.ts
AccessorgetCorrelationNormalizerAgent()

The Analysis Agent

Responsibilities

Interprets computed correlation coefficients, classifies relationship strength, identifies cascade effects, and produces up to three actionable recommendations.

Interpretation Scale

Coefficient (r)ClassificationTypical Interpretation
0.7 to 1.0Strong positiveMetrics move together consistently
0.4 to 0.7Moderate positiveNotable co-movement
0.0 to 0.4Weak positiveLimited relationship
-0.4 to 0.0Weak negativeSlight inverse tendency
-0.7 to -0.4Moderate negativeNotable inverse co-movement
-1.0 to -0.7Strong negativeStrongly inverse -- improving one metric may improve the other

Example Output

{
"summary": "Strong negative correlation (r=-0.82) between stress and sleep quality indicates that elevated stress significantly disrupts sleep. Energy shows strong positive correlation (r=0.71) with sleep quality.",
"insights": [
"Elevated stress days consistently correspond to reduced sleep quality",
"Improved sleep is a strong predictor of higher energy the following day",
"Addressing stress may produce cascading benefits: reduced stress -> improved sleep -> higher energy"
],
"nextSteps": [
"Monitor the impact of stress management interventions on sleep quality",
"Prioritize sleep hygiene practices during high-stress periods",
"Track energy levels as sleep quality improves to validate the cascade hypothesis"
]
}

Technical Details

PropertyValue
Registry IDreasoning-engine-correlation-analysis-agent
Profile IDcorrelation-tool-analysis
Codesrc/mastra/agents/reasoning-engine/correlation/analysis.ts
AccessorgetCorrelationAnalysisAgent()

Pipeline Position

The correlation step executes as Step 3. It requires a minimum of 2 numeric datasets to compute meaningful correlations. When only one metric is available, the orchestrator typically bypasses this step.


Next Steps