A multi-agent Retrieval-Augmented Generation (RAG) system built with FastAPI and LangChain. This demo showcases how multiple AI agents can work together to provide intelligent responses by retrieving relevant information from a knowledge base, in this case about retail and product information.
- Multi-agent architecture: Separate retriever and responder agents for specialized tasks
- Vector-based search: Semantic search using ChromaDB for document retrieval
- FastAPI REST API: Clean HTTP endpoints for querying the system
- Async processing: Background task processing with webhook callbacks and queue.
- Configurable: Environment-based configuration for easy deployment
- Callback integration: RAG responses are sent to a configurable callback URL.
The system consists of two main agents:
- Retriever Agent: Performs semantic search in the vector database to find relevant documents.
- Responder Agent: Generates responses using retrieved context and handles user interactions. It is responsible for deciding whether to call the retriever agent or not.
curl -X POST "http://localhost:8000/query" \
-H "Content-Type: application/json" \
-d '{
"query": "What is the price and availability of product 1427b3b0?",
"user_id": "user123"
}'The result of this question comes from 3 files (product description, prices and stock files). The response will be received by the callback endpoint and can be seen in the logs, like this:
INFO:app: * RAG RESPONSE: The product **1427b3b0 (Mystery Book)** is priced at **$111** but is currently **out of stock**.
- Python 3.12 or higher
- Mistral API key (for the language model)
The easiest way to manage the project is using the make commands from the Makefile file.
Try running this to see all the available commands:
make help-
Clone the repository
git clone <repository-url> cd agentic-rag
-
Set up environment variables
cp .env.sample .env
Edit
.envand add your Mistral API key:MISTRAL_API_KEY=your_mistral_api_key_here -
Build and start the application
docker compose build docker compose up
-
View logs (optional)
docker compose logs -f
The API will be available at http://localhost:8000
-
Clone the repository
git clone <repository-url> cd agentic-rag
-
Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh -
Install dependencies
uv sync
-
Set up environment variables
cp .env.sample .env
Edit
.envand add your Mistral API key:MISTRAL_API_KEY=your_mistral_api_key_here
-
Clone the repository
git clone <repository-url> cd agentic-rag
-
Create and activate virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
If
requirements.txtdoesn't exist, install from pyproject.toml:pip install -e . -
Set up environment variables
cp .env.sample .env
Edit
.envand add your Mistral API key:MISTRAL_API_KEY=your_mistral_api_key_here
docker compose upuv run uvicorn app:app --port 8000uvicorn app:app --port 8000The API will be available at http://localhost:8000
Once running, visit http://localhost:8000/docs for interactive API documentation.
Submit a query to the RAG system.
Request body:
{
"query": "What is the price of Product 1?",
"user_id": "user123"
}Response:
{
"message": "User query enqueued successfully!"
}Receives callback responses (for internal use).
The application can be configured through environment variables in the .env file:
MISTRAL_API_KEY: Your Mistral API key (required)DOCUMENTS_DIRECTORY: Directory containing documents to index (default: "documents")VECTOR_DB_DIRECTORY: Directory for vector database storage (default: ".vector_db")CHUNK_SIZE: Text chunk size for document processing (default: 1000)CHUNK_OVERLAP_SIZE: Overlap between chunks (default: 100)TOP_K: Number of documents to retrieve (default: 5)CALLBACK_URL: Webhook URL for responses (optional)
The system automatically indexes documents from the documents/ directory on startup. Supported formats:
.txtfiles.mdfiles
To add new documents:
- Place files in the
documents/directory - Restart the application to re-index
docker compose exec app uv run pytest tests/uv run pytest tests/pytest tests/agentic-rag/
├── agents/ # AI agents (retriever, responder)
├── app/ # FastAPI application
├── documents/ # Knowledge base documents
├── rag/ # RAG implementation and vector store
├── tests/ # Unit tests
├── config.py # Configuration management
└── pyproject.toml # Project dependencies
This project is licensed under the terms specified in the LICENSE file.