«`html
A Coding Guide to Build a Hierarchical Supervisor Agent Framework with CrewAI and Google Gemini for Coordinated Multi-Agent Workflows
In this tutorial, we walk you through the design and implementation of an advanced Supervisor Agent Framework using CrewAI with the Google Gemini model. We set up specialized agents, including researchers, analysts, writers, and reviewers, and bring them under a supervisor agent who coordinates and monitors their work. By combining structured task configurations, hierarchical workflows, and built-in tools, we create a system where each agent plays a defined role. At the same time, the supervisor ensures quality and coherence across the entire project lifecycle.
Target Audience Analysis
The target audience for this guide includes:
- AI Developers: Individuals looking to implement AI frameworks in their projects.
- Business Managers: Professionals interested in optimizing workflows through AI.
- Data Scientists: Experts seeking to enhance their research and analysis capabilities with AI tools.
Common pain points include:
- Difficulty in coordinating multi-agent workflows.
- Challenges in ensuring quality and coherence in collaborative projects.
- Need for efficient task management and execution.
Goals of the audience:
- To implement AI solutions that streamline project management.
- To enhance productivity through coordinated workflows.
- To achieve high-quality deliverables in collaborative environments.
Interests include:
- Learning about advanced AI frameworks.
- Exploring practical applications of AI in business management.
- Networking with other professionals in the AI and business sectors.
Preferred communication methods involve:
- Detailed technical documentation.
- Interactive tutorials and coding examples.
- Webinars and online workshops.
Setting Up the Supervisor Agent Framework
We begin by installing the libraries and essential modules to set up our CrewAI framework. Here, we define the TaskPriority
enum, which helps us assign different levels of urgency and importance to each task we create.
!pip install crewai crewai-tools langchain-google-genai python-dotenv
import os
from typing import List, Dict, Any
from dataclasses import dataclass
from enum import Enum
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool, WebsiteSearchTool
from langchain_google_genai import ChatGoogleGenerativeAI
from dotenv import load_dotenv
class TaskPriority(Enum):
LOW = 1
MEDIUM = 2
HIGH = 3
CRITICAL = 4
We define a flexible TaskConfig
data class to capture each task’s intent, expected output, priority, and runtime requirements, thereby standardizing how work flows through the system. We then build a SupervisorFramework
that wires in Gemini, optional search tools, and a coordinated crew of specialized agents, so we orchestrate research, analysis, writing, and review under a supervising agent in real time.
Creating Specialized Agents
The framework includes the following specialized agents:
- Research Agent: Conducts comprehensive research and gathers accurate information.
- Data Analyst Agent: Analyzes data, identifies patterns, and provides actionable insights.
- Content Writer Agent: Creates clear, engaging, and well-structured written content.
- Quality Assurance Reviewer Agent: Reviews, validates, and improves the quality of all deliverables.
- Project Supervisor Agent: Coordinates team efforts, manages workflows, and ensures project success.
Task Workflow Creation
We create a comprehensive task workflow that includes:
- Research tasks focused on gathering information.
- Analysis tasks that identify insights from research findings.
- Writing tasks that create structured documents based on analysis.
- Review tasks that ensure quality and coherence of all outputs.
Executing the Project
The execute_project
method allows us to run the entire project workflow, ensuring that all agents work together efficiently. The supervisor agent monitors progress and ensures quality standards are met throughout the project lifecycle.
Usage Metrics
After project execution, we can retrieve usage metrics to evaluate performance, including:
- Total tokens used.
- Total cost incurred during execution.
- Execution time for the project.
Conclusion
The Supervisor Framework enables systematic management of complex projects by utilizing multiple specialized agents that work in unison. We can now execute research, analysis, writing, and reviewing tasks in a coordinated workflow, with the supervisor ensuring quality and alignment at every stage. This setup equips us to handle real-world projects more efficiently, turning abstract goals into actionable, high-quality deliverables.
For more detailed code examples and tutorials, please visit our GitHub Page.
«`