Skip to main content

Reasoning Engine Agents

Agent Architecture

The Reasoning Engine delegates analytical responsibilities across a team of specialized agents, each scoped to a single analytical discipline. This decomposition follows the principle that focused models with domain-specific prompts produce higher-quality output than general-purpose models tasked with the full analytical spectrum.

The specialization enables two architectural advantages:

  1. Precision through focus -- each agent's system prompt is tuned exclusively for its analytical domain, yielding more accurate and consistent results than a monolithic approach.
  2. Independent configurability -- prompt tuning, model selection, and temperature adjustments for one agent (e.g., improving narrative quality in the explanation agent) have zero impact on the statistical accuracy of upstream agents.

Collaboration Model

The agents execute in a defined sequence, where each stage builds upon the accumulated output of prior stages. The pipeline is organized into four functional phases:

Execution Flow

  1. The Step Orchestrator evaluates the user's objective and the available data dimensions to determine which pipeline steps are relevant, producing an execution plan that may skip unnecessary stages when enableStepOrchestration is enabled.

  2. The Temporal Agent performs statistical computation across all time-series inputs: means, extremes, trend direction, and volatility measures. Its output provides the quantitative foundation for all downstream analysis.

  3. The Pattern Agent combines algorithmic detection with semantic analysis to identify behavioral signatures -- recurring cycles, cross-metric correlations, and warning indicators that statistical summaries alone do not surface.

  4. The Normalizer and Analysis agents handle correlation as a two-stage process. The normalizer cleans and aligns heterogeneous datasets into comparable numeric arrays; after mathematical computation of Pearson coefficients, the analysis agent interprets the relationships in context.

  5. The Query Generator synthesizes the accumulated findings into targeted web search queries. The committed domain retrieval tool then calls Perplexity when configured and assembles knowledge items, with a local fallback when external retrieval is unavailable. The Content Analyzer remains a registered helper, but it is not invoked by the current domain-retrieval workflow step.

  6. The Explanation Agent synthesizes all prior outputs -- temporal statistics, detected patterns, correlation interpretations, and domain knowledge -- into a structured narrative with key findings and confidence assessment.

  7. The Validation Agent performs systematic fact-checking, verifying every claim in the narrative against the underlying data. Inconsistencies, unsupported claims, and missing caveats are flagged before the output leaves the engine.


Agent Profiles

Functional Summary

AgentResponsibilityValue Proposition
OrchestratorLegacy/planning agent available in the artifact loaderSupports planning/tool orchestration use cases outside the committed core workflow
Step OrchestratorDetermines which analysis steps to execute based on objective and data shapeReduces execution time and API cost by eliminating unnecessary stages
TemporalComputes time-series statistics and identifies trend directionsProvides the quantitative foundation all downstream agents depend on
PatternDetects behavioral signatures across metricsSurfaces recurring cycles and warning indicators beyond statistical summaries
NormalizerCleans and aligns heterogeneous datasets for correlationEnsures mathematical validity of cross-metric comparisons
Correlation AnalysisInterprets computed correlation coefficientsTranslates statistical relationships into actionable observations
Domain RetrievalProvides domain-knowledge synthesis when used directlyAvailable as a registered agent for retrieval-style consumers
Query GeneratorSynthesizes analysis context into targeted search queriesRetrieves domain knowledge specific to the user's detected patterns
Content AnalyzerRegistered helper for extracting insights from retrieved web contentAvailable to consumers, but not invoked by the committed workflow step
ExplanationProduces the user-facing analytical narrativeSynthesizes all findings into a coherent, contextual explanation
ValidationFact-checks every claim against source dataPrevents hallucinated or inconsistent claims from reaching the user
Phrasing HelperRephrases existing user-facing text without changing meaningAvailable to outer workflows; not a committed core workflow step

Technical Identifiers

AgentRegistry IDProfile IDCode
Orchestratorreasoning-engine-orchestrator-agentreasoning-orchestratorcore/orchestrator.ts
Step Orchestratorreasoning-engine-step-orchestrator-agentreasoning-step-orchestratorcore/step-orchestrator.ts
Temporalreasoning-engine-temporal-summary-agentreasoning-temporal-summarycore/temporal.ts
Patternreasoning-engine-pattern-recognition-agentreasoning-pattern-recognitioncore/pattern.ts
Normalizerreasoning-engine-correlation-normalizer-agentcorrelation-tool-normalizercorrelation/normalizer.ts
Correlation Analysisreasoning-engine-correlation-analysis-agentcorrelation-tool-analysiscorrelation/analysis.ts
Domain Retrievalreasoning-engine-domain-retrieval-agentreasoning-domain-retrievalcore/domain.ts
Query Generatorreasoning-engine-query-generator-agentreasoning-query-generatorcore/query-generator.ts
Content Analyzerreasoning-engine-content-analyzer-agentreasoning-content-analyzercore/content-analyzer.ts
Explanationreasoning-engine-explanation-agentreasoning-explanationcore/explanation.ts
Validationreasoning-engine-validation-agentreasoning-validationcore/validation.ts
Phrasing Helperreasoning-engine-phrasing-agentreasoning-phrasingcore/phrasing.ts

All agents reside under src/mastra/agents/reasoning-engine/ and share the REASONING-ENGINE- scope prefix through the common factory in correlation/common.ts.


Detailed Agent Documentation


Design Principles

Dual-Mode Processing

Every analysis step supports two complementary processing modes:

  • Algorithmic processing executes first -- deterministic computation producing reproducible, verifiable results (statistical measures, correlation coefficients, trend detection).
  • Agent enhancement layers on top -- AI-powered interpretation that adds semantic understanding the algorithms cannot provide.

This architecture guarantees a baseline result even when an agent is unavailable or returns an error. The agents improve output quality, but the pipeline does not depend on them for structural integrity.

Fail-Safe Pipeline

When any agent fails or returns invalid output:

  • The pipeline continues with degraded results rather than terminating
  • The failed step is logged, and downstream agents operate on the available data
  • The validation agent flags the gap so output consumers are aware of reduced coverage

Database-Backed Configuration

Every agent's system prompt is stored in the Core.AgentProfiles table:

  • No redeployment required to modify agent behavior -- update the prompt via Admin tools or SQL
  • Version history is maintained -- every prompt change creates a new version with the previous version preserved for audit
  • Profile hash invalidation -- the agent cache rebuilds automatically when a prompt changes
// Runtime prompt loading
const profile = await agentProfilesService.getCurrent('reasoning-explanation');
if (profile) {
systemPrompt = profile.systemPrompt ?? DEFAULT_PROMPT;
llmConfig = { ...defaultConfig, ...profile.llmOverrides };
}

Per-Agent Model Selection

Each agent can target a different LLM deployment, enabling cost and quality optimization per analytical stage:

Agent RoleRecommended ModelRationale
Temporal, Correlation, Step OrchestratorGPT-4o-miniStatistical and classification tasks; lower latency and cost
Pattern, Domain, ValidationGPT-4oBenefits from stronger reasoning and knowledge
ExplanationGPT-4oNarrative quality is user-facing; justifies the additional cost

Next Steps