├── .env.example ├── .gitignore ├── CalculatorTool.py ├── README.md ├── main - ollama - localai.py ├── main.py ├── markdown └── math.md ├── rag_pdf ├── .env_example ├── .gitignore ├── agents.py ├── gpt-4-analysis.pdf ├── main.py └── tasks.py ├── requirements.txt └── tools-example.py /.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY= 2 | OPENAI_MODEL_NAME=gpt-4 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .idea/ 3 | rag_pdf/db 4 | __pycache__/ 5 | -------------------------------------------------------------------------------- /CalculatorTool.py: -------------------------------------------------------------------------------- 1 | from langchain_community.tools import tool 2 | 3 | 4 | @tool("Calculate") 5 | def calculate(equation): 6 | """ Useful for solving math equations """ 7 | 8 | return eval(equation) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## CrewAI Beginner Course 2 | 3 | - install pycharm community edition ide (if you don't have one) 4 | - install anaconda (if you don't want to use venv) 5 | 6 | Join my [Discord](https://discord.gg/Db6e8KkHww) community for any questions! 7 | 8 | To install the requirements, type this in your terminal:
9 | pip install -r requirements.txt 10 | 11 | OR 12 | 13 | pip install crew for beginning of tutorial 14 | pip install 'crewai[tools]' for tooling on rest of tutorial 15 | 16 | ### I explain where to use these in the video 17 | -------------------------------------------------------------------------------- /main - ollama - localai.py: -------------------------------------------------------------------------------- 1 | import os 2 | from crewai import Agent, Task, Crew 3 | from langchain_openai import ChatOpenAI 4 | 5 | os.environ["OPENAI_API_KEY"] = "sk-proj-1111" 6 | 7 | llm = ChatOpenAI( 8 | model="phi3:3.8b", 9 | base_url="http://localhost:11434/v1" 10 | ) 11 | 12 | info_agent = Agent( 13 | role="Information Agent", 14 | goal="Give compelling information about a certain topic", 15 | backstory=""" 16 | You love to know information. People love and hate you for it. You win most of the 17 | quizzes at your local pub. 18 | """, 19 | llm=llm 20 | ) 21 | 22 | task1 = Task( 23 | description="Tell me all about the box jellyfish.", 24 | expected_output="Give me a quick summary and then also give me 7 bullet points describing it.", 25 | agent=info_agent 26 | ) 27 | 28 | crew = Crew( 29 | agents=[info_agent], 30 | tasks=[task1], 31 | verbose=2 32 | ) 33 | 34 | result = crew.kickoff() 35 | 36 | print("############") 37 | print(result) 38 | 39 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from crewai import Agent, Task, Crew 3 | 4 | os.environ["OPENAI_API_KEY"] = "sk-proj-1111" 5 | os.environ["OPENAI_MODEL_NAME"] = "gpt-4" 6 | 7 | info_agent = Agent( 8 | role="Information Agent", 9 | goal="Give compelling information about a certain topic", 10 | backstory=""" 11 | You love to know information. People love and hate you for it. You win most of the 12 | quizzes at your local pub. 13 | """ 14 | ) 15 | 16 | task1 = Task( 17 | description="Tell me all about the blue-ringed octopus.", 18 | expected_output="Give me a quick summary and then also give me 7 bullet points describing it.", 19 | agent=info_agent 20 | ) 21 | 22 | crew = Crew( 23 | agents=[info_agent], 24 | tasks=[task1], 25 | verbose=2 26 | ) 27 | 28 | result = crew.kickoff() 29 | 30 | print("############") 31 | print(result) 32 | 33 | -------------------------------------------------------------------------------- /markdown/math.md: -------------------------------------------------------------------------------- 1 | The mathematical journey of the expression "2 * 9 + 4 - 2 * -2 / 4" to its destination, 23.0, is a fascinating tale of operations and order. The tale begins with our equation, a seemingly jumbled string of numbers and symbols. But within this chaos, there is a defined order, a set of rules that govern how each operation is carried out. This order of operations is often remembered by the acronym PEMDAS, which stands for Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction. 2 | 3 | In our equation, the multiplication operations are the first to catch the spotlight. The stage is shared by '2 * 9' and '2 * -2'. They perform their roles beautifully, resulting in 18 and -4 respectively. 4 | 5 | Next, the division operation '(-4) / 4' steps into the limelight. With a wave of its wand, it transforms -4 into -1.0. 6 | 7 | With the multiplication and division acts over, our equation now reads '18 + 4 - -1.0'. Here, subtraction of a negative number is the same as addition, so it becomes '18 + 4 + 1.0'. 8 | 9 | Finally, it's time for the addition operations to shine. '18 + 4' and '+ 1.0' give us 22 and 1.0 respectively. The grand finale, '22 + 1.0', brings our magical mathematical journey to its end, resulting in 23.0. 10 | 11 | And there you have it! The seemingly complex expression "2 * 9 + 4 - 2 * -2 / 4" has been unraveled, step by step, following the order of operations. It's a perfect example of how beneath the surface of numbers and symbols, there's a story waiting to be told. The magical world of mathematics is a theatre where each operation plays its part, guided by the order of operations, to help us reach our final destination. In this case, the result of 23.0. -------------------------------------------------------------------------------- /rag_pdf/.env_example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY=sk-proj-1111 -------------------------------------------------------------------------------- /rag_pdf/.gitignore: -------------------------------------------------------------------------------- 1 | #ignore this in github 2 | 3 | # environment variables 4 | .env 5 | 6 | #Cache folders 7 | __pycache__/ -------------------------------------------------------------------------------- /rag_pdf/agents.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent 2 | from textwrap import dedent 3 | from langchain_openai import ChatOpenAI 4 | from crewai_tools import PDFSearchTool 5 | 6 | 7 | class CustomAgents: 8 | def __init__(self): 9 | self.OpenAIGPT35 = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.7) 10 | self.OpenAIGPT4 = ChatOpenAI(model_name="gpt-4", temperature=0.7) 11 | 12 | def pdf_agent(self): 13 | 14 | pdf_tool = PDFSearchTool("gpt-4-analysis.pdf") 15 | 16 | return Agent( 17 | role="Senior PDF Analyst", 18 | backstory=dedent(f"""You can find anything in a pdf. The people need you."""), 19 | goal=dedent(f"""Uncover any information from pdf files exceptionally well."""), 20 | tools=[pdf_tool], 21 | verbose=True, 22 | llm=self.OpenAIGPT4, 23 | ) 24 | 25 | def writer_agent(self): 26 | return Agent( 27 | role="Writer", 28 | backstory=dedent(f"""All your life you have loved writing summaries."""), 29 | goal=dedent(f"""Take the information from the pdf agent and summarize it nicely."""), 30 | verbose=True, 31 | llm=self.OpenAIGPT35, 32 | ) 33 | -------------------------------------------------------------------------------- /rag_pdf/gpt-4-analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylerprogramming/crewai-beginner-course/d4bde812540445dae106361deb49ab1235c587aa/rag_pdf/gpt-4-analysis.pdf -------------------------------------------------------------------------------- /rag_pdf/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from textwrap import dedent 3 | 4 | from crewai import Crew 5 | from decouple import config 6 | 7 | from agents import CustomAgents 8 | from tasks import CustomTasks 9 | 10 | os.environ["OPENAI_API_KEY"] = config("OPENAI_API_KEY") 11 | 12 | class CustomCrew: 13 | def __init__(self, var1): 14 | self.var1 = var1 15 | 16 | def run(self): 17 | # Define your custom agents and tasks in agents.py and tasks.py 18 | agents = CustomAgents() 19 | tasks = CustomTasks() 20 | 21 | # Define your custom agents and tasks here 22 | pdf_agent = agents.pdf_agent() 23 | writer_agent = agents.writer_agent() 24 | 25 | # Custom tasks include agent name and variables as input 26 | task1 = tasks.pdf_task( 27 | pdf_agent, 28 | self.var1 29 | ) 30 | 31 | task2 = tasks.writer_task( 32 | writer_agent, 33 | ) 34 | 35 | # Define your custom crew here 36 | crew = Crew( 37 | agents=[pdf_agent, writer_agent], 38 | tasks=[task1, task2], 39 | verbose=True, 40 | ) 41 | 42 | result = crew.kickoff() 43 | return result 44 | 45 | 46 | # This is the main function that you will use to run your custom crew. 47 | if __name__ == "__main__": 48 | print("## Welcome to Crew AI Template") 49 | print("-------------------------------") 50 | var1 = input(dedent("""Enter variable 1: """)) 51 | 52 | custom_crew = CustomCrew(var1) 53 | result = custom_crew.run() 54 | print("\n\n########################") 55 | print("## Here is you custom crew run result:") 56 | print("########################\n") 57 | print(result) 58 | -------------------------------------------------------------------------------- /rag_pdf/tasks.py: -------------------------------------------------------------------------------- 1 | from crewai import Task 2 | from textwrap import dedent 3 | 4 | 5 | # This is an example of how to define custom tasks. 6 | # You can define as many tasks as you want. 7 | # You can also define custom agents in agents.py 8 | class CustomTasks: 9 | def __tip_section(self): 10 | return "If you do your BEST WORK, I'll give you a $10,000 commission!" 11 | 12 | def pdf_task(self, agent, var1): 13 | return Task( 14 | description=dedent( 15 | f""" 16 | Tell me precisely what I need to know from the RAG tool. 17 | Use this as what I want to lookup: {var1} 18 | 19 | {self.__tip_section()} 20 | 21 | Make sure to be as accurate as possible. 22 | """ 23 | ), 24 | expected_output="Full analysis.", 25 | agent=agent, 26 | ) 27 | 28 | def writer_task(self, agent): 29 | return Task( 30 | description=dedent( 31 | f""" 32 | Take the input from task 1 and write a compelling narrative about it. 33 | 34 | {self.__tip_section()} 35 | """ 36 | ), 37 | expected_output="Give me the title, then brief summary, then bullet points, and a TL;DR.", 38 | agent=agent, 39 | ) 40 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp==3.9.5 2 | aiosignal==1.3.1 3 | alembic==1.13.2 4 | annotated-types==0.7.0 5 | anyio==4.4.0 6 | appdirs==1.4.4 7 | asgiref==3.8.1 8 | attrs==23.2.0 9 | backoff==2.2.1 10 | bcrypt==4.1.3 11 | beautifulsoup4==4.12.3 12 | boto3==1.34.138 13 | botocore==1.34.138 14 | build==1.2.1 15 | cachetools==5.3.3 16 | certifi==2024.6.2 17 | charset-normalizer==3.3.2 18 | chroma-hnswlib==0.7.3 19 | chromadb==0.4.24 20 | clarifai==10.5.3 21 | clarifai-grpc==10.5.4 22 | click==8.1.7 23 | cohere==5.5.8 24 | coloredlogs==15.0.1 25 | contextlib2==21.6.0 26 | crewai==0.35.8 27 | crewai-tools==0.4.6 28 | dataclasses-json==0.6.7 29 | decorator==5.1.1 30 | Deprecated==1.2.14 31 | deprecation==2.1.0 32 | distro==1.9.0 33 | dnspython==2.6.1 34 | docker==7.1.0 35 | docstring_parser==0.16 36 | docx2txt==0.8 37 | email_validator==2.2.0 38 | embedchain==0.1.113 39 | fastapi==0.111.0 40 | fastapi-cli==0.0.4 41 | fastavro==1.9.4 42 | filelock==3.15.4 43 | flatbuffers==24.3.25 44 | frozenlist==1.4.1 45 | fsspec==2024.6.1 46 | google-api-core==2.19.1 47 | google-auth==2.31.0 48 | google-cloud-aiplatform==1.57.0 49 | google-cloud-bigquery==3.25.0 50 | google-cloud-core==2.4.1 51 | google-cloud-resource-manager==1.12.3 52 | google-cloud-storage==2.17.0 53 | google-crc32c==1.5.0 54 | google-resumable-media==2.7.1 55 | googleapis-common-protos==1.63.2 56 | gptcache==0.1.43 57 | greenlet==3.0.3 58 | grpc-google-iam-v1==0.13.1 59 | grpcio==1.64.1 60 | grpcio-status==1.62.2 61 | h11==0.14.0 62 | httpcore==1.0.5 63 | httptools==0.6.1 64 | httpx==0.27.0 65 | httpx-sse==0.4.0 66 | huggingface-hub==0.23.4 67 | humanfriendly==10.0 68 | idna==3.7 69 | importlib_metadata==7.1.0 70 | importlib_resources==6.4.0 71 | iniconfig==2.0.0 72 | inquirerpy==0.3.4 73 | instructor==1.3.3 74 | Jinja2==3.1.4 75 | jiter==0.4.2 76 | jmespath==1.0.1 77 | jsonpatch==1.33 78 | jsonpointer==3.0.0 79 | jsonref==1.1.0 80 | kubernetes==30.1.0 81 | lancedb==0.5.7 82 | langchain==0.1.20 83 | langchain-cohere==0.1.5 84 | langchain-community==0.0.38 85 | langchain-core==0.1.52 86 | langchain-openai==0.1.7 87 | langchain-text-splitters==0.0.2 88 | langsmith==0.1.83 89 | Mako==1.3.5 90 | markdown-it-py==3.0.0 91 | MarkupSafe==2.1.5 92 | marshmallow==3.21.3 93 | mdurl==0.1.2 94 | mmh3==4.1.0 95 | monotonic==1.6 96 | mpmath==1.3.0 97 | multidict==6.0.5 98 | mypy-extensions==1.0.0 99 | nodeenv==1.9.1 100 | numpy==1.26.4 101 | oauthlib==3.2.2 102 | onnxruntime==1.18.1 103 | openai==1.35.9 104 | opentelemetry-api==1.25.0 105 | opentelemetry-exporter-otlp-proto-common==1.25.0 106 | opentelemetry-exporter-otlp-proto-grpc==1.25.0 107 | opentelemetry-exporter-otlp-proto-http==1.25.0 108 | opentelemetry-instrumentation==0.46b0 109 | opentelemetry-instrumentation-asgi==0.46b0 110 | opentelemetry-instrumentation-fastapi==0.46b0 111 | opentelemetry-proto==1.25.0 112 | opentelemetry-sdk==1.25.0 113 | opentelemetry-semantic-conventions==0.46b0 114 | opentelemetry-util-http==0.46b0 115 | orjson==3.10.6 116 | outcome==1.3.0.post0 117 | overrides==7.7.0 118 | packaging==23.2 119 | parameterized==0.9.0 120 | pfzy==0.3.4 121 | pillow==10.4.0 122 | pluggy==1.5.0 123 | posthog==3.5.0 124 | prompt_toolkit==3.0.47 125 | proto-plus==1.24.0 126 | protobuf==4.25.3 127 | pulsar-client==3.5.0 128 | py==1.11.0 129 | pyarrow==16.1.0 130 | pyasn1==0.6.0 131 | pyasn1_modules==0.4.0 132 | pydantic==2.8.0 133 | pydantic_core==2.20.0 134 | Pygments==2.18.0 135 | pylance==0.9.18 136 | pypdf==4.2.0 137 | PyPika==0.48.9 138 | pyproject_hooks==1.1.0 139 | pyright==1.1.369 140 | pysbd==0.3.4 141 | PySocks==1.7.1 142 | pytest==8.2.2 143 | python-dateutil==2.9.0.post0 144 | python-dotenv==1.0.1 145 | python-multipart==0.0.9 146 | python-rapidjson==1.18 147 | pytube==15.0.0 148 | PyYAML==6.0.1 149 | ratelimiter==1.2.0.post0 150 | regex==2023.12.25 151 | requests==2.32.3 152 | requests-oauthlib==2.0.0 153 | retry==0.9.2 154 | rich==13.7.1 155 | rsa==4.9 156 | s3transfer==0.10.2 157 | schema==0.7.5 158 | selenium==4.22.0 159 | semver==3.0.2 160 | shapely==2.0.4 161 | shellingham==1.5.4 162 | six==1.16.0 163 | sniffio==1.3.1 164 | sortedcontainers==2.4.0 165 | soupsieve==2.5 166 | SQLAlchemy==2.0.31 167 | starlette==0.37.2 168 | sympy==1.12.1 169 | tabulate==0.9.0 170 | tenacity==8.4.2 171 | tiktoken==0.7.0 172 | tokenizers==0.19.1 173 | tqdm==4.66.4 174 | trio==0.25.1 175 | trio-websocket==0.11.1 176 | tritonclient==2.47.0 177 | typer==0.12.3 178 | types-requests==2.32.0.20240622 179 | typing-inspect==0.9.0 180 | typing_extensions==4.12.2 181 | ujson==5.10.0 182 | urllib3==2.2.2 183 | uvicorn==0.30.1 184 | uvloop==0.19.0 185 | watchfiles==0.22.0 186 | wcwidth==0.2.13 187 | websocket-client==1.8.0 188 | websockets==12.0 189 | wrapt==1.16.0 190 | wsproto==1.2.0 191 | yarl==1.9.4 192 | zipp==3.19.2 193 | -------------------------------------------------------------------------------- /tools-example.py: -------------------------------------------------------------------------------- 1 | import os 2 | from crewai import Agent, Task, Crew, Process 3 | from dotenv import load_dotenv 4 | from CalculatorTool import calculate 5 | 6 | load_dotenv() 7 | 8 | os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") 9 | os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME") 10 | 11 | print("## Welcome to the Math Whiz") 12 | math_input = input("What is your math equation: ") 13 | 14 | math_agent = Agent( 15 | role="Math Magician", 16 | goal="You are able to evaluate any math expression", 17 | backstory="YOU ARE A MATH WHIZ.", 18 | verbose=True, 19 | tools=[calculate] 20 | ) 21 | 22 | writer = Agent( 23 | role="Writer", 24 | goal="Craft compelling explanations based from results of math equations.", 25 | backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles. 26 | You transform complex concepts into compelling narratives. 27 | """, 28 | verbose=True 29 | ) 30 | 31 | task1 = Task( 32 | description=f"{math_input}", 33 | expected_output="Give full details in bullet points.", 34 | agent=math_agent 35 | ) 36 | 37 | task2 = Task( 38 | description="""using the insights provided, explain in great detail how the equation and result 39 | were formed.""", 40 | expected_output="""Explain in great detail and save in markdown. Do no add the triple tick marks at the 41 | beginning or end of the file. Also don't say what type it is in the first line.""", 42 | output_file="markdown/math.md", 43 | agent=writer 44 | ) 45 | 46 | crew = Crew( 47 | agents=[math_agent, writer], 48 | tasks=[task1, task2], 49 | process=Process.sequential, 50 | verbose=2 51 | ) 52 | 53 | result = crew.kickoff() 54 | 55 | print(result) 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | --------------------------------------------------------------------------------