This repository contains example Python file implementations of Crews using CrewAI, based on the first course from DeepLearning.ai. A newer course has since released going more in-depth into real use-cases for CrewAI. The examples from this first course demonstrate how to create and use AI agent crews for various tasks.
It also includes detailed notes from the DeepLearning.ai course on how to successfully build incredible Multi-Agent systems using the CrewAI framework. You can find those below in this README.
- Dependencies
- Introduction to CrewAI
- Key Concepts
- Agent Creation Framework
- Key Elements of Agent Tools
- Task Definition
- Multi-Agent Collaboration
- Example Implementations
- Next Steps with AI Agent Systems
- Additional Resources
The core dependencies for these examples are listed in the requirements.txt file:
CrewAI is a framework for creating and managing crews of AI agents that can work together to accomplish complex tasks. This repository provides practical examples of how to implement such crews using Python.
There are 6 key things that make an agent great:
-
Research (Data Collection): Ability to search online, in internal databases, or other sources. This includes comparison between findings and internal databases.
-
Role Playing: Carefully choosing the role, goal, and backstory with appropriate keywords to get better results.
-
Focus: The ability to handle the amount of content they receive and the tools they have. This often involves having many agents work together instead of one agent with many responsibilities.
-
Tools: Providing the key tools necessary for the job without overloading the agent. It's important to choose tools wisely.
-
Cooperation: The ability to take feedback and delegate tasks to each other. Agents should be set up to collaborate effectively.
-
Guardrails: Preventing hallucinations, random loops, or repetitive tool usage. Many of these are implemented at the framework level in CrewAI.
Agents in CrewAI get three types of memory out of the box:
- Short-term memory: Retains information during the execution of a task.
- Shared knowledge: Allows agents to share information and learnings with other agents.
- Long-term memory: Stores information after task completion for future use, leading to 'self-improving' agents.
When creating agents, think like a manager:
- Define the goal and process clearly.
- Identify the roles needed to accomplish the task.
- Create specific and well-defined roles (e.g., "HR Research Specialist" instead of just "Researcher").
- Consider the backstory and goals for each agent.
Tools are crucial for connecting your agents to the external world. They act as a translation layer, allowing agents to communicate with existing programs. To work properly, tools should cover these three key aspects:
- Versatility: Tools should accept different kinds of requests and fuzzy inputs.
- Fault-tolerance: Tools should be able to handle exceptions gracefully.
- Caching: Implement a caching layer to prevent unnecessary API calls or service requests.
Well-defined tasks are crucial for effective multi-agent systems. When defining tasks, consider the following:
- Clear Description: Explain the task very carefully and in detail.
- Clear Expectations: Set clear and concise expectations for the task outcome.
- CrewAI Hyperparameters: Utilize CrewAI's hyperparameters to fine-tune task execution.
Effective collaboration is key to the success of multi-agent systems. Consider these process types:
- Sequential: Agents work one after another in a predetermined order.
- Hierarchical: Involves a manager agent that delegates work to other agents.
- Asynchronous: Agents work independently and simultaneously on different aspects of the task.
File: collaboration_financial_analysis.py
This implementation demonstrates a crew of AI agents collaborating on financial analysis tasks.
- Agents: Data Analyst, Trading Strategy Developer, Trade Advisor, Risk Advisor
- Tools: SerperDevTool, ScrapeWebsiteTool
- Tasks: Analyze Market Data, Develop Trading Strategies, Plan Trade Execution, Assess Trading Risks
- Process: Hierarchical
- The crew is initialized with the agents and tasks.
- The process runs hierarchically, allowing for complex decision-making.
- The crew analyzes a specific stock based on user-defined parameters.
- Each agent performs its specialized task, building upon the work of others.
- The final output includes insights on market opportunities, trading strategies, execution plans, and risk analysis.
File: tailor_job_applications.py
This implementation demonstrates how a crew of AI agents can assist in tailoring job applications.
- Agents: Tech Job Researcher, Personal Profiler for Engineers, Resume Strategist for Engineers, Engineering Interview Preparer
- Tools: SerperDevTool, ScrapeWebsiteTool, FileReadTool, MDXSearchTool
- Tasks: Extract Job Requirements, Compile Comprehensive Profile, Align Resume with Job Requirements, Develop Interview Materials
- The crew is initialized with the agents and tasks.
- The process starts with analyzing a job posting URL and the applicant's GitHub profile.
- Each agent performs its specialized task, from researching job requirements to preparing interview materials.
- The output includes a tailored resume and interview preparation materials.
File: automate_event_planning.py
This implementation demonstrates how a crew of AI agents can automate the process of planning an event.
- Agents: Venue Coordinator, Logistics Manager, Marketing and Communications Agent
- Tools: SerperDevTool, ScrapeWebsiteTool
- Tasks: Find and Book Venue, Coordinate Catering and Equipment, Promote the Event
- Custom Elements: VenueDetails (Pydantic model), CustomTask (Extended Task class)
- The crew is initialized with the agents and tasks.
- Each agent performs its specialized task based on the event details provided.
- The Venue Coordinator outputs structured venue details in JSON format.
- The Marketing and Communications Agent produces a marketing report in Markdown format.
- The main function displays the venue details and marketing report after the crew completes its tasks.
File: customer_outreach_campaign.py
This implementation demonstrates how a crew of AI agents can conduct a customer outreach campaign.
- Agents: Sales Representative, Lead Sales Representative
- Tools: DirectoryReadTool, FileReadTool, SerperDevTool, SentimentAnalysisTool (custom)
- Tasks: Lead Profiling, Personalized Outreach
- The crew is initialized with the agents and tasks.
- The Sales Representative conducts an in-depth analysis of a lead company.
- The Lead Sales Representative crafts a personalized outreach campaign based on the lead profile.
- The process uses a custom SentimentAnalysisTool to ensure positive communication.
- The crew operates with verbose output and memory enabled for better tracking and context retention.
File: technical_articles.py
This implementation demonstrates how a crew of AI agents can collaborate to create technical articles.
- Agents: Content Planner, Content Writer, Editor
- Tasks: Plan Content, Write Content, Edit Content
- The crew is initialized with the agents and tasks.
- The Content Planner develops a comprehensive content plan for a given topic.
- The Content Writer uses the plan to craft a blog post.
- The Editor reviews and refines the blog post for publication.
- The final output is a well-structured, SEO-optimized blog post in Markdown format.
File: customer_support.py
This implementation demonstrates how a crew of AI agents can handle customer support inquiries effectively.
- Agents:
- Senior Support Representative
- Support Quality Assurance Specialist
- Tools:
- ScrapeWebsiteTool (for accessing documentation)
- Tasks:
- Inquiry Resolution
- Quality Assurance Review
- The crew is initialized with the support agent and quality assurance agent.
- The Senior Support Representative addresses the customer's inquiry using the available documentation and tools.
- The Support Quality Assurance Specialist reviews and refines the response to ensure high-quality support.
- The process uses memory to maintain context throughout the interaction.
- The final output is a comprehensive, friendly, and accurate response to the customer's inquiry.
This implementation showcases:
- The use of specialized roles for different aspects of customer support
- Integration of documentation scraping for up-to-date information
- A quality assurance process to ensure high-quality responses
- Maintaining a balance between professionalism and a friendly tone
To further explore and develop AI agent systems, consider the following:
- Practical Application: Apply the concepts to real-world scenarios, such as maximizing interview chances or streamlining business processes.
- Explore CrewAI+: For production deployments, consider using CrewAI+ which offers features like API deployment and secure hosting.
- Study Relevant Research: Dive into papers on role-playing and agent collaboration to deepen your understanding of multi-agent systems.
- Dive into the Code: Explore the CrewAI Github repository to understand the underlying mechanisms of the framework.
- CrewAI Documentation: [Link to documentation]
- CrewAI Custom GPT: A tool for writing CrewAI code and accessing CrewAI documents
- Discord Community: Join for support and discussions with other CrewAI users
- Research papers on role-playing and agent collaboration
- ChatDev paper on complex problem-solving through agent communication
This README provides an overview of the key concepts and techniques learned from the CrewAI course, along with practical examples of their implementation. For more detailed information and hands-on experience, refer to the example implementations in this repository and explore the additional resources provided.