Skip to content

hhe48203-ctrl/AlphaLens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” AlphaLens

Multi-Agent Financial Intelligence System

Enter a stock ticker. Get a structured risk report.

Python 3.10+ LangGraph Streamlit License: MIT

δΈ­ζ–‡ζ–‡ζ‘£


What is AlphaLens?

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.

Screenshot 2026-02-28 at 19 31 52

Key Highlights

  • πŸ”„ 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
Screenshot 2026-02-28 at 19 34 36

Architecture

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 β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Agents

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

Quick Start

1. Clone & Install

git clone https://github.com/YOUR_USERNAME/AlphaLens.git
cd AlphaLens
pip install -r requirements.txt

2. Configure API Keys

Create 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 tracing

3. Run

Web UI (recommended):

streamlit run app_ui.py

CLI mode:

python main.py

Project Structure

AlphaLens/
β”œβ”€β”€ 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

UI Preview

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

Testing & Evaluation

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

Key Technical Decisions

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)

How the Graph Routing Works

  1. Supervisor resolves user input to a ticker via LLM. If unresolvable β†’ graph exits gracefully.
  2. Fan-out: Sentiment Scout, Market Quant, and SEC Auditor execute in parallel.
  3. Fan-in: All three reports converge at Truth Checker.
  4. Truth Checker evaluates consistency:
    • consistent / minor_conflicts β†’ proceed to Report Generator
    • needs_more_data (round 1 only) β†’ loop back to Supervisor for round 2
  5. Report Generator synthesizes a calibrated 1–10 risk assessment.
  6. Market Quant skips re-computation on round 2 (yfinance data doesn't change in minutes).
Screenshot 2026-02-28 at 19 34 51

License

MIT


Built with LangGraph Β· Gemini Β· Grok Β· Tavily

About

AlphaLens multi-agent financial intelligence system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages