Query Generator Agent
Purpose
Data analysis identifies what is happening; domain knowledge contextualizes why and informs what to do about it. The Query Generator Agent bridges this gap by synthesizing the accumulated pipeline findings -- temporal trends, detected patterns, correlation results -- into focused web search queries designed to retrieve current, relevant external knowledge.
Rather than relying on the LLM's potentially stale training data, this agent generates queries that retrieve up-to-date domain expertise specific to the user's actual analytical findings.
Value Proposition
- Current knowledge retrieval -- searches return up-to-date information rather than depending on training data cutoffs
- Context-aware queries -- searches are tailored to the user's specific patterns and correlations, not generic topic queries
- Priority-ranked output -- generates 2-5 queries ranked by relevance, ensuring the most impactful knowledge is retrieved first
- Transparent rationale -- each query includes an explanation of why it was selected, supporting auditability
Query Design
The agent receives a comprehensive context summary including:
- The user's original objective
- Temporal insights (trends, anomalies, statistical summaries)
- Detected patterns (behavioral signatures, warning indicators)
- Correlation findings (metric relationships with coefficients)
- Current date (for time-sensitive queries)
Query Characteristics
| Principle | Application |
|---|---|
| Time-sensitivity | Incorporates temporal context ("2025-2026", "latest", "recent") for current information |
| Pattern-specificity | References detected patterns directly ("stress-sleep feedback loop intervention strategies") |
| Correlation-awareness | Targets the specific relationships found ("improving qubit coherence times quantum error correction") |
| Search optimization | 5-10 words, statement format, domain-specific terminology |
Priority Scoring
| Priority | Classification | Selection Criteria |
|---|---|---|
| 9-10 | Critical | Directly addresses the user's core analytical objective |
| 7-8 | High | Explores key correlations or detected patterns |
| 5-6 | Medium | Provides supporting contextual knowledge |
| 1-4 | Low | Background or exploratory information |
The domain retrieval tool executes the highest-priority query first.
Example
Given pipeline context:
- Objective: "Help me understand my stress patterns"
- Temporal: stress increasing over 5 days, midweek peaks
- Pattern:
stress_cycledetected,sleep_mood_connectionidentified - Correlation: stress-sleep r=-0.82
Generated queries:
{
"queries": [
{
"query": "stress management techniques reducing work-related stress before bedtime",
"rationale": "Targets the stress-sleep connection (r=-0.82) with evidence-based interventions",
"priority": 10
},
{
"query": "midweek stress peak causes workplace stress accumulation patterns",
"rationale": "Addresses the detected midweek stress pattern for root cause analysis",
"priority": 8
},
{
"query": "sleep quality improvement strategies during high stress periods evidence-based",
"rationale": "Focuses on sleep-specific approaches for periods of elevated stress",
"priority": 7
}
]
}
Pipeline Position
The Query Generator operates inside the Step 4 domain retrieval path. It determines what to search for; the domain retrieval tool then calls Perplexity when configured, assembles synthesized knowledge and citations, or returns local fallback context when search is unavailable. The Content Analyzer agent remains available as a registered helper, but it is not invoked by the committed domain-retrieval workflow step.
Technical Reference
Identifiers
| Property | Value |
|---|---|
| Registry ID | reasoning-engine-query-generator-agent |
| Profile ID | reasoning-query-generator |
| Code | src/mastra/agents/reasoning-engine/core/query-generator.ts |
| Accessor | getQueryGeneratorAgent() |
Output Schema
{
queries: Array<{
query: string, // Web search query text
rationale: string, // Selection rationale
priority: number // Relevance score 1-10
}>
}
Default Prompt
"You are a query generation specialist for a reasoning engine. Analyze the provided context to generate 2-5 focused web search queries that would help retrieve relevant domain knowledge. Consider temporal insights, key correlations, pattern recognition findings, the original analysis objective, and current date context for recency. Return strictly JSON:
{ queries: Array<{ query: string, rationale: string, priority: number }> }. Priority scale: 1 (low) to 10 (critical). Queries should be specific, concise, and optimized for web search engines."
Configuration
Update the prompt via Admin tools, SQL, or API targeting the reasoning-query-generator profile.