Skip to content

πŸ€– κ°€μ§œμ—°κ΅¬μ†Œ 11κΈ° Multi-Agent AI 투자 자문 μ‹œμŠ€ν…œ ν”„λ‘œμ νŠΈ

Notifications You must be signed in to change notification settings

TaskerJang/FinAgent_Investment_Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FinAgent Investment Agent

FinAgent is a sophisticated Multi-Agent AI system designed to provide personalized investment advice. By orchestrating specialized agentsβ€”from profile analysis to fierce debates between opposing viewpointsβ€”it delivers comprehensive, data-driven financial reports tailored to the user's specific risk tolerance and goals.

System Architecture

The system follows a graph-based workflow powered by LangGraph, ensuring modularity and context retention throughout the user interaction.

FinAgent Architecture

Workflow Overview

  1. Input Guardrail: Every user input is first checked for safety and domain relevance. Non-financial queries are filtered out immediately.
  2. Context-Aware Routing: The Condition Node analyzes the user's intent and conversation history to decide the next step:
    • New User / Profile Update β†’ User Chat (Onboarding)
    • Simple Data Query β†’ Retriever (Search)
    • Complex Investment Advice β†’ Debate (Analysis)
    • Report Generation β†’ Finance (Synthesis)
  3. Multi-Agent Collaboration:
    • User Chat: Conducts a natural interview to fill missing KYC data (Risk level, Income, etc.) and syncs with Supabase.
    • Debate: Bull, Bear, and Balanced experts engage in a multi-round debate using real-time data (Yahoo Finance, Tavily) to analyze risks and opportunities.
    • Retriever: Fetches specific product data via SQL or general knowledge via RAG.
  4. Final Output: The Finance Node synthesizes all gathered insights and debate conclusions into a structured Markdown report.

Key Modules:

  1. Guardrail: Ensures safety and domain relevance, filtering out non-financial queries.
  2. Condition: The intelligent router that analyzes user intent and context to direct the flow (e.g., to Debate, Retriever, or Profile setup).
  3. User Chat: Conducts a natural interview to collect and manage user profiles (KYC) and synchronizes data with the database.
  4. Retriever: Handles data fetching via SQL (for products), RAG (for regulations), and APIs (for market prices).
  5. Debate: Simulates a fierce debate between Bull (Aggressive), Bear (Conservative), and Balanced experts, concluded by a Judge (CIO).

Project Structure

FinAgent_Investment_Agent/
β”œβ”€β”€ assets/                  # Static assets (images, diagrams)
β”œβ”€β”€ condtition/              # Router & Safety Layer
β”‚   β”œβ”€β”€ condition.py         # Context-aware routing logic
β”‚   └── guardrail.py         # Input validation & safety checks
β”œβ”€β”€ debate/                  # Debate Engine
β”‚   β”œβ”€β”€ node.py              # 5-Round Debate Logic (Bull vs Bear vs Judge)
β”‚   └── tools.py             # Tools for debate (News, Market Data)
β”œβ”€β”€ finance/                 # Reporting Engine
β”‚   β”œβ”€β”€ node.py              # Final Report Generation
β”‚   └── tools.py             # SQL-based Product Recommendation Tools
β”œβ”€β”€ retriever/               # Information Retrieval
β”‚   β”œβ”€β”€ node.py              # ReAct Agent for Search
β”‚   └── tools.py             # Hybrid Search (SQL + Vector + Web)
β”œβ”€β”€ user_chat/               # User Onboarding
β”‚   β”œβ”€β”€ models.py            # Pydantic Data Models for Profile
β”‚   └── node.py              # Interview & DB Sync Logic
β”œβ”€β”€ utils/                   # Core Utilities
β”‚   β”œβ”€β”€ const.py             # Constants & Prompts
β”‚   β”œβ”€β”€ db.py                # Supabase Connection
β”‚   β”œβ”€β”€ embedding.py         # BGE-M3 Embedding Loader
β”‚   β”œβ”€β”€ llm.py               # OpenRouter/HTTPX Client
β”‚   └── state.py             # Shared Agent State (Memory)
β”œβ”€β”€ .env                     # API Keys and Config
β”œβ”€β”€ .gitignore
β”œβ”€β”€ api.py                   # FastAPI REST API Server
β”œβ”€β”€ main.py                  # Application Entry Point (Graph Compiler)
└── README.md                # Project Documentation

1. Installation

Clone the repository and install the required dependencies

# Clone repository
git clone https://github.com/your-repo/FinAgent_Investment_Agent.git
cd FinAgent

# Install dependencies
pip install -r requirements.txt

2. Configuration

Create a .env file in the root directory and add your API keys:

OPENROUTER_API_KEY="your-api-key"

SUPABASE_URL="your-supbase-url"
SUPABASE_SERVICE_KEY="your-api-key"

TAVILY_API_KEY="your-api-key"

3. Usage

Option A: Interactive CLI Mode

Run the main script to start the interactive CLI session.

python main.py

Option B: REST API Server

Start the FastAPI server for programmatic access:

python api.py

The server will start on http://localhost:8000

API Endpoints

POST /chat - Send messages and receive AI responses

curl -X POST http://localhost:8000/chat \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "test_user",
    "message": "Should I invest in Nvidia?",
    "session_id": "optional-session-id"
  }'

Response:

{
  "session_id": "abc123",
  "user_id": "test_user",
  "message": "Should I invest in Nvidia?",
  "response": "Let me analyze Nvidia for you...",
  "node_executed": "debate",
  "debate_history": [...],
  "timestamp": "2024-01-03T12:00:00"
}

GET /profile/{user_id} - Retrieve user profile

curl http://localhost:8000/profile/test_user

POST /profile/{user_id} - Create/Update user profile

curl -X POST http://localhost:8000/profile/test_user \
  -H "Content-Type: application/json" \
  -d '{
    "name_display": "John Doe",
    "age_range": "30λŒ€",
    "risk_tolerance_level": "aggressive",
    "goal_type": "long_term"
  }'

GET /health - Health check endpoint

curl http://localhost:8000/health

4. Example

Scenario: A user asks about investing in Nvidia.

User: Should I buy Nvidia right now?

Guardrail: [finance] -> Allowed: True
Routing to [debate] (Reason: User is asking for investment advice.)

[Debate Arena] Topic: Should I buy Nvidia right now? (5 Rounds)

--- Round 1: Opening Statement ---
Turn: Conservative Expert
Arg: Nvidia's valuation is too high (PER > 70). Regulatory risks in China are concerning...

Turn: Aggressive Expert
Arg: AI demand is just starting. Nvidia has a monopoly on H100 chips...

... (Rounds 2, 3, 4...) ...

Judge's Verdict:
   "While growth potential is undeniable, short-term volatility is expected. 
    I recommend a split-buying strategy."

AI Suggestion: "Shall we analyze the exchange rate risk before writing the report?"

User: Yes, please check that.

... (Additional Debate on Exchange Rates) ...

[Finance Node] Generating Final Report...
Report Saved to DB.

Agent (finance):
# πŸ“‹ Investment Advisory Report: Nvidia Analysis
## 1. Market Analysis...
## 2. Investment Strategy...
## 3. Recommended Portfolio (Product: TIGER US Tech Top 10)...

Key Components

Hybrid Market Data Tools (utils/tools.py)
Our agent uses a hybrid approach to fetch real-time stock data:

  • Korean Stocks: Uses FinanceDataReader (Naver Finance based).
  • Global Stocks/Indices: Uses Yahoo Finance (with auto-ticker mapping).

Context-Aware Router (condition/condition.py)
The router doesn't just look at the last message. It analyzes the entire conversation history to determine if the user is answering a profile question, agreeing to a suggestion, or asking a new question, preventing infinite loops.

Database Synchronization (user_chat/node.py)

  • Load: Fetches existing user profiles on startup.
  • Upsert: Automatically updates the profile in Supabase whenever new information is extracted during the chat.
  • Strict Schema: Enforces strict data types (e.g., risk_tolerance_level Enum) to ensure data integrity.

Outputs

  • Conversation History: Stored in-memory using MemorySaver for context retention.
  • User Profile: Persisted in the user_profile table in Supabase.
  • Advisory Report: Final reports are saved in the advisory_reports table and presented to the user in Markdown format.

About

πŸ€– κ°€μ§œμ—°κ΅¬μ†Œ 11κΈ° Multi-Agent AI 투자 자문 μ‹œμŠ€ν…œ ν”„λ‘œμ νŠΈ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages