Multi-Agent Financial Intelligence System
Enter a stock ticker. Get a structured risk report.
AlphaLens orchestrates 6 specialized AI agents via LangGraph to analyze investment risk from three dimensions β social sentiment, SEC filings, and quantitative indicators β then cross-validates findings and generates a structured risk report.
Built a LangGraph multi-agent system orchestrating 6 specialized AI agents with cyclic graph routing, Pydantic structured outputs, and SEC filing analysis to synthesize financial signals into risk reports, tracked via LangSmith.
- π Cyclic Graph β Truth Checker can loop agents back for deeper investigation when conflicts are detected
- β‘ Parallel Fan-out β 3 data agents run concurrently, fan-in at Truth Checker
- π§© Structured Output β Every agent returns Pydantic-validated JSON schemas
- π§ Smart Ticker Resolution β Natural language input ("apple", "biggest EV company") β resolved stock ticker
- π₯οΈ Streamlit UI β Real-time streaming logs, risk gauge, metric cards, downloadable reports
- π LangSmith Tracing β Full execution visibility in the LangSmith dashboard
- π° $0 Total Cost β All APIs used have generous free tiers
User Query (natural language)
β
βΌ
βββββββββββββββ
β Supervisor β β LLM-based ticker resolution
ββββββββ¬βββββββ
β
βββββββΌββββββ Fan-out (parallel)
βΌ βΌ βΌ
ββββββββββββββββββββββββ
βSenti-ββMarketββ SEC β
βment ββQuant ββAudit-β
βScout ββ ββ or β
ββββ¬ββββββββ¬ββββββββ¬ββββ
β β β
βββββββββΌββββββββ Fan-in
βΌ
ββββββββββββββββ
β Truth Checker| β Cross-validation
ββββββββ¬ββββββββ
β
βββββββ΄ββββββ
βΌ βΌ
Conflicts? No conflicts
β β
βΌ βΌ
Loop back ββββββββββββ
to Super- β Report β
visor βGenerator β
ββββββββββββ
| Agent | Role | Data Source |
|---|---|---|
| π§ Supervisor | Resolves user intent β ticker, dispatches tasks, manages re-investigation rounds | Gemini LLM |
| π Sentiment Scout | Analyzes real-time social media sentiment and news coverage | Grok x_search + Tavily |
| π Market Quant | Computes price action, volatility, Sharpe ratio, RSI-14, volume trends | yfinance |
| βοΈ SEC Auditor | Fetches SEC EDGAR filings (10-K / 20-F), extracts risk factors and red flags | SEC EDGAR + Tavily |
| π Truth Checker | Cross-validates 3 agent reports, identifies contradictions, recommends action | Gemini LLM |
| π Report Generator | Synthesizes all findings into a calibrated 1-10 risk assessment | Gemini LLM |
git clone https://github.com/YOUR_USERNAME/AlphaLens.git
cd AlphaLens
pip install -r requirements.txtCreate a .env file in the project root:
GOOGLE_API_KEY=your_gemini_api_key
XAI_API_KEY=your_grok_api_key
TAVILY_API_KEY=your_tavily_api_key
LANGCHAIN_API_KEY=your_langsmith_api_key # optional, for tracingWeb UI (recommended):
streamlit run app_ui.pyCLI mode:
python main.pyAlphaLens/
βββ app_ui.py # Streamlit web interface
βββ main.py # CLI entry point
βββ requirements.txt
βββ .env # API keys (not committed)
β
βββ app/
β βββ config.py # LLM configuration (Gemini 2.5 Flash)
β βββ state.py # Pydantic schemas + LangGraph state
β βββ graph.py # Graph builder with routing logic
β βββ reporter.py # Markdown report generator
β β
β βββ agents/
β βββ supervisor.py # Task dispatch + ticker resolution
β βββ sentiment.py # X search + Tavily news sentiment
β βββ market_quant.py # yfinance quantitative analysis
β βββ sec_auditor.py # SEC EDGAR filing analysis
β βββ truth_checker.py # Cross-validation + conflict detection
β βββ reporter.py # Final report generation (LLM)
β
βββ tests/
β βββ test_*.py # Unit tests (routing, error handling, Pydantic validation)
β βββ eval/ # 3-layer evaluation framework
β βββ eval_schemas.py # LLM judge Pydantic schemas
β βββ test_agent_quality.py # Layer 1: LLM-as-judge per agent
β βββ test_truth_checker_eval.py # Layer 2: conflict detection accuracy
β βββ test_e2e_regression.py # Layer 3: full pipeline regression
The Streamlit interface provides:
- Sidebar β Query input, API key management, start button
- Status Panel β Real-time streaming logs with color-coded agent output
- Risk Gauge β 1-10 risk score with color-coded progress bar
- Metric Cards β Three-column layout showing Market / Sentiment / SEC data
- Detail Tabs β Full report, agent reasoning chain, conflict analysis
- Download β Export complete Markdown report
AlphaLens includes a 3-layer evaluation framework that measures agent output quality, not just functional correctness.
# Run all eval tests (requires API keys + sufficient Gemini quota)
pytest tests/eval/ -v -s -m slow
# Run unit tests only (no API calls)
pytest tests/ --ignore=tests/eval -v| Layer | What it tests | Method |
|---|---|---|
| Agent Quality | Faithfulness, completeness, reasonableness of each agent's output | LLM-as-judge (real API calls β Gemini scores 1-5) |
| Truth Checker | Conflict detection accuracy on known scenarios | Mock reports + real LLM cross-validation |
| E2E Regression | Full pipeline on representative tickers (AAPL, TSLA) | Pipeline completion + LLM-as-judge on final report |
| Decision | Rationale |
|---|---|
| LangGraph over CrewAI/AutoGen | Native support for cyclic graphs, conditional routing, and parallel fan-out/fan-in |
| Gemini 2.5 Flash | 1M free tokens/day, strong structured output support |
Grok x_search |
Only API with native access to real-time X/Twitter data |
| Pydantic structured output | Type-safe agent communication, no parsing failures |
graph.stream() in UI |
Enables per-node UI updates without threading issues |
| RSI-14 (Wilder method) | Industry-standard momentum indicator, not just simple moving average |
| 20-F support | Handles foreign-listed companies (ADRs like BABA, TSM) |
- Supervisor resolves user input to a ticker via LLM. If unresolvable β graph exits gracefully.
- Fan-out: Sentiment Scout, Market Quant, and SEC Auditor execute in parallel.
- Fan-in: All three reports converge at Truth Checker.
- Truth Checker evaluates consistency:
consistent/minor_conflictsβ proceed to Report Generatorneeds_more_data(round 1 only) β loop back to Supervisor for round 2
- Report Generator synthesizes a calibrated 1β10 risk assessment.
- Market Quant skips re-computation on round 2 (yfinance data doesn't change in minutes).
MIT