The Supervisor Agent is an intelligent task router and orchestrator that automatically analyzes user requests and routes them to the most appropriate specialized agent. It provides a single entry point for all calendar and email operations while optimizing performance by using the most efficient agent for each task.
User Request → Supervisor Agent → Task Analysis → Agent Selection → Execution → Response
- Calendar Agent - Specialized for calendar operations
- Gmail Agent - Specialized for email operations
- Unified Agent - Handles complex workflows involving both calendar and email
- Keywords: schedule, meeting, calendar, event, availability, reschedule, appointment
- Use Cases:
- "Schedule a meeting tomorrow at 2 PM"
- "Check my availability for Friday"
- "List my events for next week"
- Keywords: email, send, mail, gmail, reply, forward, message, inbox
- Use Cases:
- "Send an email to john@example.com"
- "Search for emails from alice@company.com"
- "Reply to the latest email"
- Keywords: and, then, also, additionally, follow up
- Use Cases:
- "Schedule a meeting and send invitation"
- "Check calendar and send summary to team"
- "Reschedule meeting and notify attendees"
POST /api/supervisor/chatRequest Body:
{
"prompt": "Schedule a meeting tomorrow at 2 PM",
"user_id": "optional_user_id",
"preferred_agent": "auto"
}Response:
{
"response": "✅ Event successfully scheduled...",
"success": true,
"selected_agent": "calendar",
"reasoning": "The request is specifically about scheduling a meeting.",
"task_description": "Schedule a meeting for the user tomorrow at 2 PM.",
"error": null
}POST /api/supervisor/analyzeRequest Body:
{
"prompt": "Send an email to amankumar.ak0012@gmail.com"
}Response:
{
"success": true,
"analysis": {
"selected_agent": "gmail",
"reasoning": "The request involves sending an email, which falls under the email handling category.",
"task_description": "Send an email to the specified address."
},
"recommended_agent": "gmail",
"reasoning": "The request involves sending an email, which falls under the email handling category."
}GET /api/supervisor/healthGET /api/supervisor/capabilitiesGET /api/supervisor/agentsGET /api/supervisor/statsSchedule a Meeting:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Schedule a meeting with amankumar.ak0012@gmail.com tomorrow at 4 PM"}'Check Calendar:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Check my calendar for tomorrow"}'Send Email:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Send an email to amankumar.ak0012@gmail.com with subject Test and body Hello"}'Search Emails:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Search for emails from amankumar.ak0098@gmail.com"}'Schedule and Send Invitation:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Schedule a meeting with amankumar.ak0098@gmail.com tomorrow at 5 PM and send an email invitation"}'Calendar Summary and Email:
curl -X POST "http://localhost:8000/api/supervisor/chat" \
-H "Content-Type: application/json" \
-d '{"prompt": "Check my calendar for tomorrow and send a summary to amankumar.ak0098@gmail.com"}'Run the supervisor agent tests:
python test_supervisor_agent.pyThis will test:
- ✅ Supervisor agent creation
- ✅ Task analysis functionality
- ✅ Supervisor routing
- ✅ API endpoint functionality
- ✅ Agent capabilities
- Task analysis and classification
- Intelligent agent selection
- Workflow orchestration
- Result aggregation
- Schedule events
- Delete events
- Reschedule events
- Check availability
- List events
- Suggest free slots
- Send emails
- Read emails
- Search emails
- Reply to emails
- Forward emails
- Delete emails
- Manage labels
- All calendar capabilities
- All email capabilities
- Complex workflows
- Context awareness
- Automatically selects the most efficient agent
- Avoids using heavy unified agent for simple tasks
- Optimizes performance and cost
- One API endpoint for all operations
- Consistent interface across all agents
- Simplified client integration
- Graceful error handling
- Automatic fallback to unified agent
- Robust error recovery
- Easy to add new specialized agents
- Modular architecture
- Extensible design
User Request
↓
Supervisor Agent
↓
Task Analysis
↓
Agent Selection Decision
↓
┌─ Calendar Agent ──┐
├─ Gmail Agent ────┤
├─ Unified Agent ───┤
└─ Multi-Agent ────┘
↓
Execution & Tool Usage
↓
Service Layer (Calendar/Gmail APIs)
↓
Result Collection
↓
Response Aggregation
↓
Final Response to User
app/agents/supervisor_agent.py- Main supervisor agent implementationapp/api/endpoints/supervisor.py- API endpointstest_supervisor_agent.py- Test suiteSUPERVISOR_AGENT_README.md- This documentation
- JSON-based task analysis with fallback keyword matching
- Intelligent agent selection based on task complexity
- Comprehensive error handling with fallback strategies
- Detailed response format with reasoning and analysis
- Health monitoring and capability reporting
-
Start the server:
python -m uvicorn app.main:app --reload
-
Test the supervisor:
python test_supervisor_agent.py
-
Use the API:
curl -X POST "http://localhost:8000/api/supervisor/chat" \ -H "Content-Type: application/json" \ -d '{"prompt": "Schedule a meeting tomorrow at 2 PM"}'
The supervisor agent provides:
- Faster response times for simple tasks (direct routing)
- Cost optimization (uses specialized agents when possible)
- Better user experience (intelligent task handling)
- Scalable architecture (easy to add new agents)
Monitor supervisor performance through:
/api/supervisor/health- Health status/api/supervisor/stats- Performance metrics/api/supervisor/capabilities- Available capabilities
Your supervisor agent is now ready to intelligently route tasks to the most appropriate agent, providing a seamless experience for calendar and email management!