The-Swarm-Corporation
Multi-Agent-RAG-Template
Python

This template demonstrates how to create a collaborative team of AI agents that work together to process, analyze, and generate insights from documents.

Last updated Jul 8, 2026
59
Stars
10
Forks
2
Issues
0
Stars/day
Attention Score
16
Language breakdown
Python 100.0%
โ–ธ Files click to expand
README

Multi-Agent-RAG-Template

Join our Discord Subscribe on YouTube Connect on LinkedIn Follow on X.com

GitHub stars Swarms Framework

License: MIT Python 3.10+ Swarms Framework

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
- Easily swap or modify agents without disrupting the system - Add custom agents with specialized capabilities - Define your own agent interaction patterns - Scale from 2 to 100+ agents seamlessly - Any LLM can be used, this template uses GROQ but you can use any other LLM such as OpenAI, Anthropic, Cohere, etc.
  • Adaptable Document Processing
- Support for any document format through custom extractors - Flexible document storage options (local, cloud, or hybrid) - Customizable chunking and embedding strategies - Dynamic index updates without system restart - Any RAG system can be used, this template uses LlamaIndexDB but you can use any other RAG system.
  • Configurable Workflows
- Design custom agent communication patterns - Implement parallel or sequential processing - Add conditional logic and branching workflows - Adjust system behavior through environment variables

๐Ÿš€ 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_system parameter in the AgentRearrange initialization is used to configure the RAG system.
  • The memory_system parameter is an instance of LlamaIndexDB, which is a database class for storing and retrieving medical documents.
  • The memory_system class must have a query(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, and PINECONE_ENVIRONMENT environment variables set.
  • See the pinecone_swarm.py file for the full example.
  • The PineconeManager class 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
g

๐Ÿ›  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:


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

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท The-Swarm-Corporation/Multi-Agent-RAG-Template ยท Updated daily from GitHub