An intelligent multi-agent Django application powered by LangGraph and Google Gemini, featuring role-based access control and specialized AI agents for document management and movie discovery.
- Multi-Agent Supervisor System: Intelligent routing between specialized agents using LangGraph
- Document Management Agent: Full CRUD operations with permission-based access control
- Movie Discovery Agent: Integrated TMDB API for movie search and detailed information
- Role-Based Access Control (RBAC): Powered by Permit.io for fine-grained permissions
- AI-Powered Intelligence: Google Gemini LLM for natural language understanding
- Interactive Development: Jupyter notebooks for experimentation and testing
User Request
β
Supervisor Agent (Router)
β
ββββ΄βββ
β β
Document Movie
Agent Agent
The supervisor agent intelligently routes user requests to the appropriate specialized agent based on the query context.
- Python 3.12+
- Django 5.0+
- Google Gemini API Key
- TMDB API Key
- Permit.io API Key
- Clone the repository
git clone <your-repo-url>
cd DJANGO-AI-AGENT- Create and activate virtual environment
python -m venv venv_aiagent
source venv_aiagent/bin/activate # Linux/Mac
# or
venv_aiagent\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Set up environment variables
Create a .env file in the src directory:
# Django
SECRET_KEY=your-django-secret-key
DEBUG=True
# Google Gemini
GOOGLE_API_KEY=your-gemini-api-key
# TMDB API
TMDB_API_KEY=your-tmdb-api-key
# Permit.io
PERMIT_API_KEY=your-permit-api-key
PERMIT_PDP_URL=https://cloudpdp.api.permit.io- Run migrations
cd src
python manage.py migrate- Create a superuser
python manage.py createsuperuser- Run the development server
python manage.py runserverDJANGO-AI-AGENT/
βββ src/
β βββ AI/
β β βββ agents.py # Agent definitions
β β βββ supervisors.py # Supervisor routing logic
β β βββ llms.py # LLM configurations
β β βββ tools/
β β βββ documents.py # Document management tools
β β βββ movie_discovery.py # Movie discovery tools
β βββ documents/ # Document app
β βββ cfehome/ # Django project settings
β βββ mypermit/ # Permit.io client
β βββ tmdb/ # TMDB API client
βββ notebook/ # Jupyter notebooks for testing
βββ requirements.txt
Manages document operations with permission checks:
- Search documents: Query-based document search
- Create document: Add new documents
- Read document: Retrieve document details
- Update document: Modify existing documents
- Delete document: Remove documents
Provides movie information via TMDB API:
- Search movies: Find movies by title/keyword
- Movie details: Get comprehensive movie information including ratings, cast, and synopsis
The system uses Permit.io for RBAC with the following default roles:
- Full document access (read, create, update, delete)
- Movie discovery access (search, detail)
- Read-only document access
- Movie discovery access (search, detail)
Configure roles and permissions in the Permit.io dashboard or via the API.
Explore the notebook/ directory for interactive examples:
1-django-users-perms.ipynb- User and permission basics3-langgraph-django-tools.ipynb- LangGraph integration5-ai-agent.ipynb- Agent implementation6-memory-agent.ipynb- Agent memory management7-agent-crud.ipynb- CRUD operations with agents9-movie-discovery-ai-agent.ipynb- Movie agent examples10-multiagent.ipynb- Multi-agent system11-roles-and-permissions.ipynb- RBAC configuration
from AI.supervisors import get_supervisor
from langchain_core.messages import HumanMessage
supervisor = get_supervisor()
# Document query
response = supervisor.invoke({
"messages": [HumanMessage(content="Show me my recent documents")]
}, config={"configurable": {"user_id": "user_123"}})
# Movie query
response = supervisor.invoke({
"messages": [HumanMessage(content="Find movies about space exploration")]
}, config={"configurable": {"user_id": "user_123"}})from AI.agents import get_document_agent, get_movie_discovery_agent
# Document agent
doc_agent = get_document_agent()
result = doc_agent.invoke({
"messages": [HumanMessage(content="List my documents")]
}, config={"configurable": {"user_id": "user_123"}})
# Movie agent
movie_agent = get_movie_discovery_agent()
result = movie_agent.invoke({
"messages": [HumanMessage(content="Search for Inception")]
}, config={"configurable": {"user_id": "user_123"}})Configure the Gemini model in AI/llms.py:
def get_gemini_model(model=None):
return ChatGoogleGenerativeAI(
model=model or "gemini-2.0-flash-exp",
temperature=0.7
)Customize routing logic in AI/supervisors.py by modifying the ROUTER_SYS message and decision logic.
- Django 5.0+ - Web framework
- LangGraph - Agent orchestration
- LangChain - LLM framework
- Google Generative AI - LLM provider
- Permit.io - Authorization as a service
- TMDB API - Movie database
- Jupyter - Interactive development
Run Django tests:
python manage.py testUse Jupyter notebooks for interactive testing and experimentation.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- LangGraph for agent orchestration
- Google Gemini for AI capabilities
- Permit.io for authorization management
- TMDB for movie data
Built with β€οΈ using Django, LangGraph, and AI