--- title: PortfolioMind emoji: πŸ“Š colorFrom: gray colorTo: purple sdk: docker pinned: false license: apache-2.0 short_description: 'MultiAgent MCP - Personal FinAssistant ' tags: - mcp-in-action-track-consumer - mcp-in-action-track-creative - building-mcp-track-consumer --- # πŸ€– PortfolioMind - Multi-Agent Financial Assistant PortfolioMind is an intelligent multi-agent financial assistant that leverages the Model Context Protocol (MCP) to provide comprehensive financial services through specialized AI agents. Built with LangGraph, Google Gemini, and MCP servers, it offers real-time market data, portfolio management, document Q&A, and web search capabilitiesβ€”all in one unified platform. Whether you're tracking cryptocurrency trends, analyzing stock performance, or seeking insights from your financial documents, PortfolioMind delivers accurate, actionable intelligence through its orchestrated network of specialized agents. Experience the future of financial analysis with a system designed to handle complex queries, synthesize multi-source data, and provide you with the clarity you need to make informed investment decisions. ## 🎯 Overview PortfolioMind orchestrates multiple specialized AI agents using a ReAct (Reasoning + Acting) supervisor pattern. Each agent is equipped with domain-specific tools via MCP servers, enabling them to perform complex financial tasks with high accuracy and context awareness. ## πŸ—οΈ Architecture ### System Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Gradio UI Interface β”‚ β”‚ (Chat Interface + Document Upload + Voice Agent) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ReAct Supervisor (LangGraph) β”‚ β”‚ β€’ Analyzes queries using reasoning loops β”‚ β”‚ β€’ Routes to appropriate agents β”‚ β”‚ β€’ Synthesizes comprehensive answers β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Crypto β”‚ β”‚ Stock β”‚ β”‚ Finance β”‚ β”‚ RAG β”‚ β”‚ Search β”‚ β”‚ Agent β”‚ β”‚ Agent β”‚ β”‚ Tracker β”‚ β”‚ Agent β”‚ β”‚ Agent β”‚ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ MCP Servers β”‚ β”‚ β€’ CoinGecko MCP (Crypto data) β”‚ β”‚ β€’ Alpha Vantage MCP (Stock data) β”‚ β”‚ β€’ MCP Toolbox (Database operations) β”‚ β”‚ β€’ ChromaDB (Vector database) β”‚ β”‚ β€’ DuckDuckGo MCP (Web search) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### ReAct Pattern Workflow 1. **Think**: Supervisor analyzes the query and determines what information is needed 2. **Act**: Calls appropriate specialized agent(s) to gather information 3. **Observe**: Reviews agent responses and evaluates if more information is needed 4. **Repeat**: Continues reasoning loop until sufficient information is gathered 5. **Synthesize**: Generates comprehensive final answer from all gathered information ## πŸ€– Specialized Agents ### 🎀 ReAct Supervisor - Voice Agent PortfolioMind supports voice interaction through ElevenLabs integration. The same ReAct supervisor orchestrates agents via voice, providing: - Natural voice conversation - Real-time agent orchestration - Comprehensive financial assistance ### πŸͺ™ Crypto Agent - **Purpose**: Real-time cryptocurrency market data and analysis - **MCP Server**: CoinGecko MCP Server - **Capabilities**: - Current crypto prices and market data - Historical price trends - Market cap and volume information - Cryptocurrency comparisons - **LLM**: Google Gemini 2.5 Flash ### πŸ“ˆ Stock Agent - **Purpose**: Stock market data, company information, and financial analysis - **MCP Server**: Alpha Vantage MCP Server - **Capabilities**: - Real-time and historical stock prices - Company overview and fundamentals - Income statements and balance sheets - Technical indicators (RSI, MACD, SMA, EMA) - News sentiment analysis - Top gainers/losers - **LLM**: Google Gemini 2.5 Flash ### πŸ’Ό Finance Tracker Agent - **Purpose**: Personal portfolio management and tracking - **MCP Server**: MCP Toolbox (HTTP server for Cloud SQL) - **Capabilities**: - Add/remove stock transactions (BUY/SELL) - View current portfolio holdings - Calculate cost basis and realized gains - Portfolio performance analysis - Transaction history - Portfolio allocation visualization - **Database**: Google Cloud SQL (PostgreSQL) - **LLM**: Google Gemini 2.5 Flash with structured output ### πŸ“š RAG Agent - **Purpose**: Document storage, retrieval, and question answering - **Vector Database**: ChromaDB Cloud - **Embeddings**: Google Generative AI (embedding-001) - **Capabilities**: - Upload and process documents (PDF, TXT, DOCX) - Semantic search across documents - Context-aware Q&A - Document chunking with overlap - **LLM**: Google Gemini 2.5 Flash ### πŸ” Search Agent - **Purpose**: Web search for current information and news - **MCP Server**: DuckDuckGo MCP Server - **Capabilities**: - Real-time web search - Current events and news - General knowledge queries - Source citations - **LLM**: Google Gemini 2.5 Flash ## πŸ› οΈ Technology Stack ### Core Framework - **LangGraph**: Agent orchestration and workflow management - **LangChain**: LLM integration and tool management - **Gradio**: Web UI framework ### LLM & AI - **Google Gemini 2.5 Flash**: Primary language model for all agents - **Google Generative AI Embeddings**: For document vectorization ### MCP Integration - **langchain-mcp-adapters**: Bridge between LangChain and MCP servers - **mcp**: Official MCP Python SDK ### Data Storage - **ChromaDB Cloud**: Vector database for RAG - **Google Cloud SQL (PostgreSQL)**: Portfolio transaction database ### Document Processing - **PyPDF2**: PDF text extraction - **python-docx**: DOCX text extraction ### Other Libraries - **pydantic**: Data validation and structured output - **python-dotenv**: Environment configuration - **toolbox-langchain**: MCP Toolbox integration ## πŸ“‹ Prerequisites - Python 3.8+ - Docker (for MCP Toolbox server) - Google Cloud SQL instance (for Finance Tracker) - GCP Service Account Credentials - API Keys: - Google API Key (for Gemini) - Alpha Vantage API Key (for stock data) - CoinGecko API Key (optional, for crypto pro features) - ChromaDB API Key, Tenant, and Database (for RAG) ## πŸ›οΈ Project Structure ``` PortfolioMind/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ agents/ β”‚ β”‚ β”œβ”€β”€ crypto_agent_mcp.py # Crypto market data agent β”‚ β”‚ β”œβ”€β”€ stock_agent_mcp.py # Stock market data agent β”‚ β”‚ β”œβ”€β”€ finance_tracker_agent_mcp.py # Portfolio management β”‚ β”‚ β”œβ”€β”€ rag_agent_mcp.py # Document Q&A agent β”‚ β”‚ └── search_agent_mcp.py # Web search agent β”‚ β”œβ”€β”€ core/ β”‚ β”‚ β”œβ”€β”€ config.py # Configuration management β”‚ β”‚ β”œβ”€β”€ langgraph_supervisor.py # ReAct supervisor β”‚ β”‚ └── mcp_client.py # MCP client utilities β”‚ └── utils/ β”‚ └── file_processors.py # Document processing β”œβ”€β”€ ui/ β”‚ └── gradio_app.py # Gradio UI application β”œβ”€β”€ docker/ β”‚ └── Dockerfile # Docker configuration β”œβ”€β”€ database_schema.sql # PostgreSQL schema β”œβ”€β”€ requirements.txt # Python dependencies └── README.md # This file ``` ## πŸ—„οΈ Database Schema The Finance Tracker uses PostgreSQL with the following schema: ### Tables - **stock_transactions**: Stores all BUY/SELL transactions - Transaction details (symbol, type, quantity, price, date) - Notes and metadata - **portfolio_positions**: Aggregated current positions - Calculated from transactions via triggers - Cost basis, realized gains, total invested - **portfolio_snapshots**: Historical portfolio value tracking - Time-series data for performance analysis - **stock_metadata**: Cached stock information - Company name, sector, industry, market cap - Reduces API calls ### Features - **Automatic Position Calculation**: Triggers automatically update positions when transactions change - **Realized Gains Tracking**: Calculates gains/losses from sales - **Performance Snapshots**: Historical tracking of portfolio value ## πŸ“ License Apache 2.0 --- **Built with ❀️ using LangGraph, MCP, and Google Gemini**