A production-style agentic AI trading system built with Google ADK and Gemini on Vertex AI.
The system demonstrates how AI agents can safely automate financial workflows by combining deterministic quantitative models, multi-agent adversarial reasoning, a risk engine that can override AI decisions, paper trading, and a real-time React dashboard.
This is a workflow automation system, not a chatbot.
| Page | What It Shows |
|---|---|
Dashboard (/) |
Chat interface, market regime card, portfolio summary, backtest results, dividend scanner, Nifty 50 signal board |
Market (/market) |
Interactive candlestick / line chart with SMA overlays, volume bars, RSI, period & interval selectors |
Analyze (/analyze) |
Full 7-step AI pipeline: Regime β Scan β Dividend Health β Debate β Trade/Risk β Portfolio β Autonomous Flow |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React + Tailwind Frontend β
β Dashboard Β· Market Chart Β· Analyze Pipeline Β· Chat β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β REST API
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββ
β FastAPI Server (server/app.py) β
β β
β /api/chat βββΊ ADK root_agent (LLM-driven delegation) β
β /api/analyze βββΊ Server-orchestrated 7-step pipeline β
β /api/market, /api/regime, /api/portfolio, /api/signals, ... β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββ
β Google ADK Agent Layer β
β β
β root_agent (trading_assistant) β
β βββ regime_analyst β analyze_regime() β
β βββ stock_scanner β scan_watchlist / get_analysis β
β βββ dividend_scanner β assess_dividend_health() β
β βββ trade_debate_judge β Bull vs Bear adversarial debate β
β β βββ bull_advocate β
β β βββ bear_advocate β
β βββ trade_executor β check_risk() + paper trading β
β βββ portfolio_manager β portfolio CRUD β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββ
β Deterministic Python Layer β
β β
β Risk Engine Β· Technical Indicators Β· Regime Classifier β
β Position Sizing Β· ATR Stop-Loss Β· Portfolio Persistence β
β yfinance (live NSE data) Β· News Fetcher β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key design principle: The LLM reasons and orchestrates; Python computes and enforces. The AI cannot override mathematical risk rules.
When you click Run Analysis on the Analyze page, the server orchestrates these steps programmatically (no LLM delegation failures):
| Step | Agent | What It Does |
|---|---|---|
| 1 | Regime Analyst | Classifies market as BULL / SIDEWAYS / BEAR using 50-DMA, 200-DMA, slope, momentum |
| 2 | Stock Scanner | Fetches live OHLCV, computes RSI, ATR, 50-DMA, breakout detection, volume ratio |
| 3 | Dividend Scanner | Assesses dividend health (HEALTHY / CAUTION / DESPERATE) via earnings growth, payout ratio, PE, ROE |
| 4 | Debate (Bull vs Bear) | LLM produces BULL_THESIS + BEAR_THESIS + CIO_DECISION in one pass with embedded market data |
| 5 | Trade Executor | Deterministic risk engine: entry/stop/target calc, position sizing, kill rules. Or HOLD with no trade. |
| 6 | Portfolio Manager | Reports cash, open positions, portfolio value |
| 7 | Autonomous Flow | Synthesis summary of all completed steps |
The debate is the core innovation. Instead of a single LLM opinion, the system generates adversarial arguments:
- Bull Advocate β strongest possible case FOR the trade (quant strengths, sentiment strengths, catalysts, risk rebuttal)
- Bear Advocate β strongest possible case AGAINST (quant weaknesses, sentiment risks, downside catalysts, bull case flaws)
- CIO Decision β final verdict (BUY / SELL / HOLD) with entry, stop-loss, target, risk-reward ratio, conviction score
Both sides cite real data (RSI, 50-DMA, volume, news headlines). The CIO weighs both and delivers a data-backed verdict.
All risk calculations are deterministic Python β the LLM cannot override them.
| Rule | Implementation |
|---|---|
| Stop-Loss | Entry β (1.5 Γ ATR) for BUY; Entry + (1.5 Γ ATR) for SELL |
| Position Size | floor((Portfolio Γ 0.01) / RiskPerShare) β 1% risk per trade |
| Minimum R:R | β₯ 1.5:1 reward-to-risk ratio |
| Conviction Gate | Trades below 0.4 conviction are killed |
| Regime Filter | BEAR regime trades face stricter scrutiny |
| Volatility Cap | Excessive ATR-to-price ratio triggers rejection |
| Max Exposure | Portfolio-level position limits |
The risk engine can REJECT trades that pass the debate β risk rules act as a hard safety layer.
| Layer | Technology |
|---|---|
| AI | Google ADK, Gemini (via Vertex AI or API key) |
| Backend | Python 3.11, FastAPI, uvicorn |
| Frontend | React 19, TypeScript, Vite, Tailwind CSS 4, Recharts, shadcn/ui |
| Data | yfinance (live NSE OHLCV + news), Yahoo Finance |
| Storage | JSON file-based portfolio (server/memory/portfolio.json) |
At startup, _pick_available_model() probes models in order and uses the first that responds:
gemini-3-flash-previewgemini-2.5-flashgemini-2.0-flashgemini-2.5-pro
| Endpoint | Method | Description |
|---|---|---|
/api/health |
GET | Health check |
/api/chat |
POST | Send message to ADK root agent |
/api/analyze |
POST | Server-orchestrated 7-step analysis pipeline |
/api/regime |
GET | Current market regime |
/api/market |
GET | OHLCV + indicators for chart (ticker, period, interval) |
/api/portfolio |
GET | Portfolio summary |
/api/portfolio/performance |
GET | Portfolio performance metrics |
/api/portfolio/refresh |
POST | Refresh position prices |
/api/portfolio/reset |
POST | Reset to initial INR 10,00,000 |
/api/backtest/oversold-summary |
GET | Oversold bounce backtest results |
/api/backtest/oversold-best |
GET | Best oversold trades |
/api/dividend/top |
GET | Top dividend stocks |
/api/signals/nifty50 |
GET | Nifty 50 signal board |
GDG_HACKFEST/
βββ server/
β βββ app.py # FastAPI backend (~970 lines)
β
βββ trading_agents/ # Google ADK agent package
β βββ __init__.py
β βββ agent.py # root_agent β coordinator
β βββ config.py # model fallback, risk rules, watchlist
β βββ models.py # Pydantic data models
β βββ utils.py # shared helpers (IST, ticker normalization)
β βββ risk_engine.py # deterministic risk engine (290 lines)
β βββ regime_agent.py # market regime classifier
β βββ scanner_agent.py # breakout + stock scanner
β βββ debate_agent.py # bull/bear/CIO debate system
β βββ trade_agent.py # trade execution + risk check
β βββ portfolio_agent.py # portfolio queries
β βββ dividend_agent.py # dividend scanning
β βββ tools/
β βββ market_data.py # live NSE data (yfinance)
β βββ news_data.py # stock news fetcher
β βββ technical.py # indicators (DMA, ATR, RSI, breakout)
β βββ fundamental_data.py # fundamentals + dividend health
β βββ dividend_data.py # MoneyControl dividend scraper
β βββ paper_trading.py # paper trade execution
β βββ portfolio.py # portfolio persistence (JSON)
β βββ risk_tool.py # ADK-compatible check_risk wrapper
β βββ backtest_oversold.py # oversold bounce backtest
β βββ backtest_dividend.py # dividend momentum backtest
β βββ autonomous_trading.py # autonomous trading flow
β βββ market_status.py # market open/close check
β βββ demo_tools.py # demo helpers
β
βββ frontend/ # React + Vite + Tailwind
β βββ src/
β β βββ App.tsx # Router setup
β β βββ api.ts # API client
β β βββ pages/
β β β βββ Home.tsx # Dashboard (chat + widgets)
β β β βββ Market.tsx # Interactive chart page
β β β βββ Analyze.tsx # 7-step AI pipeline page
β β βββ components/
β β βββ Layout.tsx # App shell + nav
β β βββ Chat.tsx # Chat interface
β β βββ MarketChart.tsx # Candlestick/line chart (SVG + Recharts)
β β βββ MarketRegime.tsx # Regime status card
β β βββ Portfolio.tsx # Portfolio summary
β β βββ DecisionCard.tsx # Trade decision display
β β βββ DebatePanel.tsx # Bull vs Bear debate UI
β β βββ PipelineSteps.tsx # 7-step pipeline visualizer
β β βββ SignalBoard.tsx # Nifty 50 signals
β β βββ BacktestSummary.tsx # Backtest results
β β βββ DividendTop.tsx # Top dividend stocks
β βββ package.json
β βββ vite.config.ts
β
βββ tests/ # Test suite
βββ _archive/ # Archived legacy code
βββ docs/ # Architecture docs
βββ memory/ # Portfolio JSON persistence
βββ requirements.txt # Python dependencies
βββ README.md
| # | Symbol | Company |
|---|---|---|
| 1 | RELIANCE.NS | Reliance Industries |
| 2 | TCS.NS | Tata Consultancy Services |
| 3 | HDFCBANK.NS | HDFC Bank |
| 4 | INFY.NS | Infosys |
| 5 | ICICIBANK.NS | ICICI Bank |
| 6 | HINDUNILVR.NS | Hindustan Unilever |
| 7 | ITC.NS | ITC Limited |
| 8 | SBIN.NS | State Bank of India |
| 9 | BHARTIARTL.NS | Bharti Airtel |
| 10 | KOTAKBANK.NS | Kotak Mahindra Bank |
| 11 | LT.NS | Larsen & Toubro |
| 12 | AXISBANK.NS | Axis Bank |
| 13 | ASIANPAINT.NS | Asian Paints |
| 14 | MARUTI.NS | Maruti Suzuki |
| 15 | TITAN.NS | Titan Company |
| 16 | SUNPHARMA.NS | Sun Pharma |
| 17 | BAJFINANCE.NS | Bajaj Finance |
| 18 | WIPRO.NS | Wipro |
| 19 | HCLTECH.NS | HCL Technologies |
| 20 | TATAMOTORS.NS | Tata Motors |
git clone <repo-url>
cd GDG_HACKFEST
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
pip install -r requirements.txtCreate trading_agents/.env:
# Option A: Vertex AI (recommended)
GOOGLE_GENAI_USE_VERTEXAI=TRUE
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
# Option B: API Key
# GOOGLE_API_KEY=your-api-keycd frontend
npm install
npm run build
cd ..python -m uvicorn server.app:app --host 0.0.0.0 --port 8000Open http://localhost:8000 in your browser.
cd trading_agents
adk web| Prompt | What Happens |
|---|---|
| "What is the current market regime?" | Fetches live Nifty 50 data, classifies BULL/SIDEWAYS/BEAR |
| "Scan for breakout stocks" | Scans watchlist for 20-day breakout candidates |
| "Analyze RELIANCE" | Full 7-step pipeline: regime β scan β dividend β debate β risk β portfolio |
| "Should I buy TCS?" | Bull vs Bear debate with BUY/SELL/HOLD verdict |
| "Show my portfolio" | Cash, positions, P&L, trade history |
| "Reset portfolio" | Resets to INR 10,00,000 |
| Property | Implementation |
|---|---|
| Autonomous reasoning | LLM decides which sub-agent to delegate to and how to interpret results |
| Tool use | 15+ deterministic tool functions registered with ADK |
| Multi-agent orchestration | Root agent coordinates 6 sub-agents (8 total including debate advocates) |
| Adversarial reasoning | Bull and Bear agents debate from opposing perspectives; CIO delivers verdict |
| Deterministic safety | Risk engine is pure Python β LLM cannot override math |
| Memory | Portfolio state persists to disk across sessions |
| Explainability | Every decision includes data, reasoning, source, and timestamp |
| Observability | React dashboard shows pipeline steps, debate points, chart, and trade details in real time |
See LICENSE.
Built for GDG Chennai HackFest 2026 β Autonomous AI Agents solving real workflows.