A comprehensive multi-agent system for document processing, mathematical computation, and database querying using FastAPI, LangGraph, and LangChain.
- Multi-Agent Orchestration: Uses LangGraph to route queries between different specialized agents
- Document RAG: Pinecone vector store for document retrieval and search
- Math Computation: Pandas-based mathematical and statistical analysis
- SQL Query Engine: DuckDB integration for database operations
- PDF Processing: PyMuPDF and OCR for document text extraction
- Persona System: Financial, Legal, and General Assistant personas
- Suggested Queries: AI-powered follow-up question generation
- FastAPI Backend: RESTful API with automatic documentation
- Next.js Frontend: Modern React-based user interface
dynamic_agentic_system/
├── agents/ # Agent personas and management
│ ├── __init__.py
│ └── personas.py # Financial, Legal, General personas
├── rag/ # Retrieval-Augmented Generation
│ ├── __init__.py
│ └── document_store.py # Pinecone vector store integration
├── math_ops/ # Mathematical computations
│ ├── __init__.py
│ ├── computation.py # Pandas-based calculations
│ ├── data_processor.py # CSV data processing
│ └── sql_query.py # DuckDB database operations
├── ocr/ # PDF processing and OCR
│ ├── __init__.py
│ └── pdf_processor.py # PyMuPDF and Tesseract integration
├── router/ # Agent orchestration
│ ├── __init__.py
│ ├── agent_router.py # LangGraph workflow
│ └── suggested_queries.py # Follow-up query generation
├── api/ # FastAPI application
│ ├── __init__.py
│ └── main.py # Main API endpoints
├── frontend/ # Next.js frontend application
│ ├── app/ # Next.js app directory
│ ├── components/ # React components
│ ├── lib/ # Utility functions
│ ├── types/ # TypeScript type definitions
│ └── package.json # Frontend dependencies
├── data/ # Data storage
│ ├── docs/ # Uploaded PDF documents
│ └── stocks/ # Stock data files
├── config.py # Configuration and environment variables
├── requirements.txt # Python dependencies
├── env_example.txt # Environment variables template
├── run.py # Main server entry point
└── README.md # This file
- Python 3.8+
- OpenAI API key
- Pinecone API key and environment
- Tesseract OCR (optional, for enhanced PDF processing)
-
Clone the repository:
git clone <repository-url> cd dynamic_agentic_system
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp env_example.txt .env # Edit .env with your API keys and configuration -
Install Tesseract OCR (optional):
- Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki
- macOS:
brew install tesseract - Linux:
sudo apt-get install tesseract-ocr
Create a .env file with the following variables:
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Pinecone Configuration
PINECONE_API_KEY=your_pinecone_api_key_here
PINECONE_ENVIRONMENT=your_pinecone_environment_here
PINECONE_INDEX_NAME=dynamic-agentic-system
# Database Configuration
DATABASE_URL=sqlite:///./data/system.db
# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=True
# OCR Configuration
TESSERACT_CMD_PATH=/usr/bin/tesseract
# File Upload Configuration
MAX_FILE_SIZE=10485760 # 10MB
UPLOAD_DIR=./data/docscd api
python main.pyThe server will start at http://localhost:8000
POST /query
Content-Type: application/json
{
"query": "What are the key findings in the uploaded documents?",
"persona_type": "financial",
"context": "Additional context if needed"
}POST /upload
Content-Type: multipart/form-data
file: [PDF file]GET /personasGET /statusGET /documents/statsGET /database/tablesimport requests
# Query with financial persona
response = requests.post("http://localhost:8000/query", json={
"query": "Analyze the stock performance data and calculate the average return",
"persona_type": "financial"
})
print(response.json())# Upload PDF
with open("document.pdf", "rb") as f:
files = {"file": f}
upload_response = requests.post("http://localhost:8000/upload", files=files)
# Query the uploaded document
query_response = requests.post("http://localhost:8000/query", json={
"query": "What are the main points in the uploaded document?",
"persona_type": "general"
})- Stock market analysis and investment strategies
- Financial planning and portfolio management
- Economic trends and market indicators
- Risk assessment and mitigation
- Contract law and legal document analysis
- Corporate law and business regulations
- Intellectual property and compliance
- Risk assessment and legal implications
- General knowledge and research
- Problem-solving and analysis
- Writing and communication
- Technology and tools
- Query Classification: The system analyzes the query to determine the appropriate processing path
- Document Search: Searches uploaded PDFs using vector similarity
- Math Computation: Performs mathematical calculations and statistical analysis
- Database Query: Executes SQL queries on available data
- Response Generation: Uses the selected persona to generate a comprehensive response
- Query Suggestions: Generates relevant follow-up questions
- Create a new persona class in
agents/personas.py - Add it to the
PersonaManagerclass - Update the
PersonaTypeenum
- Extend the
MathComputationclass inmath/computation.py - Add new patterns to the query classification in
router/agent_router.py
- Extend the
SQLQueryEngineclass inmath/sql_query.py - Add new table schemas and sample data
- Missing API Keys: Ensure all required API keys are set in the
.envfile - Pinecone Index: The system will create the Pinecone index automatically on first run
- Tesseract OCR: If OCR fails, check the Tesseract installation path in the configuration
- File Upload: Ensure the upload directory exists and has proper permissions
Check the console output for detailed error messages and system status information.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions, please open an issue on the GitHub repository.
cd frontend
npm install
npm run devThe frontend will start at http://localhost:3000
- Modern UI: Built with Next.js 14, Tailwind CSS, and ShadCN components
- Real-time Chat: Interactive chat interface with persona selection
- File Upload: Drag-and-drop PDF upload functionality
- Responsive Design: Works on desktop and mobile devices
- Dark Mode: Toggle between light and dark themes
This project is licensed under the MIT License - see the LICENSE file for details.