AI-powered financial intelligence for Canadian investors.
WealthMind is a multi-agent system that monitors a client's full financial profile β TFSA, RRSP, FHSA, non-registered, margin, crypto, and chequing β and surfaces ranked, dollar-quantified insights in real time. Five specialist LLM agents run in parallel via LangGraph, each analyzing a different financial domain. A synthesis layer merges their findings into plain-language recommendations delivered through "Welly," a conversational AI interface.
No trades are executed. No money moves. The system surfaces intelligence. The human acts.
- What It Does
- System Architecture
- LangGraph Agent Architecture
- Agent Workflow Pipeline
- Chat Pipeline (SSE Streaming)
- Cross-Referral System
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- License
WealthMind ingests a Canadian investor's complete financial picture and answers one question: "What should I do with my money right now?"
The system:
- Runs 5 specialist agents in parallel against live portfolio data and CRA tax rules
- Calculates dollar-quantified impact for every recommendation (e.g. "$4,297 RRSP tax refund")
- Ranks findings by urgency and dollar impact
- Delivers insights through Welly, a conversational AI that streams responses via SSE
- Supports what-if scenario analysis (e.g. "What if I contribute $5,000 to my RRSP?")
- Provides a full portfolio management dashboard with live prices via yfinance
- Simulates buy/sell/deposit/withdraw/transfer/currency exchange operations
- Tracks CRA contribution room for TFSA, RRSP, and FHSA with deadline awareness
- Computes capital gains tax exposure on non-registered positions in real time
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WEALTHMIND β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ€
β FRONTEND β BACKEND β
β Next.js 16 β FastAPI β
β β β
β ββββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββββββ β
β β Dashboard β β β API Routes β β
β β Portfolio ββββΌβββ€ /portfolio /accounts β β
β β Accounts β β β /trade /markets β β
β β Markets β β β /chat /analyze β β
β β History β β β /fx /health β β
β ββββββββββββββββββββββββ β ββββββββββββββββ¬ββββββββββββββββββββ β
β β β β
β ββββββββββββββββββββββββ β ββββββββββββββββΌββββββββββββββββββββ β
β β Welly Chat Panel ββββΌβββ€ LangGraph Engine β β
β β (SSE Streaming) β β β Supervisor β Synthesis β β
β β Onboarding β β β β HITL β Stream β β
β ββββββββββββββββββββββββ β ββββββββββββββββ¬ββββββββββββββββββββ β
β β β β
β ββββββββββββββββββββββββ β ββββββββββββββββΌββββββββββββββββββββ β
β β Auth.js β β β Services Layer β β
β β Google OAuth β β β Portfolio Β· Prices Β· Trading β β
β ββββββββββββββββββββββββ β β FX Β· CRA Rules β β
β β ββββββββββββββββ¬ββββββββββββββββββββ β
β β β β
β β ββββββββββββββββΌββββββββββββββββββββ β
β β β SQLite + aiosqlite β β
β β β Users Β· Accounts Β· Positions β β
β β β Transactions Β· Conversations β β
β β ββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
External: Anthropic API Β· yfinance Β· Google OAuth
βββββββββββββββ
β START β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β SUPERVISOR β
ββββββββ¬βββββββ
β
ββββββββββββ¬βββββββββββΌβββββββββββ¬βββββββββββ
β β β β β
ββββββββΌββββββ ββββΌββββββ βββΌβββββββ βββΌβββββββ βββΌβββββββ
β Allocation β β Tax β β TLH β β Rate β β Timing β
β Agent β β Agent β β Agent β β Arb. β β Agent β
ββββββββ¬ββββββ ββββ¬ββββββ βββ¬βββββββ βββ¬βββββββ βββ¬βββββββ
β β β β β
ββββββββββββ΄ββββββββββ΄βββββββββββ΄βββββββββββ
β
(asyncio.gather β all run in parallel)
β
ββββββββΌβββββββ
β MERGE β
β domain_ β
β findings β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β SYNTHESIS β
β Deduplicate β
β Rank by $ β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β HITL β
β Human-in- β
β the-Loop β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β END β
βββββββββββββββ
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT β RESPONSIBILITY β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Allocation β TFSA/RRSP/FHSA contribution room analysis β
β β Cash placement optimization β
β β Registered account gap detection β
β β Idle cash identification β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Tax β Capital gains tax consequences of trades β
β Implications β Tax exposure on unrealized gains β
β β CRA inclusion rate calculations β
β β Marginal rate impact analysis β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β TLH β Tax-loss harvesting opportunities β
β (Harvesting) β Unrealized losses eligible for harvest β
β β Superficial loss rule awareness (30-day) β
β β Wash sale avoidance β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Rate β Margin interest vs cash savings rate β
β Arbitrage β Capital inefficiency detection β
β β Debt cost vs opportunity cost analysis β
β β 6.2% margin vs 2.5% chequing arbitrage β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Timing β RRSP contribution deadline awareness β
β β Tax-year-end opportunities β
β β Time-sensitive financial actions β
β β Seasonal optimization windows β
ββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Client Request
β
βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Load Live ββββββΆβ Build Graph ββββββΆβ Supervisor β
β Portfolio β β State β β Node β
β Snapshot β β β β β
βββββββββββββββββββ βββββββββββββββββββ ββββββββββ¬βββββββββ
β
ββββββββββββ¬βββββββββββ¬ββββββββββΌββββββββββ¬
β β β β β
ββββββΌβββββ βββββΌββββ βββββΌββββ βββββΌββββ βββββΌββββ
β Alloc- β β Tax β β TLH β β Rate β βTiming β
β ation β β β β β β Arb. β β β
ββββββ¬βββββ βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ
β β β β β
β Each agent: β β β
β 1. Load prompt β β β
β 2. Inject data β β β
β 3. Call Claude β β β
β 4. Parse JSON β β β
ββββββββββββ΄βββββββββββ΄ββββββββββ΄βββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββ
β Merge domain_findings β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββ
β Synthesis Node β
β β’ Validate required keys β
β β’ Deduplicate by title β
β β’ Rank by dollar_impact DESC β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββ
β HITL Node β
β β’ Status: "surfaced" β
β β’ Insights ready for human review β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββ
β WebSocket Broadcast β
β β’ Push ranked insights to frontend β
βββββββββββββββββββββββββββββββββββββββββββββββ
User Message
β
βΌ
βββββββββββββββββββββββ
β Conversation βββββ SSE: "routing" βββββββββββββββββΆ Frontend
β Router β
β (Claude call) β
β β
β Decides: β
β β’ which agents β
β β’ can answer from β
β context? β
ββββββββββββ¬βββββββββββ
β
ββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Can answer from context? β
ββββββββββββ¬ββββββββββββββββββββββββ¬βββββββββββ
β YES β NO
βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββββββββββββ
β Return direct β β SSE: "agent_start" (ΓN) β
β response β β SSE: "handoff" (ΓN) β
β SSE: "response" β βββββββββββββββ¬ββββββββββββββ
ββββββββββββββββββββ β
βΌ
βββββββββββββββββββββββββββββ
β Run agents in parallel β
β (asyncio.gather) β
βββββββββββββββ¬ββββββββββββββ
β
SSE: "agent_complete" (ΓN)
β
βββββββββββββββΌββββββββββββββ
β Synthesize Response β
β (Claude call) β
β β’ Enforces <60 words β
β β’ Dollar figures only β
β β’ No process talk β
βββββββββββββββ¬ββββββββββββββ
β
SSE: "response"
β
βββββββββββββββΌββββββββββββββ
β Cross-Referral Check β
β (up to 2 auto-refs) β
β Evaluates: would another β
β agent add value? β
βββββββββββββββ¬ββββββββββββββ
β
SSE: "handoff" + "auto_referral_response"
β
βββββββββββββββΌββββββββββββββ
β Follow-Up Chips β
β (2β3 suggestions) β
β with real $ figures β
βββββββββββββββ¬ββββββββββββββ
β
SSE: "follow_ups"
SSE: "done"
After every agent response, WealthMind evaluates whether additional agents should automatically run:
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Source Agent β Candidate Agents to Auto-Invoke β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Allocation β Timing, Rate Arbitrage β
β Tax Implic. β TLH, Timing β
β TLH β Tax Implications, Timing β
β Rate Arbitrage β Allocation β
β Timing β Allocation, Tax Implications β
β Direct Response β All 5 agents (evaluated individually) β
ββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Max auto-referrals per turn: 2. Each candidate is evaluated by Claude for relevance before invocation.
| Technology | Purpose |
|---|---|
| Next.js 16 | React framework with App Router |
| React 19 | UI library |
| TypeScript | Type safety |
| Tailwind CSS 4 | Utility-first styling |
| shadcn/ui | UI component primitives (Radix UI) |
| Recharts | Portfolio charts and visualizations |
| Lucide React | Icon system |
| Auth.js (NextAuth) | Google OAuth authentication |
| SSE (EventSource) | Real-time chat streaming |
| Technology | Purpose |
|---|---|
| FastAPI | Async Python web framework |
| LangGraph | Multi-agent orchestration graph |
| LangChain Anthropic | Claude API integration |
| Claude Sonnet 4.6 | LLM for all agent reasoning |
| SQLAlchemy 2.0 | Async ORM (aiosqlite driver) |
| SQLite | Database (zero-config, file-based) |
| yfinance | Live stock prices and market data |
| SSE-Starlette | Server-Sent Events for chat streaming |
| Uvicorn | ASGI server |
| Pydantic | Request/response validation |
| Technology | Purpose |
|---|---|
| Railway | Cloud deployment (both services) |
| Nixpacks | Build system |
| WebSockets | Real-time insight broadcasting |
| JWT (demo) | Stateless auth token passing |
wealthmind/
βββ backend/
β βββ main.py # FastAPI app, CORS, JWT middleware, lifespan
β βββ database.py # SQLAlchemy models, async engine, demo seeder
β βββ api/
β β βββ routes.py # All REST + SSE + WebSocket endpoints
β βββ graph/
β β βββ graph.py # LangGraph compilation (supervisor β synthesis β HITL)
β β βββ agents.py # 5 domain agent functions (Claude calls)
β β βββ router.py # Conversation router (intent classification)
β β βββ synthesizer.py # Response synthesis + cross-referral + follow-up chips
β β βββ proactive.py # Proactive greeting generation
β β βββ state.py # GraphState TypedDict
β β βββ conversation_state.py # ConversationState TypedDict
β βββ services/
β β βββ portfolio.py # Portfolio snapshots, tax exposure calculations
β β βββ prices.py # yfinance wrapper with 60s cache
β β βββ trading.py # Simulated trade execution (buy/sell/deposit/withdraw/fx)
β βββ prompts/
β β βββ allocation.txt # Allocation agent system prompt
β β βββ tax_implications.txt # Tax agent system prompt
β β βββ tlh.txt # Tax-loss harvesting agent prompt
β β βββ rate_arbitrage.txt # Rate arbitrage agent prompt
β β βββ timing.txt # Timing agent system prompt
β β βββ conversation_router.txt # Router system prompt
β β βββ response_synthesizer.txt # Synthesizer system prompt
β β βββ welly_persona.txt # Welly personality definition
β βββ data/
β β βββ demo_profile.json # Synthetic client seed data
β β βββ cra_rules_2024.json # CRA tax rules injected into agents
β βββ requirements.txt
β βββ railway.toml
β
βββ frontend/
β βββ app/
β β βββ layout.tsx # Root layout with providers
β β βββ page.tsx # Landing page
β β βββ login/page.tsx # Google OAuth login
β β βββ dashboard/page.tsx # Portfolio dashboard
β β βββ portfolio/page.tsx # Positions & trading
β β βββ accounts/page.tsx # Account management
β β βββ markets/page.tsx # Market search & quotes
β β βββ history/page.tsx # Transaction history
β βββ components/
β β βββ AppShell.tsx # Layout shell with sidebar + Welly panel
β β βββ Sidebar.tsx # Navigation sidebar
β β βββ Providers.tsx # Auth + context providers
β β βββ chat/
β β β βββ ChatPanel.tsx # Welly conversational interface
β β βββ onboarding/
β β β βββ IntroScreen.tsx # First-time intro overlay
β β β βββ WellyIntro.tsx # Programmatic onboarding sequence
β β βββ trading/
β β β βββ TradeModal.tsx # Buy/sell order modal
β β β βββ ExchangeModal.tsx # Currency exchange modal
β β βββ ui/ # shadcn/ui primitives
β βββ contexts/
β β βββ PortfolioContext.tsx # Global portfolio state
β βββ lib/
β β βββ api.ts # API client (REST + SSE streaming)
β β βββ websocket.ts # WebSocket client for insights
β β βββ utils.ts # Utility functions
β βββ types/
β β βββ index.ts # TypeScript interfaces
β βββ middleware.ts # Auth middleware (route protection)
β βββ package.json
β βββ railway.toml
β
βββ CLAUDE.md # AI development guidelines
βββ README.md
- Python 3.14+
- Node.js 20+
- Anthropic API key
- Google OAuth credentials
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Create .env file
echo "ANTHROPIC_API_KEY=your_key_here" > .env
echo "FRONTEND_URL=http://localhost:3000" >> .env
uvicorn main:app --reload --port 8000cd frontend
npm install
# Create .env.local file
echo "NEXT_PUBLIC_API_URL=http://localhost:8000" > .env.local
echo "NEXTAUTH_SECRET=your_secret_here" >> .env.local
echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
echo "GOOGLE_CLIENT_ID=your_google_client_id" >> .env.local
echo "GOOGLE_CLIENT_SECRET=your_google_client_secret" >> .env.local
npm run devThe backend auto-creates the SQLite database and seeds a demo user on first startup.
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
Anthropic API key |
DATABASE_URL |
SQLite path |
FRONTEND_URL |
Frontend origin for CORS |
| Variable | Description |
|---|---|
NEXT_PUBLIC_API_URL |
Backend API URL |
NEXTAUTH_SECRET |
NextAuth session encryption secret |
NEXTAUTH_URL |
Canonical app URL |
GOOGLE_CLIENT_ID |
Google OAuth client ID |
GOOGLE_CLIENT_SECRET |
Google OAuth client secret |
Β© Noah Kostesku. All rights reserved.
This project and its source code are proprietary. No part of this codebase may be reproduced, distributed, or transmitted in any form without prior written permission from the author.
