├── .env.example ├── .gitignore ├── README.md ├── financial_analysis.py ├── requirements.txt └── talent_search.py /.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY=YOUR_OPENAI_API_KEY 2 | SERPAPI_API_KEY=YOUR_SERPAPI_API_KEY -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README.md for CrewAI Example Project 2 | 3 | ## Introduction 4 | 5 | This repository serves as an example project demonstrating the capabilities of CrewAI, a multi-agent AI framework. It includes two example scripts, `talent_search.py` and `financial_analysis.py`, which illustrate how CrewAI can be employed in different contexts - recruitment and financial analysis, respectively. This README provides guidance on setting up and running the example project. 6 | 7 | My blog post with more detail on this project can be found [here](https://stephencollins.tech/posts/how-to-automate-processes-with-crewai). 8 | 9 | ## Project Structure 10 | 11 | This example project contains the following key files: 12 | 13 | - `talent_search.py`: An example script for a recruitment use case. 14 | - `financial_analysis.py`: An example script for financial analysis. 15 | - `.env.example`: A template for setting up your environment variables. 16 | 17 | ## Getting Started 18 | 19 | ### Prerequisites 20 | 21 | - Python 3.6 or higher. 22 | - pip, the Python package manager. 23 | - OpenAI API key and a SERPAPI API key. 24 | 25 | ### Installation Steps 26 | 27 | 1. **Clone the Example Project**: 28 | 29 | - Clone or download this repository to your local machine. 30 | 31 | 2. **Install Dependencies**: 32 | 33 | - Navigate to the project directory and install the required packages: 34 | 35 | ```bash 36 | pip install -r requirements.txt 37 | ``` 38 | 39 | 3. **Set Up Environment Variables**: 40 | - Rename `.env.example` to `.env`. 41 | - Fill in your OpenAI API key and SERPAPI API key in the `.env` file. 42 | 43 | ## Running the Examples 44 | 45 | ### Talent Search Example 46 | 47 | `talent_search.py` showcases a recruitment scenario using CrewAI. To run this script: 48 | 49 | 1. Navigate to the directory containing `talent_search.py`. 50 | 2. Execute the script: 51 | 52 | ```bash 53 | python talent_search.py 54 | ``` 55 | 56 | ### Financial Analysis Example 57 | 58 | `financial_analysis.py` demonstrates financial analysis using CrewAI. To run this script: 59 | 60 | 1. Navigate to the directory containing `financial_analysis.py`. 61 | 2. Execute the script: 62 | 63 | ```bash 64 | python financial_analysis.py 65 | ``` 66 | 67 | ## Understanding the Code 68 | 69 | Each script demonstrates the instantiation of AI agents with specific roles and goals, the assignment of tasks to these agents, and how they interact within the CrewAI framework to accomplish the tasks. 70 | 71 | ## Conclusion 72 | 73 | This example project provides a practical illustration of how CrewAI can be utilized in different domains. By exploring and running these examples, you can gain insights into integrating CrewAI into your own projects. 74 | -------------------------------------------------------------------------------- /financial_analysis.py: -------------------------------------------------------------------------------- 1 | from langchain_community.tools.yahoo_finance_news import YahooFinanceNewsTool 2 | from dotenv import load_dotenv 3 | from crewai import Agent, Task, Crew 4 | 5 | load_dotenv() 6 | 7 | # Install the required library for Yahoo Finance News Tool 8 | # !pip install langchain_community 9 | 10 | yahoo_finance_news_tool = YahooFinanceNewsTool() 11 | 12 | # Define your agents with roles and goals 13 | financial_analyst = Agent( 14 | role='Financial Analyst', 15 | goal='Analyze current financial news to identify market trends and investment opportunities', 16 | backstory="""You are an experienced financial analyst adept at interpreting market data and news 17 | to forecast financial trends and advise on investment strategies.""", 18 | verbose=True, 19 | allow_delegation=False, 20 | tools=[yahoo_finance_news_tool] 21 | ) 22 | 23 | communications_specialist = Agent( 24 | role='Corporate Communications Specialist', 25 | goal='Communicate financial insights and market trends to company stakeholders', 26 | backstory="""As a communications specialist in a corporate setting, your expertise lies in 27 | crafting clear and concise messages from complex financial data for stakeholders and the public.""", 28 | verbose=True, 29 | allow_delegation=True, 30 | # (optional) llm=another_llm 31 | ) 32 | 33 | # Create tasks for your agents 34 | task1 = Task( 35 | description="""Review the latest financial news using the Yahoo Finance News Tool. Identify key market trends 36 | and potential investment opportunities relevant to our company's portfolio.""", 37 | agent=financial_analyst 38 | ) 39 | 40 | task2 = Task( 41 | description="""Based on the financial analyst's report, prepare a press release for the company. The release should 42 | highlight the identified market trends and investment opportunities, tailored for our stakeholders and the general public.""", 43 | agent=communications_specialist 44 | ) 45 | 46 | # Instantiate your crew with a sequential process 47 | crew = Crew( 48 | agents=[financial_analyst, communications_specialist], 49 | tasks=[task1, task2], 50 | verbose=2 51 | ) 52 | 53 | # Get your crew to work! 54 | result = crew.kickoff() 55 | 56 | print("######################") 57 | print(result) 58 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | crewai 2 | python-dotenv 3 | langchain_community -------------------------------------------------------------------------------- /talent_search.py: -------------------------------------------------------------------------------- 1 | from dotenv import load_dotenv 2 | from langchain_community.tools.google_jobs import GoogleJobsQueryRun 3 | from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper 4 | from crewai import Agent, Task, Crew 5 | 6 | # load dotenv: 7 | load_dotenv() 8 | 9 | # Initialize the Google Jobs tool 10 | google_jobs_tool = GoogleJobsQueryRun(api_wrapper=GoogleJobsAPIWrapper()) 11 | 12 | # Define your agents with roles and goals 13 | recruitment_specialist = Agent( 14 | role='Recruitment Specialist', 15 | goal='Find suitable job candidates for various positions within the company', 16 | backstory="""You are a recruitment specialist with expertise in identifying and attracting top talent 17 | across various industries and roles.""", 18 | verbose=True, 19 | allow_delegation=True, 20 | tools=[google_jobs_tool] 21 | ) 22 | 23 | hr_communicator = Agent( 24 | role='HR Communications Coordinator', 25 | goal='Communicate job openings and company culture to potential applicants', 26 | backstory="""As an HR communications coordinator, you excel at crafting compelling job descriptions 27 | and showcasing the company's values and culture to attract the right candidates.""", 28 | verbose=True, 29 | allow_delegation=True, 30 | # (optional) llm=another_llm 31 | ) 32 | 33 | # Create tasks for your agents 34 | task1 = Task( 35 | description="""Identify current job openings in the field of software development using the Google Jobs tool. 36 | Focus on roles suitable for candidates with 1-3 years of experience.""", 37 | agent=recruitment_specialist 38 | ) 39 | 40 | task2 = Task( 41 | description="""Based on the job openings identified, create engaging job descriptions and a recruitment 42 | social media post. Emphasize the company's commitment to innovation and a supportive work environment.""", 43 | agent=hr_communicator 44 | ) 45 | 46 | # Instantiate your crew with a sequential process (by default tasks are executed sequentially) 47 | crew = Crew( 48 | agents=[recruitment_specialist, hr_communicator], 49 | tasks=[task1, task2], 50 | verbose=2 51 | ) 52 | 53 | # Kick off the crew to start on it's tasks 54 | result = crew.kickoff() 55 | 56 | print("######################") 57 | print(result) 58 | --------------------------------------------------------------------------------