How Finance Agent routes questions to the right data sources based on intent
Semantic routing is a key differentiator of Finance Agent. Instead of using simple keyword matching, the agent analyzes question intent to determine which data sources will best answer the question.
The ReasoningPlanner performs combined reasoning + analysis in a single LLM call:
# From agent/rag/reasoning_planner.pyclass ReasoningPlanner: """ Combined question analysis and research reasoning. Single LLM call that: 1. Analyzes the question (extracts entities, intent) 2. Explains the research approach (reasoning) 3. Outputs structured metadata for search planning """ async def create_reasoning_plan( self, question: str, conversation_id: Optional[str] = None ) -> ReasoningResult: # LLM analyzes intent and selects data sources # Returns reasoning + structured metadata pass
Why a single LLM call? Combining reasoning and analysis is faster than two separate calls and produces more coherent results because the reasoning drives the analysis.
Here’s a real example of the routing decision for a complex question:
{ "reasoning": "The user wants a comprehensive analysis of Oracle's balance sheet and debt strategy. This requires detailed financial data from the 10-K filing, including total assets, liabilities, debt structure, maturity schedules, and management's discussion of capital allocation. I'll search the latest 10-K for balance sheet data, debt footnotes, and MD&A sections on capital structure.", "tickers": ["ORCL"], "time_refs": ["latest"], "topic": "balance sheet and debt usage analysis", "question_type": "specific_company", "data_sources": ["10k"], "answer_mode": "detailed", "is_valid": true, "validation_message": "", "confidence": 0.95}
By understanding intent rather than keywords, the agent can retrieve the most relevant information even when questions don’t explicitly mention data sources.
Flexible Querying
Users can ask questions naturally without needing to know which data source contains the answer. The agent figures it out.
Multi-Source Intelligence
For complex questions, the agent can automatically combine multiple sources (hybrid mode) for comprehensive answers.
Context-Aware
The LLM considers conversation history, time periods, and question complexity to make intelligent routing decisions.
Transparent Reasoning
The agent explains its routing decision, making the research approach transparent to users.
Semantic routing also includes question validation:
# Questions marked as invalid (is_valid=false):- Gibberish or greetings- Non-finance questions- Questions about private companies or unavailable data- Too vague to answer
When a question is invalid, the agent responds with a helpful message instead of attempting retrieval.
Synthesis: Combines results into unified comparative analysis
{ "reasoning": "The user wants to compare Apple and Microsoft's revenue growth trends over the last 2 years. I'll search earnings transcripts for both companies across the last 8 quarters to extract revenue figures, growth rates, and segment breakdowns for a comprehensive comparison.", "tickers": ["AAPL", "MSFT"], "time_refs": ["last 2 years"], "topic": "revenue growth comparison", "question_type": "multiple_companies", "data_sources": ["earnings_transcripts"], "answer_mode": "detailed", "is_valid": true, "confidence": 0.95}