Temporal Analysis
Overview
The Temporal Analysis step examines time-series data to identify trends and compute statistics.
File: steps/temporal.step.ts
What It Does
- Computes statistics for each series (mean, min, max, trend)
- Identifies trends (increasing, decreasing, stable)
- Optionally uses temporal agent for richer summaries
Algorithmic Analysis
const computeStats = (points: Point[]) => {
const values = points.map(p => p.v);
const mean = values.reduce((a, b) => a + b, 0) / values.length;
const min = Math.min(...values);
const max = Math.max(...values);
const first = values[0];
const last = values[values.length - 1];
const trend = last > first ? 'increasing'
: last < first ? 'decreasing'
: 'stable';
return { mean, min, max, trend };
};
Input
Expects series array from preflight step:
{
series: Array<{
id: string,
label?: string,
points: Array<{ t: string, v: number }>
}>
}
Output
{
temporal: {
summary: string, // Human-readable summary
insights: string[], // Key findings
stats: Array<{
id: string,
mean: number,
min: number,
max: number,
trend: string // 'increasing' | 'decreasing' | 'stable'
}>
}
}
Agent Enhancement
When available, the temporal agent provides richer analysis:
const agent = await getTemporalAgent(mastra);
const response = await callAgent(agent, {
series: inputData.series,
objective: inputData.objective
});
// Agent adds narrative summary and deeper insights
Example Output
{
"temporal": {
"summary": "Stress levels show an increasing trend over the past 30 days, rising from an average of 2.5 to 4.1. Mood remains relatively stable with minor fluctuations.",
"insights": [
"Stress increased 64% over the analysis period",
"Weekend stress levels are consistently lower than weekdays",
"Mood shows inverse correlation with stress peaks"
],
"stats": [
{ "id": "stress", "mean": 3.2, "min": 1, "max": 5, "trend": "increasing" },
{ "id": "mood", "mean": 3.8, "min": 2, "max": 5, "trend": "stable" }
]
}
}
Skip Conditions
This step is skipped if:
stepPlanexists and doesn't include'temporal'- No
seriesdata is available