Architecture Components
The system is designed with a modern, decoupled architecture ensuring high scalability and rapid AI execution.
Frontend
Built with Angular 21, providing a UI to view portfolio status, recent trades, logs, and trigger new trading cycles manually.
Backend
Developed using Python and FastAPI, handling REST APIs, database connections, and triggering AI workflows.
Database
MongoDB is used for persistent storage of portfolios, trade histories, and execution logs, with an in-memory fallback.
LangGraph
Models core intelligence as a state graph, allowing structured data flow from data gatherers to execution managers.
AI Integration
Integrates Google's Gemini-3.1-pro model to process complex data and output structured trading decisions and rigorous risk reasoning.
Agentic Workflow
The core trading intelligence is powered by a multi-agent system orchestrated by LangGraph. Each agent plays a specific role.
1 Market Data Gatherer
Role: Collects real-time market data (price, volume, trend).
Value: Provides foundational quantitative context.
2 Sentiment Analyst
Role: Analyzes news and social media to provide a sentiment score.
Value: Captures emotional and qualitative market drivers.
3 Technical Analyst
Role: Computes technical indicators like RSI and MACD.
Value: Identifies short-term momentum and price patterns.
4 Strategy/Decision Agent
Role: Aggregates data and uses Gemini to formulate a strategy (ACTION, AMOUNT, REASONING).
Value: Acts as the brain, synthesizing diverse streams to make context-aware decisions.
5 Risk Manager (LLM)
Role: Evaluates proposed trades against standard risk management principles to APPROVE or REJECT.
Value: Protects portfolio from severe drawdowns, ensuring long-term capital preservation.
6 Execution Agent
Role: Executes the order if approved by Risk Management.
Value: Automates physical trade execution.
Control & Communication Flow
Agents do not communicate directly. A shared AgentState object is managed by the LangGraph state machine. As the graph executes sequentially, each agent receives the state, performs its task, appends findings, and passes the enriched state down the pipeline.
System Diagrams
Overall System Design
graph TD
User([User]) -->|Interacts with UI| Frontend[Angular Frontend]
Frontend <-->|REST API| Backend[FastAPI Backend]
subgraph Server Infrastructure
Backend -->|Persists Data| MongoDB[(MongoDB Database)]
Backend -->|Invokes Workflow| LangGraph[LangGraph Engine]
end
subgraph AI Orchestration
LangGraph <-->|Prompts & Responses| LLM[Google Gemini LLM API]
end
LangGraph State Flow
graph TD
Start((Start)) --> gather_market_data
gather_market_data -->|"Market Data Gathered, Sentiment and Technicals Analyzed"| formulate_strategy
formulate_strategy -->|"Strategy Proposed (via LLM)"| evaluate_risk
evaluate_risk -->|"Risk Evaluated (via LLM)"| execute_trade
execute_trade -->|"Trade Executed (or Hold)"| End((End))
%% Notes attached via dotted lines
note_strategy["Uses LLM to decide
BUY, SELL, or HOLD based on
aggregated data."]
formulate_strategy -.- note_strategy
note_risk["Uses LLM to rigorously
evaluate the proposed strategy
against risk principles."]
evaluate_risk -.- note_risk
%% Styling to visually distinguish the notes
classDef note fill:#fff5ad,stroke:#d4c257,stroke-width:1px,color:#333;
class note_strategy,note_risk note;
Setup & Run
Get the agentic trader running locally in minutes.
Backend Setup
-
1
Navigate to backend
cd backend -
2
Install packages
pip install -r requirements.txt -
3
Set API Key
export GOOGLE_API_KEY="..." -
4
Start server
uvicorn main:app --reload
Frontend Setup
-
1
Navigate to frontend
cd frontend -
2
Install packages
npm install -
3
Start UI
npm start