This backend powers a multi-agent AI application using FastAPI, LangChain, and LangGraph. It provides robust session management, user authentication, and agent orchestration for advanced AI workflows.
- FastAPI-based RESTful API: High-performance and easy-to-use API framework.
- User Authentication: Secure signup and login functionality using JWT.
- Session Management: Persistent session handling for multi-agent interactions.
- Multi-Agent Orchestration: Designed for integration with LangChain and LangGraph.
- MongoDB Integration: Asynchronous database operations using Motor.
- Structured Logging: Application-wide logging with configurable levels.
- Chat & Conversations: Chat with conversation history tracking.
- Framework: FastAPI
- AI Frameworks: LangChain, LangGraph
- Database: MongoDB with Motor
- Authentication: JWT (JSON Web Tokens)
- Environment Management:
python-dotenv - LLM Providers: Google Gemini, Groq
backend/
├── app/
│ ├── api/ # API Route handlers (chat, sessions, users)
│ ├── auth/ # Authentication & Security logic (JWT, hashing)
│ ├── configs/ # App configurations
│ ├── db/ # Database connection & setup
│ ├── graphs/ # LangGraph workflows for AI agents
│ ├── persistance/ # Repositories for DB interactions
│ ├── schemas/ # Pydantic models for validation
│ ├── services/ # Business logic (chat, LLM, web search)
│ ├── utils/ # Helper functions (logger, error handlers)
│ └── main.py # Entry point of the application
├── .env.example # Example environment variables
├── requirements.txt # Python dependencies
- Python 3.10+
- MongoDB instance (Local or MongoDB Atlas)
- API Keys (at least one LLM provider required):
- Google Gemini API Key (Recommended for production)
- Groq API Key (Recommended for fastest inference)
- Tavily API Key (Optional, for web search)
-
Navigate to the backend directory:
cd backend -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Create a .env file in the backend directory and add your configurations (refer to .env.example):
# Database Configuration
MONGODB_URL=mongodb://localhost:27017
MONGODB_DB_NAME=aiagent
# Authentication
SECRET_KEY=your_super_secret_key_change_this
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
# LLM Provider API Keys (at least one required)
GOOGLE_API_KEY=your-google-api-key-here
GROQ_API_KEY=your-groq-api-key-here
# Web Search API Key
TAVILY_API_KEY=your-tavily-api-key-hereRequired Environment Variables:
MONGODB_URL- MongoDB connection stringMONGODB_DB_NAME- Database nameSECRET_KEY- Secret key for JWT token generation (use a strong random string)- At least one LLM provider key (
GOOGLE_API_KEYorGROQ_API_KEY) TAVILY_API_KEY- For web search functionality
Start the development server:
python app/main.pyThe API will be available at http://localhost:8000. You can access the Interactive API docs (Swagger UI) at http://localhost:8000/docs.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/ |
Root endpoint with API information | ❌ |
GET |
/agent/health |
Health check endpoint | ❌ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/agent/users/signup |
Create a new user account | ❌ |
POST |
/agent/users/login |
Authenticate user and get JWT token | ❌ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/agent/sessions/create |
Create a new agent session | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/agent/chat/messages |
Send a message to AI agent and get response | ✅ |
GET |
/agent/chat/conversations/{session_id}/messages |
Get conversation history for a session | ✅ |