This template demonstrates how to create a collaborative team of AI agents that work together to process, analyze, and generate insights from documents.
Multi-Agent-RAG-Template
A production-ready template for building Multi-Agent RAG (Retrieval-Augmented Generation) systems using the Swarms Framework. This template demonstrates how to create a collaborative team of AI agents that work together to process, analyze, and generate insights from documents.
๐ Features
- Plug-and-Play Agent Architecture
- Adaptable Document Processing
- Configurable Workflows
๐ Quick Start
- Clone the Repository
git clone https://github.com/The-Swarm-Corporation/Multi-Agent-RAG-Template.git
cd Multi-Agent-RAG-Template
- Set Up Environment
# Create and activate virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
Install dependencies
pip install -r requirements.txt
- Configure Environment Variables
# Create .env file
Edit .env file with your credentials
GROQAPIKEY="your-api-key-here"
WORKSPACEDIR="agentworkspace"
OPENAIAPIKEY="your-openai-api-key-here"
- Run the Example
python main.py
๐๏ธ Project Structure
Multi-Agent-RAG-Template/
โโโ main.py # Main entry point
โโโ multiagentrag/
โ โโโ agents.py # Agent definitions
โ โโโ memory.py # RAG implementation
โโโ docs/ # Place your documents here
โโโ requirements.txt # Project dependencies
โโโ .env # Environment variables
๐ง Customization
Adding New Agents
- Open
multiagentrag/agents.py - Create a new agent using the Agent class:
new_agent = Agent(
agent_name="New-Agent",
system_prompt="Your system prompt here",
llm=model,
max_loops=1,
# ... additional configuration
)
Modifying the Agent Flow
In main.py, update the flow parameter in the AgentRearrange initialization:
flow=f"{agent1.agentname} -> {agent2.agentname} -> {newagent.agentname}"
Integrating RAG
- The
memory_systemparameter in theAgentRearrangeinitialization is used to configure the RAG system. - The
memory_systemparameter is an instance ofLlamaIndexDB, which is a database class for storing and retrieving medical documents. - The
memory_systemclass must have aquery(query: str)method that returns a string for the agent to use it.
# Import the AgentRearrange class for coordinating multiple agents
from swarms import AgentRearrange
from multiagentrag.agents import ( diagnostic_specialist, medicaldataextractor, patientcarecoordinator, specialist_consultant, treatment_planner, )
from multiagentrag.memory import LlamaIndexDB
router = AgentRearrange( name="medical-diagnosis-treatment-swarm", description="Collaborative medical team for comprehensive patient diagnosis and treatment planning", max_loops=1, agents=[ medicaldataextractor, diagnostic_specialist, treatment_planner, specialist_consultant, patientcarecoordinator, ], memory_system=LlamaIndexDB( data_dir="docs", filenameasid=True, recursive=True, similaritytopk=10, ), flow=f"{medicaldataextractor.agentname} -> {diagnosticspecialist.agentname} -> {treatmentplanner.agentname} -> {specialistconsultant.agentname} -> {patientcarecoordinator.agentname}", )
if name == "main": router.run( "Analyze this Lucas Brown's medical data to provide a diagnosis and treatment plan" )
Pinecone Example
Here is an example of how to use Pinecone as the RAG system.
- Make sure you have a Pinecone index created and the
PINECONEAPIKEY,PINECONEINDEXNAME, andPINECONE_ENVIRONMENTenvironment variables set. - See the
pinecone_swarm.pyfile for the full example. - The
PineconeManagerclass is used to interface with the Pinecone API.
import os
from swarms import AgentRearrange
from multiagentrag.agents import (
diagnostic_specialist,
medicaldataextractor,
patientcarecoordinator,
specialist_consultant,
treatment_planner,
)
from multiagentrag.pinecone_wrapper import PineconeManager
router = AgentRearrange( name="medical-diagnosis-treatment-swarm", description="Collaborative medical team for comprehensive patient diagnosis and treatment planning", max_loops=1, agents=[ medicaldataextractor, diagnostic_specialist, treatment_planner, specialist_consultant, patientcarecoordinator, ], memory_system=PineconeManager( apikey=os.getenv("PINECONEAPI_KEY"), indexname=os.getenv("PINECONEINDEX_NAME"), environment=os.getenv("PINECONE_ENVIRONMENT"), ), flow=f"{medicaldataextractor.agentname} -> {diagnosticspecialist.agentname} -> {treatmentplanner.agentname} -> {specialistconsultant.agentname} -> {patientcarecoordinator.agentname}", )
if name == "main": router.run( "Analyze this Lucas Brown's medical data to provide a diagnosis and treatment plan" )
๐ Documentation
For detailed documentation on:
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ Built With
- Swarms Framework
- Python 3.10+
- GROQ API Key or you can change it to use any model from Swarm Models
- LlamaIndexDB for storing and retrieving medical documents
๐ฌ Contact
Questions? Reach out:
- Twitter: @kyegomez
- Email: kye@swarms.world
Want Real-Time Assistance?
Book a call with here for real-time assistance:
โญ Star us on GitHub if this project helped you!
Built with โฅ using Swarms Framework