├── crewai-streamlit-hierarchical-quickstart ├── filler ├── crewai-logo.png ├── README.md ├── .env.example ├── pyproject.toml ├── stream.py └── app.py ├── .gitignore ├── .DS_Store ├── images └── crewai-quick-start-cover.png ├── crewai-sequential-ollama2-quickstart ├── img.png ├── .env.example ├── CHEATSHEET.md ├── pyproject.toml └── main.py ├── crewai-sequential-ollama3-quickstart ├── img.png ├── .env.example ├── CHEATSHEET.md ├── pyproject.toml └── main.py ├── crewai-streamlit-sequential-quickstart ├── crewai-logo.png ├── README.md ├── .env.example ├── pyproject.toml ├── stream.py └── app.py ├── crewai-sequential-quickstart ├── CHEATSHEET.md ├── .env.example ├── pyproject.toml └── main.py ├── crewai-hierarchical-quickstart ├── CHEATSHEET.md ├── .env.example ├── output.log ├── pyproject.toml └── main.py ├── LICENSE ├── crewai_custom_tool_template_quickstart.ipynb ├── README.md ├── crewai_hierarchical_quickstart.ipynb ├── crewai_example_collaboration_financial_analysis_quickstart.ipynb ├── crewai-example-task-event-planning-quickstart.ipynb ├── crewai_sequential_quickstart.ipynb ├── crewai_sequential_BrowserbaseLoadTool_quickstart.ipynb ├── crewai_sequential_SerperDevTool_quickstart.ipynb ├── crewai_sequential_composio_core_quickstart.ipynb └── crewai_sequential_CodeInterpreterTool_quickstart.ipynb /crewai-streamlit-hierarchical-quickstart/filler: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store/ 3 | *.env 4 | !.env.example -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/.DS_Store -------------------------------------------------------------------------------- /images/crewai-quick-start-cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/images/crewai-quick-start-cover.png -------------------------------------------------------------------------------- /crewai-sequential-ollama2-quickstart/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/crewai-sequential-ollama2-quickstart/img.png -------------------------------------------------------------------------------- /crewai-sequential-ollama3-quickstart/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/crewai-sequential-ollama3-quickstart/img.png -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/crewai-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/crewai-streamlit-sequential-quickstart/crewai-logo.png -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/crewai-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfazio/crewAI-quickstart/main/crewai-streamlit-hierarchical-quickstart/crewai-logo.png -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/README.md: -------------------------------------------------------------------------------- 1 | ### Cheatsheet 2 | 3 | 1. `$ pip install poetry` 4 | 5 | 6 | 2. `$ poetry install` 7 | 8 | 9 | 3. `$ poetry run streamlit run app.py` -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/README.md: -------------------------------------------------------------------------------- 1 | ### Cheatsheet 2 | 3 | 1. `$ pip install poetry` 4 | 5 | 6 | 2. `$ poetry install` 7 | 8 | 9 | 3. `$ poetry run streamlit run app.py` -------------------------------------------------------------------------------- /crewai-sequential-quickstart/CHEATSHEET.md: -------------------------------------------------------------------------------- 1 | 2 | ### Cheatsheet 3 | 4 | 1. Add your API key(s) to the `./.env` file. 5 | 6 | 2. `pip install poetry` 7 | 8 | 3. `poetry install` 9 | 10 | 4. `poetry run python main.py` -------------------------------------------------------------------------------- /crewai-hierarchical-quickstart/CHEATSHEET.md: -------------------------------------------------------------------------------- 1 | 2 | ### Cheatsheet 3 | 4 | 1. Add your API key(s) to the `./.env` file. 5 | 6 | 2. `pip install poetry` 7 | 8 | 3. `poetry install` 9 | 10 | 4. `poetry run python main.py` -------------------------------------------------------------------------------- /crewai-sequential-ollama2-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY="NA" 2 | # ↑ uncomment to use Ollama 3 | # GROQ_API_KEY = "" 4 | # ↑ uncomment to use Groq's API 5 | # OPENAI_API_KEY = "" 6 | # ↑ uncomment to use OpenAI API -------------------------------------------------------------------------------- /crewai-sequential-ollama3-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY="NA" 2 | # ↑ uncomment to use Ollama 3 | # GROQ_API_KEY = "" 4 | # ↑ uncomment to use Groq's API 5 | # OPENAI_API_KEY = "" 6 | # ↑ uncomment to use OpenAI API 7 | -------------------------------------------------------------------------------- /crewai-hierarchical-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | #ANTHROPIC_API_KEY=your_antrhopic_api_key_here 2 | # ↑ uncomment to use Anthropic API 3 | #OPENAI_API_KEY=your_openai_api_key_here 4 | # ↑ uncomment to use OpenAI API 5 | #GROQ_API_KEY=your_groq_api_key_here 6 | # ↑ uncomment to use OpenAI API 7 | -------------------------------------------------------------------------------- /crewai-sequential-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | #ANTHROPIC_API_KEY=your_antrhopic_api_key_here 2 | # ↑ uncomment to use Anthropic API 3 | #OPENAI_API_KEY=your_openai_api_key_here 4 | # ↑ uncomment to use OpenAI API 5 | #GROQ_API_KEY=your_groq_api_key_here 6 | # ↑ uncomment to use OpenAI API 7 | -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | #ANTHROPIC_API_KEY=your_antrhopic_api_key_here 2 | # ↑ uncomment to use Anthropic API 3 | #OPENAI_API_KEY=your_openai_api_key_here 4 | # ↑ uncomment to use OpenAI API 5 | #GROQ_API_KEY=your_groq_api_key_here 6 | # ↑ uncomment to use OpenAI API 7 | -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/.env.example: -------------------------------------------------------------------------------- 1 | #ANTHROPIC_API_KEY=your_antrhopic_api_key_here 2 | # ↑ uncomment to use Anthropic API 3 | #OPENAI_API_KEY=your_openai_api_key_here 4 | # ↑ uncomment to use OpenAI API 5 | #GROQ_API_KEY=your_groq_api_key_here 6 | # ↑ uncomment to use OpenAI API 7 | -------------------------------------------------------------------------------- /crewai-sequential-ollama3-quickstart/CHEATSHEET.md: -------------------------------------------------------------------------------- 1 | ### Cheatsheet 2 | 3 | 1. Dowload and install Ollama → https://ollama.com/download or `$ brew install ollama` 4 | 5 | 6 | 2. Ensure these are your variables within `crewai-sequential-ollama2-quickstart/.env`: 7 | ```python 8 | OPENAI_API_KEY="NA" 9 | ``` 10 | 11 | 3. `$ cd crewai-sequential-ollama2-quickstart` 12 | 13 | 14 | 4. `$ poetry install` 15 | 16 | 17 | 5. `$ poetry run python main.py` 18 | 19 | ![03-05-2024_08-32-24](https://github.com/alexfazio/crewAI-quickstart/assets/34505954/e1c25feb-652e-484f-8084-ba1d12920bc7) -------------------------------------------------------------------------------- /crewai-sequential-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-sequential-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crewai-sequential-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | setuptools = "*" 15 | python-decouple = "*" 16 | langchain-community = "*" 17 | langchain_groq = "*" 18 | 19 | [[tool.poetry.packages]] 20 | include = "*.py" 21 | 22 | [build-system] 23 | requires = ["poetry-core"] 24 | build-backend = "poetry.core.masonry.api" 25 | -------------------------------------------------------------------------------- /crewai-sequential-ollama2-quickstart/CHEATSHEET.md: -------------------------------------------------------------------------------- 1 | ### Cheatsheet 2 | 3 | 1. [Dowload](https://ollama.com/download) and install [Ollama](https://ollama.com/) or `$ brew install ollama` 4 | 5 | 2. Ensure these are your variables within `crewai-sequential-ollama2-quickstart/.env`: 6 | ```python 7 | OPENAI_API_KEY="NA" 8 | ``` 9 | 10 | 3. `$ pip install poetry` 11 | 12 | 13 | 4. `$ cd crewai-sequential-ollama2-quickstart` 14 | 15 | 16 | 5. `$ poetry install` 17 | 18 | 19 | 6. `$ poetry run python main.py` 20 | 21 | ![03-05-2024_08-32-24](https://github.com/alexfazio/crewAI-quickstart/assets/34505954/e1c25feb-652e-484f-8084-ba1d12920bc7) 22 | -------------------------------------------------------------------------------- /crewai-sequential-ollama3-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-sequential-ollama2-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crewai-sequential-ollama2-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | setuptools = "*" 15 | python-decouple = "*" 16 | langchain-community = "*" 17 | langchain_groq = "*" 18 | ollama = "*" 19 | 20 | [[tool.poetry.packages]] 21 | include = "*.py" 22 | 23 | [build-system] 24 | requires = ["poetry-core"] 25 | build-backend = "poetry.core.masonry.api" 26 | -------------------------------------------------------------------------------- /crewai-hierarchical-quickstart/output.log: -------------------------------------------------------------------------------- 1 | agent=Crew Manager2024-04-25 11:34:56: task= 2 | A clear, concise statement of what the task entails. 3 | --- 4 | VARIABLE 1: "('c',)" 5 | VARIABLE 2: "('c',)" 6 | VARIABLE 3: "('c',)" 7 | Add more variables if needed... 8 | 2024-04-25 11:34:56: status=started 9 | agent=Crew Manager2024-04-25 11:35:39: task=my best complete final answer to the task.2024-04-25 11:35:39: status=completed 10 | agent=Crew Manager2024-04-25 11:35:39: task= 11 | A clear, concise statement of what the task entails. 12 | --- 13 | VARIABLE 1: "('c',)" 14 | VARIABLE 2: "('c',)" 15 | VARIABLE 3: "('c',)" 16 | Add more variables if needed... 17 | 2024-04-25 11:35:39: status=started 18 | -------------------------------------------------------------------------------- /crewai-sequential-ollama2-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-sequential-ollama2-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crewai-sequential-ollama2-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | setuptools = "*" 15 | python-decouple = "*" 16 | python-dotenv = "*" 17 | langchain-community = "*" 18 | langchain_groq = "*" 19 | ollama = "*" 20 | 21 | [[tool.poetry.packages]] 22 | include = "*.py" 23 | 24 | [build-system] 25 | requires = ["poetry-core"] 26 | build-backend = "poetry.core.masonry.api" 27 | -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-streamlit-sequential-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crcrewai-streamlit-sequential-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | streamlit = "*" 15 | pandas = "*" 16 | watchdog = "*" 17 | setuptools = "*" 18 | python-decouple = "*" 19 | langchain-community = "*" 20 | langchain_groq = "*" 21 | langchain-anthropic = "*" 22 | 23 | [[tool.poetry.packages]] 24 | include = "*.py" 25 | 26 | [build-system] 27 | requires = ["poetry-core"] 28 | build-backend = "poetry.core.masonry.api" 29 | -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-streamlit-sequential-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crcrewai-streamlit-sequential-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | streamlit = "*" 15 | pandas = "*" 16 | watchdog = "*" 17 | setuptools = "*" 18 | python-decouple = "*" 19 | langchain-community = "*" 20 | langchain_groq = "*" 21 | langchain-anthropic = "*" 22 | 23 | [[tool.poetry.packages]] 24 | include = "*.py" 25 | 26 | [build-system] 27 | requires = ["poetry-core"] 28 | build-backend = "poetry.core.masonry.api" 29 | -------------------------------------------------------------------------------- /crewai-hierarchical-quickstart/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai-hierarchical-quickstart" 3 | version = "0.0.1" 4 | description = "" 5 | authors = ["Alex Fazio "] 6 | 7 | [tool.poetry.scripts] 8 | crewai-hierarchical-quickstart = "main:main" 9 | 10 | [tool.poetry.dependencies] 11 | python = ">=3.10,<=3.13" 12 | pydantic = "*" 13 | crewai = "*" 14 | setuptools = "*" 15 | python-decouple = "*" 16 | langchain-community = "*" 17 | # ↑ uncomment to use OpenAI API 18 | # langchain_groq = "*" 19 | # ↑ uncomment to use Groq's API 20 | # langchain-anthropic = "*" 21 | # ↑ uncomment to use Anthropic's API 22 | 23 | [[tool.poetry.packages]] 24 | include = "*.py" 25 | 26 | [build-system] 27 | requires = ["poetry-core"] 28 | build-backend = "poetry.core.masonry.api" 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Alex Fazio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/stream.py: -------------------------------------------------------------------------------- 1 | import re 2 | import streamlit as st 3 | 4 | # display the console processing on streamlit UI 5 | class StreamToStreamlit: 6 | def __init__(self, expander): 7 | self.expander = expander 8 | self.buffer = [] 9 | self.colors = ['red', 'green', 'blue', 'orange'] # Define a list of colors 10 | self.color_index = 0 # Initialize color index 11 | 12 | def write(self, data): 13 | # Filter out ANSI escape codes using a regular expression 14 | cleaned_data = re.sub(r'\x1B\[[0-9;]*[mK]', '', data) 15 | 16 | # Check if the data contains 'task' information 17 | task_match_object = re.search(r'\"task\"\s*:\s*\"(.*?)\"', cleaned_data, re.IGNORECASE) 18 | task_match_input = re.search(r'task\s*:\s*([^\n]*)', cleaned_data, re.IGNORECASE) 19 | task_value = None 20 | if task_match_object: 21 | task_value = task_match_object.group(1) 22 | elif task_match_input: 23 | task_value = task_match_input.group(1).strip() 24 | 25 | if task_value: 26 | st.info(":robot_face: " + task_value) 27 | 28 | # Check if the text contains the specified phrase and apply color 29 | if "Entering new CrewAgentExecutor chain" in cleaned_data: 30 | # Apply different color and switch color index 31 | self.color_index = (self.color_index + 1) % len( 32 | self.colors) # Increment color index and wrap around if necessary 33 | 34 | cleaned_data = cleaned_data.replace("Entering new CrewAgentExecutor chain", 35 | f":{self.colors[self.color_index]}[Entering new CrewAgentExecutor chain]") 36 | 37 | if "Market Research Analyst" in cleaned_data: 38 | # Apply different color 39 | cleaned_data = cleaned_data.replace("Market Research Analyst", 40 | f":{self.colors[self.color_index]}[Market Research Analyst]") 41 | if "Business Development Consultant" in cleaned_data: 42 | cleaned_data = cleaned_data.replace("Business Development Consultant", 43 | f":{self.colors[self.color_index]}[Business Development Consultant]") 44 | if "Technology Expert" in cleaned_data: 45 | cleaned_data = cleaned_data.replace("Technology Expert", 46 | f":{self.colors[self.color_index]}[Technology Expert]") 47 | if "Finished chain." in cleaned_data: 48 | cleaned_data = cleaned_data.replace("Finished chain.", f":{self.colors[self.color_index]}[Finished chain.]") 49 | 50 | self.buffer.append(cleaned_data) 51 | if "\n" in data: 52 | self.expander.markdown(''.join(self.buffer), unsafe_allow_html=True) 53 | self.buffer = [] -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/stream.py: -------------------------------------------------------------------------------- 1 | import re 2 | import streamlit as st 3 | 4 | # display the console processing on streamlit UI 5 | class StreamToStreamlit: 6 | def __init__(self, expander): 7 | self.expander = expander 8 | self.buffer = [] 9 | self.colors = ['red', 'green', 'blue', 'orange'] # Define a list of colors 10 | self.color_index = 0 # Initialize color index 11 | 12 | def write(self, data): 13 | # Filter out ANSI escape codes using a regular expression 14 | cleaned_data = re.sub(r'\x1B\[[0-9;]*[mK]', '', data) 15 | 16 | # Check if the data contains 'task' information 17 | task_match_object = re.search(r'\"task\"\s*:\s*\"(.*?)\"', cleaned_data, re.IGNORECASE) 18 | task_match_input = re.search(r'task\s*:\s*([^\n]*)', cleaned_data, re.IGNORECASE) 19 | task_value = None 20 | if task_match_object: 21 | task_value = task_match_object.group(1) 22 | elif task_match_input: 23 | task_value = task_match_input.group(1).strip() 24 | 25 | if task_value: 26 | st.info(":robot_face: " + task_value) 27 | 28 | # Check if the text contains the specified phrase and apply color 29 | if "Entering new CrewAgentExecutor chain" in cleaned_data: 30 | # Apply different color and switch color index 31 | self.color_index = (self.color_index + 1) % len( 32 | self.colors) # Increment color index and wrap around if necessary 33 | 34 | cleaned_data = cleaned_data.replace("Entering new CrewAgentExecutor chain", 35 | f":{self.colors[self.color_index]}[Entering new CrewAgentExecutor chain]") 36 | 37 | if "Market Research Analyst" in cleaned_data: 38 | # Apply different color 39 | cleaned_data = cleaned_data.replace("Market Research Analyst", 40 | f":{self.colors[self.color_index]}[Market Research Analyst]") 41 | if "Business Development Consultant" in cleaned_data: 42 | cleaned_data = cleaned_data.replace("Business Development Consultant", 43 | f":{self.colors[self.color_index]}[Business Development Consultant]") 44 | if "Technology Expert" in cleaned_data: 45 | cleaned_data = cleaned_data.replace("Technology Expert", 46 | f":{self.colors[self.color_index]}[Technology Expert]") 47 | if "Finished chain." in cleaned_data: 48 | cleaned_data = cleaned_data.replace("Finished chain.", f":{self.colors[self.color_index]}[Finished chain.]") 49 | 50 | self.buffer.append(cleaned_data) 51 | if "\n" in data: 52 | self.expander.markdown(''.join(self.buffer), unsafe_allow_html=True) 53 | self.buffer = [] -------------------------------------------------------------------------------- /crewai_custom_tool_template_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyOjpmTOzsJP4UAmZbt4YoBk", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "Github repo: https://github.com/alexfazio/crewai-quickstart\n", 34 | "\n", 35 | "Docs: https://docs.crewai.com/\n", 36 | "\n", 37 | "- Create a custom tool using crewAi's [BaseTool](https://docs.crewai.com/core-concepts/Tools/#subclassing-basetool) class\n", 38 | "\n", 39 | "Requirements:\n", 40 | "- [OpenAI](https://platform.openai.com/playground)/[Groq](https://console.groq.com/settings/organization)/[Anthropic](https://console.anthropic.com/dashboard) API Key\n", 41 | "- Serper API Key: https://serper.dev/" 42 | ], 43 | "metadata": { 44 | "id": "UcsQt3pIKXMe" 45 | } 46 | }, 47 | { 48 | "cell_type": "code", 49 | "source": [ 50 | "# To create a personalized tool, inherit from BaseTool and define the necessary attributes and the _run method.\n", 51 | "\n", 52 | "from crewai_tools import BaseTool" 53 | ], 54 | "metadata": { 55 | "id": "QW3M0rxxJYNG" 56 | }, 57 | "execution_count": null, 58 | "outputs": [] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "source": [ 63 | "Every Tool needs to have a name and a description.\n", 64 | "\n", 65 | "When running locally, you can customize the code with your logic in the _run function." 66 | ], 67 | "metadata": { 68 | "id": "NAReTLDNJguV" 69 | } 70 | }, 71 | { 72 | "cell_type": "code", 73 | "source": [ 74 | "class MyCustomTool(BaseTool):\n", 75 | " name: str = \"Name of my tool\"\n", 76 | " description: str = \"What this tool does. It's vital for effective utilization.\"\n", 77 | "\n", 78 | " def _run(self, argument: str) -> str:\n", 79 | " # Your tool's logic here\n", 80 | " return \"Tool's result\"" 81 | ], 82 | "metadata": { 83 | "id": "XfXeWU6gJVwM" 84 | }, 85 | "execution_count": null, 86 | "outputs": [] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": { 92 | "id": "Nj0WHrYDJQDh" 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "sentiment_analysis_tool = SentimentAnalysisTool()" 97 | ] 98 | } 99 | ] 100 | } -------------------------------------------------------------------------------- /crewai-sequential-quickstart/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from crewai import Agent, Task, Crew, Process 3 | from decouple import config 4 | from textwrap import dedent 5 | from langchain_groq import ChatGroq 6 | 7 | # Add API key within `./.env.example.example.example.example` file 8 | os.environ["GROQ_API_KEY"] = config("GROQ_API_KEY") 9 | # os.environ["OPENAI_API_KEY"] = config("OPENAI_API_KEY") 10 | # ↑ uncomment to use OpenAI API 11 | 12 | 13 | print("## Welcome to the YOUR_CREW_NAME") 14 | print('-------------------------------------------') 15 | var_1 = input(dedent(( 16 | f"""What is the to pass to your crew?\n 17 | """))), 18 | var_2 = input(dedent(( 19 | f"""What is the to pass to your crew?\n 20 | """))), 21 | var_3 = input(dedent(( 22 | f"""What is the to pass to your crew?\n 23 | """))), 24 | print("-------------------------------") 25 | 26 | # Agent Definitions 27 | 28 | agent_1 = Agent( 29 | role=dedent(( 30 | f""" 31 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 32 | """)), 33 | backstory=dedent(( 34 | f""" 35 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 36 | """)), 37 | goal=dedent(( 38 | f""" 39 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 40 | """)), 41 | allow_delegation=False, 42 | verbose=True, 43 | # ↑ Whether the agent execution should be in verbose mode 44 | max_iter=3, 45 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 46 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 47 | # ↑ uncomment to use OpenAI API + "gpt-4" 48 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 49 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 50 | llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 51 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 52 | ) 53 | 54 | agent_2 = Agent( 55 | role=dedent(( 56 | f""" 57 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 58 | """)), 59 | backstory=dedent(( 60 | f""" 61 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 62 | """)), 63 | goal=dedent(( 64 | f""" 65 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 66 | """)), 67 | allow_delegation=False, 68 | verbose=True, 69 | # ↑ Whether the agent execution should be in verbose mode 70 | max_iter=3, 71 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 72 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8), 73 | # ↑ uncomment to use OpenAI API + "gpt-4" 74 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 75 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 76 | llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 77 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 78 | ) 79 | 80 | agent_3 = Agent( 81 | role=dedent(( 82 | f""" 83 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 84 | """)), 85 | backstory=dedent(( 86 | f""" 87 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 88 | """)), 89 | goal=dedent(( 90 | f""" 91 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 92 | """)), 93 | allow_delegation=False, 94 | verbose=True, 95 | # ↑ Whether the agent execution should be in verbose mode 96 | max_iter=3, 97 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 98 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8), 99 | # ↑ uncomment to use OpenAI API + "gpt-4" 100 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 101 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 102 | llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 103 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 104 | ) 105 | 106 | # Task Definitions 107 | 108 | task_1 = Task( 109 | description=dedent(( 110 | f""" 111 | A clear, concise statement of what the task entails. 112 | --- 113 | VARIABLE 1: "{var_1}" 114 | VARIABLE 2: "{var_2}" 115 | VARIABLE 3: "{var_3}" 116 | Add more variables if needed... 117 | """)), 118 | expected_output=dedent(( 119 | f""" 120 | A detailed description of what the task's completion looks like. 121 | """)), 122 | agent=agent_1, 123 | ) 124 | 125 | task_2 = Task( 126 | description=dedent(( 127 | f""" 128 | A clear, concise statement of what the task entails. 129 | --- 130 | VARIABLE 1: "{var_1}" 131 | VARIABLE 2: "{var_2}" 132 | VARIABLE 3: "{var_3}" 133 | Add more variables if needed... 134 | """)), 135 | expected_output=dedent(( 136 | f""" 137 | A detailed description of what the task's completion looks like. 138 | """)), 139 | agent=agent_2, 140 | context=[task_1], 141 | # ↑ specify which task's output should be used as context for subsequent tasks 142 | ) 143 | 144 | task_3 = Task( 145 | description=dedent(( 146 | f""" 147 | A clear, concise statement of what the task entails. 148 | --- 149 | VARIABLE 1: "{var_1}" 150 | VARIABLE 2: "{var_2}" 151 | VARIABLE 3: "{var_3}" 152 | Add more variables if needed... 153 | """)), 154 | expected_output=dedent(( 155 | f""" 156 | A detailed description of what the task's completion looks like. 157 | """)), 158 | agent=agent_3, 159 | context=[task_2], 160 | # ↑ specify which task's output should be used as context for subsequent tasks 161 | ) 162 | 163 | 164 | # Get your crew to work! 165 | 166 | def main(): 167 | # Instantiate your crew with a sequential process 168 | crew = Crew( 169 | agents=[agent_1, agent_2, agent_3], 170 | tasks=[task_1, task_2, task_3], 171 | verbose=True, # You can set it to True or False 172 | # ↑ indicates the verbosity level for logging during execution. 173 | process=Process.sequential 174 | # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical). 175 | ) 176 | 177 | result = crew.kickoff() 178 | print(dedent(f"""\n\n########################""")) 179 | print(dedent(f"""## Here is your custom crew run result:""")) 180 | print(dedent(f"""########################\n""")) 181 | print(result) 182 | 183 | if __name__ == "__main__": 184 | main() 185 | -------------------------------------------------------------------------------- /crewai-sequential-ollama2-quickstart/main.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent, Task, Crew, Process 2 | from textwrap import dedent 3 | import ollama 4 | from dotenv import load_dotenv 5 | # from langchain_groq import ChatGroq 6 | # ↑ uncomment to use Groq's API 7 | # from langchain_community.llms import Ollama 8 | from langchain_openai import ChatOpenAI 9 | from langchain_community.llms import Ollama 10 | 11 | # Add API keys within `./.env.example.example.example.example` file 12 | load_dotenv() 13 | 14 | modelfile=''' 15 | FROM llama2 16 | # Set parameters 17 | PARAMETER temperature 0.8 18 | PARAMETER stop Result 19 | # Sets a custom system message to specify the behavior of the chat assistant 20 | # Leaving it blank for now. 21 | SYSTEM """""" 22 | # More guidance on customising your `.modelfile` ↓ 23 | # here: https://tinyurl.com/2688vcnx 24 | # and here: https://tinyurl.com/29e4wmv8 25 | ''' 26 | 27 | ollama.create(model='crewai-llama2', modelfile=modelfile) 28 | 29 | ollama2 = Ollama(model="crewai-llama2") 30 | 31 | print("## Welcome to the YOUR_CREW_NAME") 32 | print('-------------------------------------------') 33 | var_1 = input(dedent(( 34 | f"""What is the to pass to your crew?\n 35 | """))), 36 | var_2 = input(dedent(( 37 | f"""What is the to pass to your crew?\n 38 | """))), 39 | var_3 = input(dedent(( 40 | f"""What is the to pass to your crew?\n 41 | """))), 42 | print("-------------------------------") 43 | 44 | # Agent Definitions 45 | 46 | agent_1 = Agent( 47 | role=dedent(( 48 | f""" 49 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 50 | """)), 51 | backstory=dedent(( 52 | f""" 53 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 54 | """)), 55 | goal=dedent(( 56 | f""" 57 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 58 | """)), 59 | allow_delegation=False, 60 | verbose=True, 61 | # ↑ Whether the agent execution should be in verbose mode 62 | max_iter=3, 63 | llm = ollama2 64 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 65 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 66 | # ↑ uncomment to use OpenAI API + "gpt-4" 67 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 68 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 69 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 70 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 71 | ) 72 | 73 | agent_2 = Agent( 74 | role=dedent(( 75 | f""" 76 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 77 | """)), 78 | backstory=dedent(( 79 | f""" 80 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 81 | """)), 82 | goal=dedent(( 83 | f""" 84 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 85 | """)), 86 | allow_delegation=False, 87 | verbose=True, 88 | # ↑ Whether the agent execution should be in verbose mode 89 | max_iter=3, 90 | llm = ollama2 91 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 92 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 93 | # ↑ uncomment to use OpenAI API + "gpt-4" 94 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 95 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 96 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 97 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 98 | ) 99 | 100 | agent_3 = Agent( 101 | role=dedent(( 102 | f""" 103 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 104 | """)), 105 | backstory=dedent(( 106 | f""" 107 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 108 | """)), 109 | goal=dedent(( 110 | f""" 111 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 112 | """)), 113 | allow_delegation=False, 114 | verbose=True, 115 | # ↑ Whether the agent execution should be in verbose mode 116 | max_iter=3, 117 | llm = ollama2 118 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 119 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 120 | # ↑ uncomment to use OpenAI API + "gpt-4" 121 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 122 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 123 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 124 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 125 | ) 126 | 127 | # Task Definitions 128 | 129 | task_1 = Task( 130 | description=dedent(( 131 | f""" 132 | A clear, concise statement of what the task entails. 133 | --- 134 | VARIABLE 1: "{var_1}" 135 | VARIABLE 2: "{var_2}" 136 | VARIABLE 3: "{var_3}" 137 | Add more variables if needed... 138 | """)), 139 | expected_output=dedent(( 140 | f""" 141 | A detailed description of what the task's completion looks like. 142 | """)), 143 | agent=agent_1, 144 | ) 145 | 146 | task_2 = Task( 147 | description=dedent(( 148 | f""" 149 | A clear, concise statement of what the task entails. 150 | --- 151 | VARIABLE 1: "{var_1}" 152 | VARIABLE 2: "{var_2}" 153 | VARIABLE 3: "{var_3}" 154 | Add more variables if needed... 155 | """)), 156 | expected_output=dedent(( 157 | f""" 158 | A detailed description of what the task's completion looks like. 159 | """)), 160 | agent=agent_2, 161 | context=[task_1], 162 | # ↑ specify which task's output should be used as context for subsequent tasks 163 | ) 164 | 165 | task_3 = Task( 166 | description=dedent(( 167 | f""" 168 | A clear, concise statement of what the task entails. 169 | --- 170 | VARIABLE 1: "{var_1}" 171 | VARIABLE 2: "{var_2}" 172 | VARIABLE 3: "{var_3}" 173 | Add more variables if needed... 174 | """)), 175 | expected_output=dedent(( 176 | f""" 177 | A detailed description of what the task's completion looks like. 178 | """)), 179 | agent=agent_3, 180 | context=[task_2], 181 | # ↑ specify which task's output should be used as context for subsequent tasks 182 | ) 183 | 184 | 185 | # Get your crew to work! 186 | 187 | def main(): 188 | # Instantiate your crew with a sequential process 189 | crew = Crew( 190 | agents=[agent_1, agent_2, agent_3], 191 | tasks=[task_1, task_2, task_3], 192 | verbose=True, # You can set it to True or False 193 | # ↑ indicates the verbosity level for logging during execution. 194 | process=Process.sequential 195 | # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical). 196 | ) 197 | 198 | result = crew.kickoff() 199 | print(dedent(f"""\n\n########################""")) 200 | print(dedent(f"""## Here is your custom crew run result:""")) 201 | print(dedent(f"""########################\n""")) 202 | print(result) 203 | 204 | if __name__ == "__main__": 205 | main() 206 | -------------------------------------------------------------------------------- /crewai-sequential-ollama3-quickstart/main.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent, Task, Crew, Process 2 | from textwrap import dedent 3 | import ollama 4 | from dotenv import load_dotenv 5 | # from langchain_groq import ChatGroq 6 | # ↑ uncomment to use Groq's API 7 | # from langchain_community.llms import Ollama 8 | from langchain_openai import ChatOpenAI 9 | from langchain_community.llms import Ollama 10 | 11 | # Add API keys within `./.env.example.example.example.example` file 12 | load_dotenv() 13 | 14 | modelfile=''' 15 | FROM llama3 16 | # Set parameters 17 | PARAMETER temperature 0.8 18 | PARAMETER stop Result 19 | # Sets a custom system message to specify the behavior of the chat assistant 20 | # Leaving it blank for now. 21 | SYSTEM """""" 22 | # More guidance on customising your `.modelfile` ↓ 23 | # here: https://tinyurl.com/2688vcnx 24 | # and here: https://tinyurl.com/29e4wmv8 25 | ''' 26 | 27 | ollama.create(model='crewai-llama3', modelfile=modelfile) 28 | 29 | ollama3 = Ollama(model="crewai-llama3") 30 | 31 | print("## Welcome to the YOUR_CREW_NAME") 32 | print('-------------------------------------------') 33 | var_1 = input(dedent(( 34 | f"""What is the to pass to your crew?\n 35 | """))), 36 | var_2 = input(dedent(( 37 | f"""What is the to pass to your crew?\n 38 | """))), 39 | var_3 = input(dedent(( 40 | f"""What is the to pass to your crew?\n 41 | """))), 42 | print("-------------------------------") 43 | 44 | # Agent Definitions 45 | 46 | agent_1 = Agent( 47 | role=dedent(( 48 | f""" 49 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 50 | """)), 51 | backstory=dedent(( 52 | f""" 53 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 54 | """)), 55 | goal=dedent(( 56 | f""" 57 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 58 | """)), 59 | allow_delegation=False, 60 | verbose=True, 61 | # ↑ Whether the agent execution should be in verbose mode 62 | max_iter=3, 63 | llm = ollama3 64 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 65 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 66 | # ↑ uncomment to use OpenAI API + "gpt-4" 67 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 68 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 69 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 70 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 71 | ) 72 | 73 | agent_2 = Agent( 74 | role=dedent(( 75 | f""" 76 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 77 | """)), 78 | backstory=dedent(( 79 | f""" 80 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 81 | """)), 82 | goal=dedent(( 83 | f""" 84 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 85 | """)), 86 | allow_delegation=False, 87 | verbose=True, 88 | # ↑ Whether the agent execution should be in verbose mode 89 | max_iter=3, 90 | llm = ollama3 91 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 92 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 93 | # ↑ uncomment to use OpenAI API + "gpt-4" 94 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 95 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 96 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 97 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 98 | ) 99 | 100 | agent_3 = Agent( 101 | role=dedent(( 102 | f""" 103 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 104 | """)), 105 | backstory=dedent(( 106 | f""" 107 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 108 | """)), 109 | goal=dedent(( 110 | f""" 111 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 112 | """)), 113 | allow_delegation=False, 114 | verbose=True, 115 | # ↑ Whether the agent execution should be in verbose mode 116 | max_iter=3, 117 | llm = ollama3 118 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 119 | # llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 120 | # ↑ uncomment to use OpenAI API + "gpt-4" 121 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 122 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 123 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 124 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 125 | ) 126 | 127 | # Task Definitions 128 | 129 | task_1 = Task( 130 | description=dedent(( 131 | f""" 132 | A clear, concise statement of what the task entails. 133 | --- 134 | VARIABLE 1: "{var_1}" 135 | VARIABLE 2: "{var_2}" 136 | VARIABLE 3: "{var_3}" 137 | Add more variables if needed... 138 | """)), 139 | expected_output=dedent(( 140 | f""" 141 | A detailed description of what the task's completion looks like. 142 | """)), 143 | agent=agent_1, 144 | ) 145 | 146 | task_2 = Task( 147 | description=dedent(( 148 | f""" 149 | A clear, concise statement of what the task entails. 150 | --- 151 | VARIABLE 1: "{var_1}" 152 | VARIABLE 2: "{var_2}" 153 | VARIABLE 3: "{var_3}" 154 | Add more variables if needed... 155 | """)), 156 | expected_output=dedent(( 157 | f""" 158 | A detailed description of what the task's completion looks like. 159 | """)), 160 | agent=agent_2, 161 | context=[task_1], 162 | # ↑ specify which task's output should be used as context for subsequent tasks 163 | ) 164 | 165 | task_3 = Task( 166 | description=dedent(( 167 | f""" 168 | A clear, concise statement of what the task entails. 169 | --- 170 | VARIABLE 1: "{var_1}" 171 | VARIABLE 2: "{var_2}" 172 | VARIABLE 3: "{var_3}" 173 | Add more variables if needed... 174 | """)), 175 | expected_output=dedent(( 176 | f""" 177 | A detailed description of what the task's completion looks like. 178 | """)), 179 | agent=agent_3, 180 | context=[task_2], 181 | # ↑ specify which task's output should be used as context for subsequent tasks 182 | ) 183 | 184 | 185 | # Get your crew to work! 186 | 187 | def main(): 188 | # Instantiate your crew with a sequential process 189 | crew = Crew( 190 | agents=[agent_1, agent_2, agent_3], 191 | tasks=[task_1, task_2, task_3], 192 | verbose=True, # You can set it to True or False 193 | # ↑ indicates the verbosity level for logging during execution. 194 | process=Process.sequential 195 | # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical). 196 | ) 197 | 198 | result = crew.kickoff() 199 | print(dedent(f"""\n\n########################""")) 200 | print(dedent(f"""## Here is your custom crew run result:""")) 201 | print(dedent(f"""########################\n""")) 202 | print(result) 203 | 204 | if __name__ == "__main__": 205 | main() 206 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | OpenAI Cookbook Logo 5 | 6 | 7 | 8 | [![Build GitHub Docs On Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new/?repo=crewAI-quickstart) 9 | 10 | CrewAI Quickstart offers a cookbook of code templates and guides designed to help developers build with CrewAI. It includes easily copy-able code snippets that you can seamlessly integrate into your own projects. 11 | 12 | 13 | ## Prerequisites 14 | 15 | To make the most of the examples in this quickstart guide, you'll need to be familiar with CrewAI. We recommend reviewing the official CrewAI documentation at https://docs.crewai.com/ to understand the basic concepts and functionality. You'll also need an API key from one of the major Language Model providers such as Anthropic, OpenAI, Groq, or Cohere. 16 | 17 | 18 | ## Table of Contents 19 | 20 | - [Quickstart Templates](#quickstart-templates) 21 | - [Basic Notebooks](#basic-notebooks) 22 | - [Notebooks with Tool Use](#notebooks-with-tool-use) 23 | - [Extra Notebooks](#extra-notebooks) 24 | - [Python Scripts](#python-scripts) 25 | - [GUI with Streamlit](#gui-with-streamlit) 26 | - [Local LLMs](#local-llms) 27 | - [Contributing](#contributing) 28 | - [Credits](#credits) 29 | - [License](#license) 30 | 31 | ## Quickstart Templates 32 | 33 | ### Basic Notebooks 34 | 35 | - [Sequential Google Colab Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_quickstart.ipynb) 36 | - [Hierarchical Google Colab Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_hierarchical_quickstart.ipynb) 37 | 38 | ### Notebooks with Tool Use 39 | 40 | | Tool Name | Description | Notebook Link | 41 | |-----------|-------------|---------------| 42 | | TXTSearchTool | RAG tool for searching within text (.txt) files | [Sequential `.txt` Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_TXTSearchTool_quickstart.ipynb) | 43 | | CodeDocsSearchTool | RAG tool for searching through code documentation | [Sequential Code Docs Search Tool Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_CodeDocsSearchTool_quickstart.ipynb) | 44 | | CodeInterpreterTool | Tool for interpreting Python code | [Sequential Code Interpreter Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_CodeInterpreterTool_quickstart.ipynb) | 45 | | ComposioTool | Enables use of Composio tools | [Sequential Composio SDK Tool Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_composio_core_quickstart.ipynb) | 46 | | CSVSearchTool | RAG tool for searching within CSV files | [Sequential CSV lookup Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_CSVSearchTool_quickstart.ipynb) | 47 | | DirectoryReadTool | Facilitates reading of directory structures | [Sequential Directory Read Tool Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_DirectoryReadTool_quickstart.ipynb) | 48 | | DOCXSearchTool | RAG tool for searching within DOCX documents | [Sequential DOCX Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_DOCXSearchTool_quickstart.ipynb) | 49 | | GithubSearchTool | RAG tool for searching within GitHub repositories | [Sequential GitHub Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_GithubSearchTool_quickstart.ipynb) | 50 | | BrowserbaseLoadTool | Tool for interacting with web browsers | [Sequential Headless Browser Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_BrowserbaseLoadTool_quickstart.ipynb) | 51 | | JSONSearchTool | RAG tool for searching within JSON files | [Sequential JSON Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_JSONSearchTool_quickstart.ipynb) | 52 | | MDXSearchTool | RAG tool for searching within Markdown (MDX) files | [Sequential MDX Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_MDXSearchTool_quickstart.ipynb) | 53 | | PDFSearchTool | RAG tool for searching within PDF documents | [Sequential PDF Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_PDFSearchTool_quickstart.ipynb) | 54 | | PGSearchTool | RAG tool for searching within PostgreSQL databases | [Sequential PostgreSQL Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_PGSearchTool_quickstart.ipynb) | 55 | | ScrapeWebsiteTool | Facilitates scraping entire websites | [Sequential Web Scraping Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_ScrapeWebsiteTool_quickstart.ipynb) | 56 | | SeleniumScrapingTool | Web scraping tool using Selenium | [Sequential Web Scraping (Selenium) Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_SeleniumScrapingTool_quickstart.ipynb) | 57 | | SerperDevTool | Specialized tool for development purposes | [Sequential Web Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_SerperDevTool_quickstart.ipynb) | 58 | | WebsiteSearchTool | RAG tool for searching website content | [Sequential Website Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_WebsiteSearchTool_quickstart.ipynb) | 59 | | XMLSearchTool | RAG tool for searching within XML files | [Sequential XML Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_XMLSearchTool_quickstart.ipynb) | 60 | | YoutubeChannelSearchTool | RAG tool for searching within YouTube channels | [Sequential YouTube Channel Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_YoutubeChannelSearchTool_quickstart.ipynb) | 61 | | YoutubeVideoSearchTool | RAG tool for searching within YouTube videos | [Sequential YouTube Video Search Notebook](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_sequential_YoutubeVideoSearchTool_quickstart.ipynb) | 62 | 63 | ### Extra Notebooks 64 | 65 | - [Custom Tool Template](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai_custom_tool_template_quickstart.ipynb) 66 | - [Example Task: Event Planning](https://github.com/alexfazio/crewAI-quickstart/blob/main/crewai-example-task-event-planning-quickstart.ipynb) 67 | 68 | ### Python Scripts 69 | 70 | - [Sequential](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-sequential-quickstart) 71 | - [Hierarchical](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-hierarchical-quickstart) 72 | 73 | ### GUI with Streamlit 74 | 75 | - [Streamlit GUI Sequential](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-streamlit-sequential-quickstart) 76 | - [Streamlit GUI Hierarchical](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-hierarchical-quickstart) 77 | 78 | ### Local LLMs 79 | 80 | - [Sequential Ollama with `llama2`](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-sequential-ollama2-quickstart) 81 | - [Sequential Ollama with `llama3`](https://github.com/alexfazio/crewAI-quickstart/tree/main/crewai-sequential-ollama3-quickstart) 82 | 83 | ## Contributing 84 | 85 | The CrewAI Quickstart thrives on the contributions of the developer community. We value your input, whether it's submitting an idea, fixing a typo, adding a new guide, or improving an existing one. By contributing, you help make this resource even more valuable for everyone. 86 | 87 | To avoid duplication of efforts, please review the existing issues and pull requests before contributing. 88 | 89 | If you have ideas for new examples or guides, share them on the [issues page](https://github.com/alexfazio/crewAI-quickstart/issues). 90 | 91 | ## Credits 92 | 93 | Thanks to [@AbubakrChan](https://github.com/AbubakrChan) for his contribution to the **🖼️ GUI w/ Streamlit `.py`** templates. 94 | 95 | ## License 96 | 97 | This project is licensed under the [MIT License](LICENSE). 98 | 99 | Happy learning and coding with CrewAI! 100 | -------------------------------------------------------------------------------- /crewai-streamlit-sequential-quickstart/app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import sys 3 | from crewai import Agent, Task, Crew, Process 4 | from langchain_groq import ChatGroq 5 | from langchain_anthropic import ChatAnthropic 6 | from langchain_community.chat_models import ChatOpenAI 7 | from stream import StreamToStreamlit 8 | from textwrap import dedent 9 | 10 | 11 | def main(): 12 | st.sidebar.title('Customization') 13 | api = st.sidebar.selectbox( 14 | 'Choose an API', 15 | ['Groq', 'OpenAI', 'Anthropic'] 16 | ) 17 | 18 | api_key = st.sidebar.text_input('Enter API Key', 'gsk-') 19 | 20 | temp = st.sidebar.slider("Model Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.1) 21 | 22 | if api == 'Groq': 23 | model = st.sidebar.selectbox( 24 | 'Choose a model', 25 | ['llama3-70b-8192', 'mixtral-8x7b-32768', 'gemma-7b-it'] 26 | ) 27 | 28 | llm = ChatGroq( 29 | temperature=temp, 30 | model_name=model, 31 | groq_api_key=api_key 32 | ) 33 | 34 | if api == 'OpenAI': 35 | model = st.sidebar.selectbox( 36 | 'Choose a model', 37 | ['gpt-4-turbo', 'gpt-4-1106-preview', 'gpt-3.5-turbo-0125'] 38 | ) 39 | 40 | llm = ChatOpenAI( 41 | temperature=temp, 42 | openai_api_key=api_key, 43 | model_name=model 44 | ) 45 | 46 | if api == 'Anthropic': 47 | model = st.sidebar.selectbox( 48 | 'Choose a model', 49 | ['claude-3-opus-20240229', 'claude-3-sonnet-20240229', 'claude-3-haiku-20240307'] 50 | ) 51 | 52 | llm = ChatAnthropic( 53 | temperature=temp, 54 | anthropic_api_key=api_key, 55 | model_name=model 56 | ) 57 | 58 | # Streamlit UI 59 | st.title('My New Crew') 60 | multiline_text = """ 61 | This crew does something 62 | """ 63 | 64 | st.markdown(multiline_text, unsafe_allow_html=True) 65 | 66 | # Display the Groq logo 67 | spacer, col = st.columns([5, 1]) 68 | with col: 69 | st.image('crewai-logo.png') 70 | 71 | agent_1 = Agent( 72 | role=dedent(( 73 | f""" 74 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 75 | """)), 76 | backstory=dedent(( 77 | f""" 78 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 79 | """)), 80 | goal=dedent(( 81 | f""" 82 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 83 | """)), 84 | allow_delegation=False, 85 | verbose=True, 86 | # ↑ Whether the agent execution should be in verbose mode 87 | max_iter=3, 88 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 89 | llm=llm, 90 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 91 | ) 92 | 93 | agent_2 = Agent( 94 | role=dedent(( 95 | f""" 96 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 97 | """)), 98 | backstory=dedent(( 99 | f""" 100 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 101 | """)), 102 | goal=dedent(( 103 | f""" 104 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 105 | """)), 106 | allow_delegation=False, 107 | verbose=True, 108 | # ↑ Whether the agent execution should be in verbose mode 109 | max_iter=3, 110 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 111 | llm=llm, 112 | ) 113 | 114 | agent_3 = Agent( 115 | role=dedent(( 116 | f""" 117 | Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 118 | """)), 119 | backstory=dedent(( 120 | f""" 121 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 122 | """)), 123 | goal=dedent(( 124 | f""" 125 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 126 | """)), 127 | allow_delegation=False, 128 | verbose=True, 129 | # ↑ Whether the agent execution should be in verbose mode 130 | max_iter=3, 131 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 132 | llm=llm, 133 | ) 134 | 135 | var_1 = st.text_input("Variable 1:") 136 | var_2 = st.text_input("Variable 2:") 137 | var_3 = st.text_input("Variable 3:") 138 | 139 | if var_1 and var_2 and var_3 and api_key: 140 | if st.button("Start"): 141 | 142 | task_1 = Task( 143 | description=dedent(( 144 | f""" 145 | A clear, concise statement of what the task entails. 146 | --- 147 | VARIABLE 1: "{var_1}" 148 | VARIABLE 2: "{var_2}" 149 | VARIABLE 3: "{var_3}" 150 | Add more variables if needed... 151 | """)), 152 | expected_output=dedent(( 153 | f""" 154 | A detailed description of what the task's completion looks like. 155 | """)), 156 | agent=agent_1, 157 | ) 158 | 159 | task_2 = Task( 160 | description=dedent(( 161 | f""" 162 | A clear, concise statement of what the task entails. 163 | --- 164 | VARIABLE 1: "{var_1}" 165 | VARIABLE 2: "{var_2}" 166 | VARIABLE 3: "{var_3}" 167 | Add more variables if needed... 168 | """)), 169 | expected_output=dedent(( 170 | f""" 171 | A detailed description of what the task's completion looks like. 172 | """)), 173 | agent=agent_2, 174 | context=[task_1], 175 | # ↑ specify which task's output should be used as context for subsequent tasks 176 | ) 177 | 178 | task_3 = Task( 179 | description=dedent(( 180 | f""" 181 | A clear, concise statement of what the task entails. 182 | --- 183 | VARIABLE 1: "{var_1}" 184 | VARIABLE 2: "{var_2}" 185 | VARIABLE 3: "{var_3}" 186 | Add more variables if needed... 187 | """)), 188 | expected_output=dedent(( 189 | f""" 190 | A detailed description of what the task's completion looks like. 191 | """)), 192 | agent=agent_3, 193 | context=[task_2], 194 | # ↑ specify which task's output should be used as context for subsequent tasks 195 | ) 196 | 197 | crew = Crew( 198 | agents=[agent_1, agent_2, agent_3, ], 199 | tasks=[task_1, task_2, task_3], 200 | verbose=True, # You can set it to True or False 201 | process=Process.sequential 202 | ) 203 | # result = crew.kickoff() 204 | # st.write_stream(result) 205 | 206 | with st.spinner("Generating..."): 207 | # Save the original stdout so we can restore it later 208 | original_stdout = sys.stdout 209 | sys.stdout = StreamToStreamlit(st) 210 | 211 | result = "" 212 | result_container = st.empty() 213 | for delta in crew.kickoff(): 214 | result += delta # Assuming delta is a string, if not, convert it appropriately 215 | result_container.markdown(result) 216 | 217 | 218 | if __name__ == "__main__": 219 | main() 220 | -------------------------------------------------------------------------------- /crewai-hierarchical-quickstart/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from crewai import Agent, Task, Crew, Process 3 | from decouple import config 4 | from textwrap import dedent 5 | from langchain_community.chat_models import ChatOpenAI 6 | # ↑ uncomment to use OpenAI's API 7 | # from langchain_groq import ChatGroq 8 | # ↑ uncomment to use Groq's API 9 | # from langchain_anthropic import ChatAnthropic 10 | # ↑ uncomment to use Antrhopic's API 11 | 12 | # Add API key within `./.env.example.example.example.example` file 13 | os.environ["OPENAI_API_KEY"] = config("OPENAI_API_KEY") 14 | # ↑ uncomment to use OpenAI's API 15 | # os.environ["GROQ_API_KEY"] = config("GROQ_API_KEY") 16 | # ↑ uncomment to use Groq's API 17 | # os.environ["ANTHROPIC_API_KEY"] = config("ANTHROPIC_API_KEY") 18 | # ↑ uncomment to use Anthropic's API 19 | 20 | print("## Welcome to the YOUR_CREW_NAME") 21 | print('-------------------------------------------') 22 | var_1 = input(dedent(( 23 | f"""What is the to pass to your crew?\n 24 | """))), 25 | var_2 = input(dedent(( 26 | f"""What is the to pass to your crew?\n 27 | """))), 28 | var_3 = input(dedent(( 29 | f"""What is the to pass to your crew?\n 30 | """))), 31 | print("-------------------------------") 32 | 33 | # Agent Definitions 34 | 35 | agent_1 = Agent( 36 | role=dedent(( 37 | f""" 38 | Mr. White 39 | """)), 40 | # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 41 | backstory=dedent(( 42 | f""" 43 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 44 | """)), 45 | goal=dedent(( 46 | f""" 47 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 48 | """)), 49 | allow_delegation=True, 50 | verbose=True, 51 | # ↑ Whether the agent execution should be in verbose mode 52 | max_iter=3, 53 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 54 | max_rpm=3, 55 | llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 56 | # ↑ uncomment to use OpenAI API + "gpt-4" 57 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 58 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 59 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 60 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 61 | # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8), 62 | # ↑ uncomment to use Anthropic's API + "claude-3-opus-20240229" 63 | ) 64 | 65 | agent_2 = Agent( 66 | role=dedent(( 67 | f""" 68 | Mr. Orange 69 | """)), 70 | # Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 71 | backstory=dedent(( 72 | f""" 73 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 74 | """)), 75 | goal=dedent(( 76 | f""" 77 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 78 | """)), 79 | allow_delegation=True, 80 | verbose=True, 81 | # ↑ Whether the agent execution should be in verbose mode 82 | max_iter=3, 83 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 84 | max_rpm=3, 85 | llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 86 | # ↑ uncomment to use OpenAI API + "gpt-4" 87 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 88 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 89 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 90 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 91 | # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8), 92 | # ↑ uncomment to use Anthropic's API + "claude-3-opus-20240229" 93 | ) 94 | 95 | agent_3 = Agent( 96 | role=dedent(( 97 | f""" 98 | Mr. Pink 99 | """)), 100 | # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 101 | backstory=dedent(( 102 | f""" 103 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 104 | """)), 105 | goal=dedent(( 106 | f""" 107 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 108 | """)), 109 | allow_delegation=True, 110 | verbose=True, 111 | # ↑ Whether the agent execution should be in verbose mode 112 | max_iter=3, 113 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 114 | max_rpm=3, 115 | llm=ChatOpenAI(model_name="gpt-4", temperature=0.8) 116 | # ↑ uncomment to use OpenAI API + "gpt-4" 117 | # llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 118 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 119 | # llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 120 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 121 | # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8), 122 | # ↑ uncomment to use Anthropic's API + "claude-3-opus-20240229" 123 | ) 124 | 125 | # Task Definitions 126 | 127 | task_1 = Task( 128 | description=dedent(( 129 | f""" 130 | A clear, concise statement of what the task entails. 131 | --- 132 | VARIABLE 1: "{var_1}" 133 | VARIABLE 2: "{var_2}" 134 | VARIABLE 3: "{var_3}" 135 | Add more variables if needed... 136 | """)), 137 | expected_output=dedent(( 138 | f""" 139 | A detailed description of what the task's completion looks like. 140 | """)), 141 | agent=agent_1, 142 | ) 143 | 144 | task_2 = Task( 145 | description=dedent(( 146 | f""" 147 | A clear, concise statement of what the task entails. 148 | --- 149 | VARIABLE 1: "{var_1}" 150 | VARIABLE 2: "{var_2}" 151 | VARIABLE 3: "{var_3}" 152 | Add more variables if needed... 153 | """)), 154 | expected_output=dedent(( 155 | f""" 156 | A detailed description of what the task's completion looks like. 157 | """)), 158 | agent=agent_2, 159 | context=[task_1], 160 | # ↑ specify which task's output should be used as context for subsequent tasks 161 | ) 162 | 163 | task_3 = Task( 164 | description=dedent(( 165 | f""" 166 | A clear, concise statement of what the task entails. 167 | --- 168 | VARIABLE 1: "{var_1}" 169 | VARIABLE 2: "{var_2}" 170 | VARIABLE 3: "{var_3}" 171 | Add more variables if needed... 172 | """)), 173 | expected_output=dedent(( 174 | f""" 175 | A detailed description of what the task's completion looks like. 176 | """)), 177 | agent=agent_3, 178 | context=[task_1, task_2], 179 | # ↑ specify which task's output should be used as context for subsequent tasks 180 | ) 181 | 182 | def main(): 183 | # Instantiate your crew with a sequential process 184 | crew = Crew( 185 | agents=[agent_1, agent_2, agent_3], 186 | tasks=[task_1, task_2, task_3], 187 | verbose=True, # You can set it to True or False 188 | # ↑ indicates the verbosity level for logging during execution. 189 | process=Process.hierarchical, 190 | # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical). 191 | manager_llm=ChatOpenAI(model_name="gpt-4", temperature=0.8), 192 | # ↑ uncomment to use OpenAI API + "gpt-4" 193 | # manager_llm=ChatGroq(temperature=0.8, model_name="mixtral-8x7b-32768"), 194 | # ↑ uncomment to use Groq's API + "llama3-70b-8192" 195 | # manager_llm=ChatGroq(temperature=0.6, model_name="llama3-70b-8192"), 196 | # ↑ uncomment to use Groq's API + "mixtral-8x7b-32768" 197 | # manager_llm=ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8), 198 | # ↑ uncomment to use Anthropic's API + "claude-3-opus-20240229" 199 | output_log_file = "./output.log" 200 | ) 201 | 202 | result = crew.kickoff() 203 | print(dedent(f"""\n\n########################""")) 204 | print(dedent(f"""## Here is your custom crew run result:""")) 205 | print(dedent(f"""########################\n""")) 206 | print(result) 207 | 208 | if __name__ == "__main__": 209 | main() 210 | -------------------------------------------------------------------------------- /crewai-streamlit-hierarchical-quickstart/app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import sys 3 | from crewai import Agent, Task, Crew, Process 4 | from langchain_groq import ChatGroq 5 | from langchain_anthropic import ChatAnthropic 6 | from langchain_community.chat_models import ChatOpenAI 7 | from stream import StreamToStreamlit 8 | from textwrap import dedent 9 | 10 | 11 | def main(): 12 | st.sidebar.title('Customization') 13 | api = st.sidebar.selectbox( 14 | 'Choose an API', 15 | ['Groq', 'OpenAI', 'Anthropic'] 16 | ) 17 | 18 | api_key = st.sidebar.text_input('Enter API Key', 'gsk-') 19 | 20 | temp = st.sidebar.slider("Model Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.1) 21 | 22 | if api == 'Groq': 23 | model = st.sidebar.selectbox( 24 | 'Choose a model', 25 | ['llama3-70b-8192', 'mixtral-8x7b-32768', 'gemma-7b-it'] 26 | ) 27 | 28 | llm = ChatGroq( 29 | temperature=temp, 30 | model_name=model, 31 | groq_api_key=api_key 32 | ) 33 | 34 | if api == 'OpenAI': 35 | model = st.sidebar.selectbox( 36 | 'Choose a model', 37 | ['gpt-4-turbo', 'gpt-4-1106-preview', 'gpt-3.5-turbo-0125'] 38 | ) 39 | 40 | llm = ChatOpenAI( 41 | temperature=temp, 42 | openai_api_key=api_key, 43 | model_name=model 44 | ) 45 | 46 | if api == 'Anthropic': 47 | model = st.sidebar.selectbox( 48 | 'Choose a model', 49 | ['claude-3-opus-20240229', 'claude-3-sonnet-20240229', 'claude-3-haiku-20240307'] 50 | ) 51 | 52 | llm = ChatAnthropic( 53 | temperature=temp, 54 | anthropic_api_key=api_key, 55 | model_name=model 56 | ) 57 | 58 | # Streamlit UI 59 | st.title('My New Crew') 60 | multiline_text = """ 61 | This crew does something 62 | """ 63 | 64 | st.markdown(multiline_text, unsafe_allow_html=True) 65 | 66 | # Display the Groq logo 67 | 68 | spacer, col = st.columns([5, 1]) 69 | with col: 70 | st.image('crewai-logo.png') 71 | 72 | # Agent Definitions 73 | 74 | agent_1 = Agent( 75 | role=dedent(( 76 | f""" 77 | Mr. White 78 | """)), 79 | # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 80 | backstory=dedent(( 81 | f""" 82 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 83 | """)), 84 | goal=dedent(( 85 | f""" 86 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 87 | """)), 88 | allow_delegation=True, 89 | verbose=True, 90 | # ↑ Whether the agent execution should be in verbose mode 91 | max_iter=3, 92 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 93 | max_rpm=3, 94 | llm=llm 95 | ) 96 | 97 | agent_2 = Agent( 98 | role=dedent(( 99 | f""" 100 | Mr. Orange 101 | """)), 102 | # Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 103 | backstory=dedent(( 104 | f""" 105 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 106 | """)), 107 | goal=dedent(( 108 | f""" 109 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 110 | """)), 111 | allow_delegation=True, 112 | verbose=True, 113 | # ↑ Whether the agent execution should be in verbose mode 114 | max_iter=3, 115 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 116 | max_rpm=3, 117 | llm=llm 118 | ) 119 | 120 | agent_3 = Agent( 121 | role=dedent(( 122 | f""" 123 | Mr. Pink 124 | """)), 125 | # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for. 126 | backstory=dedent(( 127 | f""" 128 | Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics. 129 | """)), 130 | goal=dedent(( 131 | f""" 132 | The individual objective that the agent aims to achieve. It guides the agent's decision-making process. 133 | """)), 134 | allow_delegation=True, 135 | verbose=True, 136 | # ↑ Whether the agent execution should be in verbose mode 137 | max_iter=3, 138 | # ↑ maximum number of iterations the agent can perform before being forced to give its best answer 139 | max_rpm=3, 140 | llm=llm 141 | ) 142 | 143 | var_1 = st.text_input("Variable 1:") 144 | var_2 = st.text_input("Variable 2:") 145 | var_3 = st.text_input("Variable 3:") 146 | 147 | if var_1 and var_2 and var_3 and api_key: 148 | if st.button("Start"): 149 | 150 | task_1 = Task( 151 | description=dedent(( 152 | f""" 153 | A clear, concise statement of what the task entails. 154 | --- 155 | VARIABLE 1: "{var_1}" 156 | VARIABLE 2: "{var_2}" 157 | VARIABLE 3: "{var_3}" 158 | Add more variables if needed... 159 | """)), 160 | expected_output=dedent(( 161 | f""" 162 | A detailed description of what the task's completion looks like. 163 | """)), 164 | agent=agent_1, 165 | ) 166 | 167 | task_2 = Task( 168 | description=dedent(( 169 | f""" 170 | A clear, concise statement of what the task entails. 171 | --- 172 | VARIABLE 1: "{var_1}" 173 | VARIABLE 2: "{var_2}" 174 | VARIABLE 3: "{var_3}" 175 | Add more variables if needed... 176 | """)), 177 | expected_output=dedent(( 178 | f""" 179 | A detailed description of what the task's completion looks like. 180 | """)), 181 | agent=agent_2, 182 | context=[task_1], 183 | # ↑ specify which task's output should be used as context for subsequent tasks 184 | ) 185 | 186 | task_3 = Task( 187 | description=dedent(( 188 | f""" 189 | A clear, concise statement of what the task entails. 190 | --- 191 | VARIABLE 1: "{var_1}" 192 | VARIABLE 2: "{var_2}" 193 | VARIABLE 3: "{var_3}" 194 | Add more variables if needed... 195 | """)), 196 | expected_output=dedent(( 197 | f""" 198 | A detailed description of what the task's completion looks like. 199 | """)), 200 | agent=agent_3, 201 | context=[task_1, task_2], 202 | # ↑ specify which task's output should be used as context for subsequent tasks 203 | ) 204 | 205 | # Instantiate your crew with a sequential process 206 | crew = Crew( 207 | agents=[agent_1, agent_2, agent_3], 208 | tasks=[task_1, task_2, task_3], 209 | verbose=True, # You can set it to True or False 210 | # ↑ indicates the verbosity level for logging during execution. 211 | process=Process.hierarchical, 212 | # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical). 213 | manager_llm=llm, 214 | output_log_file="./output.log" 215 | ) 216 | 217 | with st.spinner("Generating..."): 218 | # Save the original stdout so we can restore it later 219 | original_stdout = sys.stdout 220 | sys.stdout = StreamToStreamlit(st) 221 | 222 | result = "" 223 | result_container = st.empty() 224 | for delta in crew.kickoff(): 225 | result += delta # Assuming delta is a string, if not, convert it appropriately 226 | result_container.markdown(result) 227 | 228 | 229 | if __name__ == "__main__": 230 | main() 231 | -------------------------------------------------------------------------------- /crewai_hierarchical_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "cell_execution_strategy": "setup", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# crewai-hierarchical-quickstart\n", 33 | "By [Alex Fazio](https://www.x.com/alxfazio)\n", 34 | "\n", 35 | "Github repo: https://github.com/alexfazio/crewai-quickstart\n", 36 | "\n", 37 | "Docs: https://docs.crewai.com/\n", 38 | "\n", 39 | "A simplified and tested starter template for a **hierarchical** CrewAI." 40 | ], 41 | "metadata": { 42 | "id": "ANCxcFs-qVl4" 43 | } 44 | }, 45 | { 46 | "metadata": { 47 | "cellView": "form", 48 | "id": "Q4r-pCKUwDc_" 49 | }, 50 | "cell_type": "code", 51 | "outputs": [], 52 | "execution_count": null, 53 | "source": [ 54 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 55 | "# Warning control\n", 56 | "import warnings\n", 57 | "warnings.filterwarnings('ignore')\n", 58 | "\n", 59 | "# To avoid the restart session warning in Colab, exclude the PIL and\n", 60 | "# pydevd_plugins packages from being imported. This is fine because\n", 61 | "# we didn't execute the code in the kernel session afterward.\n", 62 | "import sys\n", 63 | "sys.modules.pop('PIL', None)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "source": [ 69 | "# @title ⬇️ Install project dependencies by running this cell\n", 70 | "%pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 71 | "%pip install crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 72 | "print(\"---\")\n", 73 | "%pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 74 | ], 75 | "metadata": { 76 | "id": "P8iHNKCfk9Rv", 77 | "cellView": "form" 78 | }, 79 | "execution_count": null, 80 | "outputs": [] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": { 86 | "id": "BhAt-unGk4kA", 87 | "cellView": "form" 88 | }, 89 | "outputs": [], 90 | "source": [ 91 | "# @title 🔑 Input API Key by running this cell\n", 92 | "\n", 93 | "import os\n", 94 | "from getpass import getpass\n", 95 | "from crewai import Agent, Task, Crew, Process\n", 96 | "from textwrap import dedent\n", 97 | "from langchain_openai import ChatOpenAI\n", 98 | "# ↑ uncomment to use OpenAI's API\n", 99 | "# from langchain_groq import ChatGroq\n", 100 | "# ↑ uncomment to use Groq's API\n", 101 | "# from langchain_anthropic import ChatAnthropic\n", 102 | "# ↑ uncomment to use Antrhopic's API\n", 103 | "# from langchain_community.chat_models import ChatCohere\n", 104 | "# ↑ uncomment to use ChatCohere API\n", 105 | "\n", 106 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 107 | "# ↑ uncomment to use OpenAI's API\n", 108 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 109 | "# ↑ uncomment to use Groq's API\n", 110 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 111 | "# ↑ uncomment to use Anthropic's API\n", 112 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 113 | "# ↑ uncomment to use Cohere's API\n", 114 | "\n", 115 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 116 | "if not os.path.exists('output-files'):\n", 117 | " os.makedirs('output-files')" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "source": [ 123 | "# @title 🕵🏻 Define your agents\n", 124 | "\n", 125 | "# Agent Definitions\n", 126 | "\n", 127 | "agent_1 = Agent(\n", 128 | " role=dedent((\n", 129 | " \"\"\"\n", 130 | " Mr. White\n", 131 | " \"\"\")),\n", 132 | " # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 133 | " backstory=dedent((\n", 134 | " \"\"\"\n", 135 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 136 | " \"\"\")),\n", 137 | " goal=dedent((\n", 138 | " \"\"\"\n", 139 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 140 | " \"\"\")),\n", 141 | " allow_delegation=True,\n", 142 | " verbose=True,\n", 143 | " # ↑ Whether the agent execution should be in verbose mode\n", 144 | " max_iter=3,\n", 145 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 146 | " max_rpm=3,\n", 147 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 148 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 149 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 150 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 151 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 152 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 153 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 154 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 155 | ")\n", 156 | "\n", 157 | "agent_2 = Agent(\n", 158 | " role=dedent((\n", 159 | " \"\"\"\n", 160 | " Mr. Orange\n", 161 | " \"\"\")),\n", 162 | " # Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 163 | " backstory=dedent((\n", 164 | " \"\"\"\n", 165 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 166 | " \"\"\")),\n", 167 | " goal=dedent((\n", 168 | " \"\"\"\n", 169 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 170 | " \"\"\")),\n", 171 | " allow_delegation=True,\n", 172 | " verbose=True,\n", 173 | " # ↑ Whether the agent execution should be in verbose mode\n", 174 | " max_iter=3,\n", 175 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 176 | " max_rpm=3,\n", 177 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 178 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 179 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 180 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 181 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 182 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 183 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 184 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 185 | ")\n", 186 | "\n", 187 | "agent_3 = Agent(\n", 188 | " role=dedent((\n", 189 | " \"\"\"\n", 190 | " Mr. Pink\n", 191 | " \"\"\")),\n", 192 | " # ↑ Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 193 | " backstory=dedent((\n", 194 | " \"\"\"\n", 195 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 196 | " \"\"\")),\n", 197 | " goal=dedent((\n", 198 | " f\"\"\"\n", 199 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 200 | " \"\"\")),\n", 201 | " allow_delegation=True,\n", 202 | " verbose=True,\n", 203 | " # ↑ Whether the agent execution should be in verbose mode\n", 204 | " max_iter=3,\n", 205 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 206 | " max_rpm=3,\n", 207 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 208 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 209 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 210 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 211 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 212 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 213 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 214 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 215 | ")" 216 | ], 217 | "metadata": { 218 | "id": "hZJwUoXasrhx", 219 | "cellView": "form" 220 | }, 221 | "execution_count": null, 222 | "outputs": [] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "source": [ 227 | "# @title 📝 Define your tasks\n", 228 | "# Task Definitions\n", 229 | "\n", 230 | "task_1 = Task(\n", 231 | " description=dedent((\n", 232 | " \"\"\"\n", 233 | " A clear, concise statement of what the task entails.\n", 234 | " ---\n", 235 | " VARIABLE 1: \"{var_1}\"\n", 236 | " VARIABLE 2: \"{var_2}\"\n", 237 | " VARIABLE 3: \"{var_3}\"\n", 238 | " Add more variables if needed...\n", 239 | " \"\"\")),\n", 240 | " expected_output=dedent((\n", 241 | " f\"\"\"\n", 242 | " A detailed description of what the task's completion looks like.\n", 243 | " \"\"\")),\n", 244 | " agent=agent_1,\n", 245 | ")\n", 246 | "\n", 247 | "task_2 = Task(\n", 248 | " description=dedent((\n", 249 | " \"\"\"\n", 250 | " A clear, concise statement of what the task entails.\n", 251 | " ---\n", 252 | " VARIABLE 1: \"{var_1}\"\n", 253 | " VARIABLE 2: \"{var_2}\"\n", 254 | " VARIABLE 3: \"{var_3}\"\n", 255 | " Add more variables if needed...\n", 256 | " \"\"\")),\n", 257 | " expected_output=dedent((\n", 258 | " \"\"\"\n", 259 | " A detailed description of what the task's completion looks like.\n", 260 | " \"\"\")),\n", 261 | " agent=agent_2,\n", 262 | " context=[task_1],\n", 263 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 264 | ")\n", 265 | "\n", 266 | "task_3 = Task(\n", 267 | " description=dedent((\n", 268 | " \"\"\"\n", 269 | " A clear, concise statement of what the task entails.\n", 270 | " ---\n", 271 | " VARIABLE 1: \"{var_1}\"\n", 272 | " VARIABLE 2: \"{var_2}\"\n", 273 | " VARIABLE 3: \"{var_3}\"\n", 274 | " Add more variables if needed...\n", 275 | " \"\"\")),\n", 276 | " expected_output=dedent((\n", 277 | " \"\"\"\n", 278 | " A detailed description of what the task's completion looks like.\n", 279 | " \"\"\")),\n", 280 | " agent=agent_3,\n", 281 | " context=[task_1, task_2],\n", 282 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 283 | ")" 284 | ], 285 | "metadata": { 286 | "id": "dqtn3w1qs-Bu", 287 | "cellView": "form" 288 | }, 289 | "execution_count": null, 290 | "outputs": [] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "source": [ 295 | "# @title ⌨️ Define any variables you have and input them\n", 296 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 297 | "print('-------------------------------------------')\n", 298 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 299 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 300 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 301 | "print(\"-------------------------------\")" 302 | ], 303 | "metadata": { 304 | "id": "HfJRdGHesMwn", 305 | "cellView": "form" 306 | }, 307 | "execution_count": null, 308 | "outputs": [] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "source": [ 313 | "# @title 🚀 Get your crew to work!\n", 314 | "def main():\n", 315 | " # Instantiate your crew with a sequential process\n", 316 | " crew = Crew(\n", 317 | " agents=[agent_1, agent_2, agent_3],\n", 318 | " tasks=[task_1, task_2, task_3],\n", 319 | " verbose=True, # You can set it to True or False\n", 320 | " # ↑ indicates the verbosity level for logging during execution.\n", 321 | " process=Process.hierarchical,\n", 322 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 323 | " manager_llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 324 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 325 | " # manager_llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 326 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 327 | " # manager_llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 328 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 329 | " # manager_llm=ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 330 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 331 | " )\n", 332 | "\n", 333 | " inputs = {\n", 334 | " \"var_1\": var_1,\n", 335 | " \"var_2\": var_2,\n", 336 | " \"var_3\": var_3\n", 337 | " }\n", 338 | "\n", 339 | " result = crew.kickoff(inputs=inputs)\n", 340 | " print(\"\\n\\n########################\")\n", 341 | " print(\"## Here is your custom crew run result:\")\n", 342 | " print(\"########################\\n\")\n", 343 | " print(result)\n", 344 | " \n", 345 | " return result\n", 346 | "\n", 347 | "if __name__ == \"__main__\":\n", 348 | " result = main()" 349 | ], 350 | "metadata": { 351 | "id": "nrBn8dMlxfCn", 352 | "cellView": "form" 353 | }, 354 | "execution_count": null, 355 | "outputs": [] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "source": [ 360 | "# @title 🖥️ Display the results of your crew as markdown\n", 361 | "from IPython.display import display, Markdown\n", 362 | "\n", 363 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 364 | "\n", 365 | "# Display the markdown content\n", 366 | "display(Markdown(markdown_text))" 367 | ], 368 | "metadata": { 369 | "cellView": "form", 370 | "id": "80UYFcFixPxq" 371 | }, 372 | "execution_count": null, 373 | "outputs": [] 374 | } 375 | ] 376 | } 377 | -------------------------------------------------------------------------------- /crewai_example_collaboration_financial_analysis_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "65GBAFDXpte9" 17 | }, 18 | "source": "# Multi-agent Collaboration for Financial Analysis" 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "KyFD2Twopte-" 24 | }, 25 | "source": [ 26 | "If you're running this notebook on your own machine, you can install the following:\n", 27 | "```Python\n", 28 | "!pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29 --quiet\n", 29 | "```" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": { 36 | "height": 64, 37 | "id": "KBtSUwo7pte-" 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Warning control\n", 42 | "import warnings\n", 43 | "warnings.filterwarnings('ignore')" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": { 49 | "id": "_DtetBg4pte-" 50 | }, 51 | "source": [ 52 | "- Import libraries, APIs and LLM" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": { 59 | "height": 30, 60 | "id": "R1bQgOSopte_" 61 | }, 62 | "outputs": [], 63 | "source": [ 64 | "from crewai import Agent, Task, Crew" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "id": "rLsDKyuZpte_" 71 | }, 72 | "source": [ 73 | "**Note**:\n", 74 | "- The video uses `gpt-4o`, but due to certain constraints, and in order to offer this course for free to everyone, the code you'll run here will use `gpt-3.5-turbo`.\n", 75 | "- You can use `gpt-4o` when you run the notebook _locally_ (using `gpt-4o` will not work on the platform)\n", 76 | "- Thank you for your understanding!" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": { 83 | "height": 115, 84 | "id": "wEGgKxVPpte_" 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "import os\n", 89 | "from utils import get_openai_api_key, get_serper_api_key\n", 90 | "\n", 91 | "openai_api_key = get_openai_api_key()\n", 92 | "os.environ[\"OPENAI_MODEL_NAME\"] = 'gpt-3.5-turbo'\n", 93 | "os.environ[\"SERPER_API_KEY\"] = get_serper_api_key()" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "id": "oZIcaQj3pte_" 100 | }, 101 | "source": [ 102 | "## crewAI Tools" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "height": 81, 110 | "id": "RDsThA14pte_" 111 | }, 112 | "outputs": [], 113 | "source": [ 114 | "from crewai_tools import ScrapeWebsiteTool, SerperDevTool\n", 115 | "\n", 116 | "search_tool = SerperDevTool()\n", 117 | "scrape_tool = ScrapeWebsiteTool()" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": { 123 | "id": "OpWxj4iXpte_" 124 | }, 125 | "source": [ 126 | "## Creating Agents" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": { 133 | "height": 234, 134 | "id": "Au0wKrgApte_" 135 | }, 136 | "outputs": [], 137 | "source": [ 138 | "data_analyst_agent = Agent(\n", 139 | " role=\"Data Analyst\",\n", 140 | " goal=\"Monitor and analyze market data in real-time \"\n", 141 | " \"to identify trends and predict market movements.\",\n", 142 | " backstory=\"Specializing in financial markets, this agent \"\n", 143 | " \"uses statistical modeling and machine learning \"\n", 144 | " \"to provide crucial insights. With a knack for data, \"\n", 145 | " \"the Data Analyst Agent is the cornerstone for \"\n", 146 | " \"informing trading decisions.\",\n", 147 | " verbose=True,\n", 148 | " allow_delegation=True,\n", 149 | " tools = [scrape_tool, search_tool]\n", 150 | ")" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": { 157 | "height": 234, 158 | "id": "Gya_cvO1pte_" 159 | }, 160 | "outputs": [], 161 | "source": [ 162 | "trading_strategy_agent = Agent(\n", 163 | " role=\"Trading Strategy Developer\",\n", 164 | " goal=\"Develop and test various trading strategies based \"\n", 165 | " \"on insights from the Data Analyst Agent.\",\n", 166 | " backstory=\"Equipped with a deep understanding of financial \"\n", 167 | " \"markets and quantitative analysis, this agent \"\n", 168 | " \"devises and refines trading strategies. It evaluates \"\n", 169 | " \"the performance of different approaches to determine \"\n", 170 | " \"the most profitable and risk-averse options.\",\n", 171 | " verbose=True,\n", 172 | " allow_delegation=True,\n", 173 | " tools = [scrape_tool, search_tool]\n", 174 | ")" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": { 181 | "height": 234, 182 | "id": "f-J7TIc9pte_" 183 | }, 184 | "outputs": [], 185 | "source": [ 186 | "execution_agent = Agent(\n", 187 | " role=\"Trade Advisor\",\n", 188 | " goal=\"Suggest optimal trade execution strategies \"\n", 189 | " \"based on approved trading strategies.\",\n", 190 | " backstory=\"This agent specializes in analyzing the timing, price, \"\n", 191 | " \"and logistical details of potential trades. By evaluating \"\n", 192 | " \"these factors, it provides well-founded suggestions for \"\n", 193 | " \"when and how trades should be executed to maximize \"\n", 194 | " \"efficiency and adherence to strategy.\",\n", 195 | " verbose=True,\n", 196 | " allow_delegation=True,\n", 197 | " tools = [scrape_tool, search_tool]\n", 198 | ")" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": { 205 | "height": 234, 206 | "id": "QAz-khxkpte_" 207 | }, 208 | "outputs": [], 209 | "source": [ 210 | "risk_management_agent = Agent(\n", 211 | " role=\"Risk Advisor\",\n", 212 | " goal=\"Evaluate and provide insights on the risks \"\n", 213 | " \"associated with potential trading activities.\",\n", 214 | " backstory=\"Armed with a deep understanding of risk assessment models \"\n", 215 | " \"and market dynamics, this agent scrutinizes the potential \"\n", 216 | " \"risks of proposed trades. It offers a detailed analysis of \"\n", 217 | " \"risk exposure and suggests safeguards to ensure that \"\n", 218 | " \"trading activities align with the firm’s risk tolerance.\",\n", 219 | " verbose=True,\n", 220 | " allow_delegation=True,\n", 221 | " tools = [scrape_tool, search_tool]\n", 222 | ")" 223 | ] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "metadata": { 228 | "id": "tWcxt1vfpte_" 229 | }, 230 | "source": [ 231 | "## Creating Tasks" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": null, 237 | "metadata": { 238 | "height": 251, 239 | "id": "OSVfRdEepte_" 240 | }, 241 | "outputs": [], 242 | "source": [ 243 | "# Task for Data Analyst Agent: Analyze Market Data\n", 244 | "data_analysis_task = Task(\n", 245 | " description=(\n", 246 | " \"Continuously monitor and analyze market data for \"\n", 247 | " \"the selected stock ({stock_selection}). \"\n", 248 | " \"Use statistical modeling and machine learning to \"\n", 249 | " \"identify trends and predict market movements.\"\n", 250 | " ),\n", 251 | " expected_output=(\n", 252 | " \"Insights and alerts about significant market \"\n", 253 | " \"opportunities or threats for {stock_selection}.\"\n", 254 | " ),\n", 255 | " agent=data_analyst_agent,\n", 256 | ")" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": null, 262 | "metadata": { 263 | "height": 268, 264 | "id": "KAbnRbRJpte_" 265 | }, 266 | "outputs": [], 267 | "source": [ 268 | "# Task for Trading Strategy Agent: Develop Trading Strategies\n", 269 | "strategy_development_task = Task(\n", 270 | " description=(\n", 271 | " \"Develop and refine trading strategies based on \"\n", 272 | " \"the insights from the Data Analyst and \"\n", 273 | " \"user-defined risk tolerance ({risk_tolerance}). \"\n", 274 | " \"Consider trading preferences ({trading_strategy_preference}).\"\n", 275 | " ),\n", 276 | " expected_output=(\n", 277 | " \"A set of potential trading strategies for {stock_selection} \"\n", 278 | " \"that align with the user's risk tolerance.\"\n", 279 | " ),\n", 280 | " agent=trading_strategy_agent,\n", 281 | ")\n" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": null, 287 | "metadata": { 288 | "height": 251, 289 | "id": "Y370kpDtpte_" 290 | }, 291 | "outputs": [], 292 | "source": [ 293 | "# Task for Trade Advisor Agent: Plan Trade Execution\n", 294 | "execution_planning_task = Task(\n", 295 | " description=(\n", 296 | " \"Analyze approved trading strategies to determine the \"\n", 297 | " \"best execution methods for {stock_selection}, \"\n", 298 | " \"considering current market conditions and optimal pricing.\"\n", 299 | " ),\n", 300 | " expected_output=(\n", 301 | " \"Detailed execution plans suggesting how and when to \"\n", 302 | " \"execute trades for {stock_selection}.\"\n", 303 | " ),\n", 304 | " agent=execution_agent,\n", 305 | ")\n" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": null, 311 | "metadata": { 312 | "height": 251, 313 | "id": "4cFzLUW4pte_" 314 | }, 315 | "outputs": [], 316 | "source": [ 317 | "# Task for Risk Advisor Agent: Assess Trading Risks\n", 318 | "risk_assessment_task = Task(\n", 319 | " description=(\n", 320 | " \"Evaluate the risks associated with the proposed trading \"\n", 321 | " \"strategies and execution plans for {stock_selection}. \"\n", 322 | " \"Provide a detailed analysis of potential risks \"\n", 323 | " \"and suggest mitigation strategies.\"\n", 324 | " ),\n", 325 | " expected_output=(\n", 326 | " \"A comprehensive risk analysis report detailing potential \"\n", 327 | " \"risks and mitigation recommendations for {stock_selection}.\"\n", 328 | " ),\n", 329 | " agent=risk_management_agent,\n", 330 | ")" 331 | ] 332 | }, 333 | { 334 | "cell_type": "markdown", 335 | "metadata": { 336 | "id": "sg91wwKNptfA" 337 | }, 338 | "source": [ 339 | "## Creating the Crew\n", 340 | "- The `Process` class helps to delegate the workflow to the Agents (kind of like a Manager at work)\n", 341 | "- In the example below, it will run this hierarchically.\n", 342 | "- `manager_llm` lets you choose the \"manager\" LLM you want to use." 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": null, 348 | "metadata": { 349 | "height": 353, 350 | "id": "HTfi3mP4ptfA" 351 | }, 352 | "outputs": [], 353 | "source": [ 354 | "from crewai import Crew, Process\n", 355 | "from langchain_openai import ChatOpenAI\n", 356 | "\n", 357 | "# Define the crew with agents and tasks\n", 358 | "financial_trading_crew = Crew(\n", 359 | " agents=[data_analyst_agent,\n", 360 | " trading_strategy_agent,\n", 361 | " execution_agent,\n", 362 | " risk_management_agent],\n", 363 | "\n", 364 | " tasks=[data_analysis_task,\n", 365 | " strategy_development_task,\n", 366 | " execution_planning_task,\n", 367 | " risk_assessment_task],\n", 368 | "\n", 369 | " manager_llm=ChatOpenAI(model=\"gpt-3.5-turbo\",\n", 370 | " temperature=0.7),\n", 371 | " process=Process.hierarchical,\n", 372 | " verbose=True\n", 373 | ")" 374 | ] 375 | }, 376 | { 377 | "cell_type": "markdown", 378 | "metadata": { 379 | "id": "SoeN-QB7ptfA" 380 | }, 381 | "source": [ 382 | "## Running the Crew\n", 383 | "\n", 384 | "- Set the inputs for the execution of the crew." 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": null, 390 | "metadata": { 391 | "height": 149, 392 | "id": "-qoJrZ13ptfA" 393 | }, 394 | "outputs": [], 395 | "source": [ 396 | "# Example data for kicking off the process\n", 397 | "financial_trading_inputs = {\n", 398 | " 'stock_selection': 'AAPL',\n", 399 | " 'initial_capital': '100000',\n", 400 | " 'risk_tolerance': 'Medium',\n", 401 | " 'trading_strategy_preference': 'Day Trading',\n", 402 | " 'news_impact_consideration': True\n", 403 | "}" 404 | ] 405 | }, 406 | { 407 | "cell_type": "markdown", 408 | "metadata": { 409 | "id": "bcUVMiLkptfA" 410 | }, 411 | "source": [ 412 | "**Note**: LLMs can provide different outputs for they same input, so what you get might be different than what you see in the video." 413 | ] 414 | }, 415 | { 416 | "cell_type": "code", 417 | "execution_count": null, 418 | "metadata": { 419 | "height": 47, 420 | "id": "PMQ3Ji5CptfA" 421 | }, 422 | "outputs": [], 423 | "source": [ 424 | "### this execution will take some time to run\n", 425 | "result = financial_trading_crew.kickoff(inputs=financial_trading_inputs)" 426 | ] 427 | }, 428 | { 429 | "cell_type": "markdown", 430 | "metadata": { 431 | "id": "bo5RwgpxptfA" 432 | }, 433 | "source": [ 434 | "- Display the final result as Markdown." 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": null, 440 | "metadata": { 441 | "height": 47, 442 | "id": "L0TX5zusptfA" 443 | }, 444 | "outputs": [], 445 | "source": [ 446 | "# @title 🖥️ Display the results of your crew as markdown\n", 447 | "from IPython.display import display, Markdown\n", 448 | "\n", 449 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 450 | "\n", 451 | "# Display the markdown content\n", 452 | "display(Markdown(markdown_text))" 453 | ] 454 | } 455 | ], 456 | "metadata": { 457 | "kernelspec": { 458 | "display_name": "Python 3 (ipykernel)", 459 | "language": "python", 460 | "name": "python3" 461 | }, 462 | "language_info": { 463 | "codemirror_mode": { 464 | "name": "ipython", 465 | "version": 3 466 | }, 467 | "file_extension": ".py", 468 | "mimetype": "text/x-python", 469 | "name": "python", 470 | "nbconvert_exporter": "python", 471 | "pygments_lexer": "ipython3", 472 | "version": "3.11.9" 473 | }, 474 | "colab": { 475 | "provenance": [], 476 | "include_colab_link": true 477 | } 478 | }, 479 | "nbformat": 4, 480 | "nbformat_minor": 0 481 | } 482 | -------------------------------------------------------------------------------- /crewai-example-task-event-planning-quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "By9Je_QqSUGw" 17 | }, 18 | "source": "# Automate Event Planning" 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "tfTPMCRgSUGy" 24 | }, 25 | "source": [ 26 | "If you're running this notebook on your own machine, you can install the following:\n", 27 | "```Python\n", 28 | "%pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29 --quiet\n", 29 | "```" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": { 36 | "height": 64, 37 | "id": "RbQDt6mJSUGy" 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Warning control\n", 42 | "import warnings\n", 43 | "warnings.filterwarnings('ignore')" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": { 49 | "id": "k12cfmZ8SUGz" 50 | }, 51 | "source": [ 52 | "- Import libraries, APIs and LLM" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": { 59 | "height": 30, 60 | "id": "bZnxm_KDSUGz" 61 | }, 62 | "outputs": [], 63 | "source": [ 64 | "from crewai import Agent, Crew, Task" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "id": "t7PqG655SUGz" 71 | }, 72 | "source": [ 73 | "**Note**:\n", 74 | "- The video uses `gpt-4o`, but due to certain constraints, and in order to offer this course for free to everyone, the code you'll run here will use `gpt-3.5-turbo`.\n", 75 | "- You can use `gpt-4o` when you run the notebook _locally_ (using `gpt-4o` will not work on the platform)\n", 76 | "- Thank you for your understanding!" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": { 83 | "height": 115, 84 | "id": "AiQCQ2CLSUGz" 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "import os\n", 89 | "from utils import get_openai_api_key,get_serper_api_key\n", 90 | "\n", 91 | "openai_api_key = get_openai_api_key()\n", 92 | "os.environ[\"OPENAI_MODEL_NAME\"] = 'gpt-3.5-turbo'\n", 93 | "os.environ[\"SERPER_API_KEY\"] = get_serper_api_key()" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "id": "j8Q4BDiPSUGz" 100 | }, 101 | "source": [ 102 | "## crewAI Tools" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "height": 98, 110 | "id": "-MXCboJsSUGz" 111 | }, 112 | "outputs": [], 113 | "source": [ 114 | "from crewai_tools import ScrapeWebsiteTool, SerperDevTool\n", 115 | "\n", 116 | "# Initialize the tools\n", 117 | "search_tool = SerperDevTool()\n", 118 | "scrape_tool = ScrapeWebsiteTool()" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": { 124 | "id": "XEXovfTBSUGz" 125 | }, 126 | "source": [ 127 | "## Creating Agents" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": null, 133 | "metadata": { 134 | "height": 268, 135 | "id": "NHCoC__NSUGz" 136 | }, 137 | "outputs": [], 138 | "source": [ 139 | "# Agent 1: Venue Coordinator\n", 140 | "venue_coordinator = Agent(\n", 141 | " role=\"Venue Coordinator\",\n", 142 | " goal=\"Identify and book an appropriate venue \"\n", 143 | " \"based on event requirements\",\n", 144 | " tools=[search_tool, scrape_tool],\n", 145 | " verbose=True,\n", 146 | " backstory=(\n", 147 | " \"With a keen sense of space and \"\n", 148 | " \"understanding of event logistics, \"\n", 149 | " \"you excel at finding and securing \"\n", 150 | " \"the perfect venue that fits the event's theme, \"\n", 151 | " \"size, and budget constraints.\"\n", 152 | " )\n", 153 | ")" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": { 160 | "height": 285, 161 | "id": "B33o3zrvSUGz" 162 | }, 163 | "outputs": [], 164 | "source": [ 165 | " # Agent 2: Logistics Manager\n", 166 | "logistics_manager = Agent(\n", 167 | " role='Logistics Manager',\n", 168 | " goal=(\n", 169 | " \"Manage all logistics for the event \"\n", 170 | " \"including catering and equipmen\"\n", 171 | " ),\n", 172 | " tools=[search_tool, scrape_tool],\n", 173 | " verbose=True,\n", 174 | " backstory=(\n", 175 | " \"Organized and detail-oriented, \"\n", 176 | " \"you ensure that every logistical aspect of the event \"\n", 177 | " \"from catering to equipment setup \"\n", 178 | " \"is flawlessly executed to create a seamless experience.\"\n", 179 | " )\n", 180 | ")" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": { 187 | "height": 251, 188 | "id": "NIAqkrlLSUG0" 189 | }, 190 | "outputs": [], 191 | "source": [ 192 | "# Agent 3: Marketing and Communications Agent\n", 193 | "marketing_communications_agent = Agent(\n", 194 | " role=\"Marketing and Communications Agent\",\n", 195 | " goal=\"Effectively market the event and \"\n", 196 | " \"communicate with participants\",\n", 197 | " tools=[search_tool, scrape_tool],\n", 198 | " verbose=True,\n", 199 | " backstory=(\n", 200 | " \"Creative and communicative, \"\n", 201 | " \"you craft compelling messages and \"\n", 202 | " \"engage with potential attendees \"\n", 203 | " \"to maximize event exposure and participation.\"\n", 204 | " )\n", 205 | ")" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": { 211 | "id": "v_OqO_WJSUG0" 212 | }, 213 | "source": [ 214 | "## Creating Venue Pydantic Object\n", 215 | "\n", 216 | "- Create a class `VenueDetails` using [Pydantic BaseModel](https://docs.pydantic.dev/latest/api/base_model/).\n", 217 | "- Agents will populate this object with information about different venues by creating different instances of it." 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "metadata": { 224 | "height": 149, 225 | "id": "F9F_1rs0SUG0" 226 | }, 227 | "outputs": [], 228 | "source": [ 229 | "from pydantic import BaseModel\n", 230 | "# Define a Pydantic model for venue details\n", 231 | "# (demonstrating Output as Pydantic)\n", 232 | "class VenueDetails(BaseModel):\n", 233 | " name: str\n", 234 | " address: str\n", 235 | " capacity: int\n", 236 | " booking_status: str" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": { 242 | "id": "LtO5v9bRSUG0" 243 | }, 244 | "source": [ 245 | "## Creating Tasks\n", 246 | "- By using `output_json`, you can specify the structure of the output you want.\n", 247 | "- By using `output_file`, you can get your output in a file.\n", 248 | "- By setting `human_input=True`, the task will ask for human feedback (whether you like the results or not) before finalising it." 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "metadata": { 255 | "height": 200, 256 | "id": "LrMzfUxPSUG0" 257 | }, 258 | "outputs": [], 259 | "source": [ 260 | "venue_task = Task(\n", 261 | " description=\"Find a venue in {event_city} \"\n", 262 | " \"that meets criteria for {event_topic}.\",\n", 263 | " expected_output=\"All the details of a specifically chosen\"\n", 264 | " \"venue you found to accommodate the event.\",\n", 265 | " human_input=True,\n", 266 | " output_json=VenueDetails,\n", 267 | " output_file=\"venue_details.json\",\n", 268 | " # Outputs the venue details as a JSON file\n", 269 | " agent=venue_coordinator\n", 270 | ")" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "metadata": { 276 | "id": "Jf5INrwOSUG0" 277 | }, 278 | "source": [ 279 | "- By setting `async_execution=True`, it means the task can run in parallel with the tasks which come after it." 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "metadata": { 286 | "height": 200, 287 | "id": "Rbx_gNjGSUG0" 288 | }, 289 | "outputs": [], 290 | "source": [ 291 | "logistics_task = Task(\n", 292 | " description=\"Coordinate catering and \"\n", 293 | " \"equipment for an event \"\n", 294 | " \"with {expected_participants} participants \"\n", 295 | " \"on {tentative_date}.\",\n", 296 | " expected_output=\"Confirmation of all logistics arrangements \"\n", 297 | " \"including catering and equipment setup.\",\n", 298 | " human_input=True,\n", 299 | " async_execution=True,\n", 300 | " agent=logistics_manager\n", 301 | ")" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": null, 307 | "metadata": { 308 | "height": 183, 309 | "id": "vuucUfPRSUG0" 310 | }, 311 | "outputs": [], 312 | "source": [ 313 | "marketing_task = Task(\n", 314 | " description=\"Promote the {event_topic} \"\n", 315 | " \"aiming to engage at least\"\n", 316 | " \"{expected_participants} potential attendees.\",\n", 317 | " expected_output=\"Report on marketing activities \"\n", 318 | " \"and attendee engagement formatted as markdown.\",\n", 319 | " async_execution=True,\n", 320 | " output_file=\"marketing_report.md\", # Outputs the report as a text file\n", 321 | " agent=marketing_communications_agent\n", 322 | ")" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "metadata": { 328 | "id": "zHOl9_9cSUG0" 329 | }, 330 | "source": [ 331 | "## Creating the Crew" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": { 337 | "id": "Sml-3Tc8SUG0" 338 | }, 339 | "source": [ 340 | "**Note**: Since you set `async_execution=True` for `logistics_task` and `marketing_task` tasks, now the order for them does not matter in the `tasks` list." 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": null, 346 | "metadata": { 347 | "height": 217, 348 | "id": "p8Mq2ar3SUG0" 349 | }, 350 | "outputs": [], 351 | "source": [ 352 | "# Define the crew with agents and tasks\n", 353 | "event_management_crew = Crew(\n", 354 | " agents=[venue_coordinator,\n", 355 | " logistics_manager,\n", 356 | " marketing_communications_agent],\n", 357 | "\n", 358 | " tasks=[venue_task,\n", 359 | " logistics_task,\n", 360 | " marketing_task],\n", 361 | "\n", 362 | " verbose=True\n", 363 | ")" 364 | ] 365 | }, 366 | { 367 | "cell_type": "markdown", 368 | "metadata": { 369 | "id": "hnUgBgWlSUG1" 370 | }, 371 | "source": [ 372 | "## Running the Crew\n", 373 | "\n", 374 | "- Set the inputs for the execution of the crew." 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "execution_count": null, 380 | "metadata": { 381 | "height": 200, 382 | "id": "pqYXRHnaSUG1" 383 | }, 384 | "outputs": [], 385 | "source": [ 386 | "event_details = {\n", 387 | " 'event_topic': \"Tech Innovation Conference\",\n", 388 | " 'event_description': \"A gathering of tech innovators \"\n", 389 | " \"and industry leaders \"\n", 390 | " \"to explore future technologies.\",\n", 391 | " 'event_city': \"San Francisco\",\n", 392 | " 'tentative_date': \"2024-09-15\",\n", 393 | " 'expected_participants': 500,\n", 394 | " 'budget': 20000,\n", 395 | " 'venue_type': \"Conference Hall\"\n", 396 | "}" 397 | ] 398 | }, 399 | { 400 | "cell_type": "markdown", 401 | "metadata": { 402 | "id": "7Qr0RRkFSUG1" 403 | }, 404 | "source": [ 405 | "**Note 1**: LLMs can provide different outputs for they same input, so what you get might be different than what you see in the video." 406 | ] 407 | }, 408 | { 409 | "cell_type": "markdown", 410 | "metadata": { 411 | "id": "LkH5JmNASUG1" 412 | }, 413 | "source": [ 414 | "**Note 2**:\n", 415 | "- Since you set `human_input=True` for some tasks, the execution will ask for your input before it finishes running.\n", 416 | "- When it asks for feedback, use your mouse pointer to first click in the text box before typing anything." 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "execution_count": null, 422 | "metadata": { 423 | "height": 30, 424 | "id": "X0JoI32bSUG1" 425 | }, 426 | "outputs": [], 427 | "source": [ 428 | "result = event_management_crew.kickoff(inputs=event_details)" 429 | ] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "metadata": { 434 | "id": "b8qZtTQISUG1" 435 | }, 436 | "source": [ 437 | "- Display the generated `venue_details.json` file." 438 | ] 439 | }, 440 | { 441 | "cell_type": "code", 442 | "execution_count": null, 443 | "metadata": { 444 | "height": 132, 445 | "id": "bAteuAVqSUG1" 446 | }, 447 | "outputs": [], 448 | "source": [ 449 | "import json\n", 450 | "from pprint import pprint\n", 451 | "\n", 452 | "with open('venue_details.json') as f:\n", 453 | " data = json.load(f)\n", 454 | "\n", 455 | "pprint(data)" 456 | ] 457 | }, 458 | { 459 | "cell_type": "markdown", 460 | "metadata": { 461 | "id": "XZibXQP6SUG1" 462 | }, 463 | "source": [ 464 | "- Display the generated `marketing_report.md` file.\n", 465 | "\n", 466 | "**Note**: After `kickoff` execution has successfully ran, wait an extra 45 seconds for the `marketing_report.md` file to be generated. If you try to run the code below before the file has been generated, your output would look like:\n", 467 | "\n", 468 | "```\n", 469 | "marketing_report.md\n", 470 | "```\n", 471 | "\n", 472 | "If you see this output, wait some more and than try again." 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": null, 478 | "metadata": { 479 | "height": 47, 480 | "id": "Laq81QzTSUG1" 481 | }, 482 | "outputs": [], 483 | "source": [ 484 | "# @title 🖥️ Display the results of your crew as markdown\n", 485 | "from IPython.display import display, Markdown\n", 486 | "\n", 487 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 488 | "\n", 489 | "# Display the markdown content\n", 490 | "display(Markdown(markdown_text))" 491 | ] 492 | } 493 | ], 494 | "metadata": { 495 | "kernelspec": { 496 | "display_name": "Python 3 (ipykernel)", 497 | "language": "python", 498 | "name": "python3" 499 | }, 500 | "language_info": { 501 | "codemirror_mode": { 502 | "name": "ipython", 503 | "version": 3 504 | }, 505 | "file_extension": ".py", 506 | "mimetype": "text/x-python", 507 | "name": "python", 508 | "nbconvert_exporter": "python", 509 | "pygments_lexer": "ipython3", 510 | "version": "3.11.9" 511 | }, 512 | "colab": { 513 | "provenance": [], 514 | "include_colab_link": true 515 | } 516 | }, 517 | "nbformat": 4, 518 | "nbformat_minor": 0 519 | } 520 | -------------------------------------------------------------------------------- /crewai_sequential_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3 (ipykernel)", 13 | "language": "python" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# crewai-sequential-quickstart\n", 34 | "By [Alex Fazio](https://www.x.com/alxfazio)\n", 35 | "\n", 36 | "Github repo: https://github.com/alexfazio/crewai-quickstart\n", 37 | "\n", 38 | "Docs: https://docs.crewai.com/\n", 39 | "\n", 40 | "Simplified and tested version of a **sequential** CrewAI." 41 | ], 42 | "metadata": { 43 | "id": "ANCxcFs-qVl4" 44 | } 45 | }, 46 | { 47 | "cell_type": "code", 48 | "source": [ 49 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 50 | "# Warning control\n", 51 | "import warnings\n", 52 | "warnings.filterwarnings('ignore')\n", 53 | "\n", 54 | "# To avoid the restart session warning in Colab, exclude the PIL and\n", 55 | "# pydevd_plugins packages from being imported. This is fine because\n", 56 | "# we didn't execute the code in the kernel session afterward.\n", 57 | "\n", 58 | "# import sys\n", 59 | "# sys.modules.pop('PIL', None)" 60 | ], 61 | "metadata": { 62 | "id": "NsNLa6Qu0JEK", 63 | "ExecuteTime": { 64 | "end_time": "2024-05-17T18:19:19.351863Z", 65 | "start_time": "2024-05-17T18:19:19.350191Z" 66 | }, 67 | "cellView": "form" 68 | }, 69 | "outputs": [], 70 | "execution_count": null 71 | }, 72 | { 73 | "cell_type": "code", 74 | "source": [ 75 | "# @title ⬇️ Install project dependencies by running this cell\n", 76 | "%pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 77 | "%pip install crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 78 | "print(\"---\")\n", 79 | "%pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 80 | ], 81 | "metadata": { 82 | "id": "P8iHNKCfk9Rv", 83 | "ExecuteTime": { 84 | "end_time": "2024-05-17T18:20:26.741468Z", 85 | "start_time": "2024-05-17T18:19:29.015624Z" 86 | }, 87 | "cellView": "form" 88 | }, 89 | "outputs": [], 90 | "execution_count": null 91 | }, 92 | { 93 | "cell_type": "code", 94 | "metadata": { 95 | "id": "BhAt-unGk4kA", 96 | "ExecuteTime": { 97 | "end_time": "2024-05-17T18:26:09.810103Z", 98 | "start_time": "2024-05-17T18:25:59.838229Z" 99 | }, 100 | "cellView": "form" 101 | }, 102 | "source": [ 103 | "# @title 🔑 Input API Key by running this cell\n", 104 | "\n", 105 | "import os\n", 106 | "from getpass import getpass\n", 107 | "from crewai import Agent, Task, Crew, Process\n", 108 | "from textwrap import dedent\n", 109 | "from langchain_openai import ChatOpenAI\n", 110 | "# ↑ uncomment to use OpenAI's API\n", 111 | "# from langchain_groq import ChatGroq\n", 112 | "# ↑ uncomment to use Groq's API\n", 113 | "# from langchain_anthropic import ChatAnthropic\n", 114 | "# ↑ uncomment to use Antrhopic's API\n", 115 | "# from langchain_community.chat_models import ChatCohere\n", 116 | "# ↑ uncomment to use ChatCohere API\n", 117 | "\n", 118 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 119 | "# ↑ uncomment to use OpenAI's API\n", 120 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 121 | "# ↑ uncomment to use Groq's API\n", 122 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 123 | "# ↑ uncomment to use Anthropic's API\n", 124 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 125 | "# ↑ uncomment to use Cohere's API\n", 126 | "\n", 127 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 128 | "if not os.path.exists('output-files'):\n", 129 | " os.makedirs('output-files')" 130 | ], 131 | "outputs": [], 132 | "execution_count": null 133 | }, 134 | { 135 | "metadata": {}, 136 | "cell_type": "markdown", 137 | "source": [ 138 | "## Define Agents\n", 139 | "In CrewAI, agents are autonomous entities designed to perform specific roles and achieve particular goals. Each agent uses a language model (LLM) and may have specialized tools to help execute tasks." 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "source": [ 145 | "# @title 🕵🏻 Define your agents\n", 146 | "\n", 147 | "# Agent Definitions\n", 148 | "\n", 149 | "agent_1 = Agent(\n", 150 | " role=dedent((\n", 151 | " \"\"\"\n", 152 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 153 | " \"\"\")),\n", 154 | " backstory=dedent((\n", 155 | " \"\"\"\n", 156 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 157 | " \"\"\")),\n", 158 | " goal=dedent((\n", 159 | " \"\"\"\n", 160 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 161 | " \"\"\")),\n", 162 | " allow_delegation=False,\n", 163 | " verbose=True,\n", 164 | " # ↑ Whether the agent execution should be in verbose mode\n", 165 | " max_iter=3,\n", 166 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 167 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 168 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 169 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 170 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 171 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 172 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 173 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 174 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 175 | " # llm = ChatCohere(model=\"command\", max_tokens=256, temperature=0.75)\n", 176 | " # ↑ uncomment to use Cohere's API + \"command-r-plus\"\n", 177 | ")\n", 178 | "\n", 179 | "agent_2 = Agent(\n", 180 | " role=dedent((\n", 181 | " \"\"\"\n", 182 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 183 | " \"\"\")),\n", 184 | " backstory=dedent((\n", 185 | " \"\"\"\n", 186 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 187 | " \"\"\")),\n", 188 | " goal=dedent((\n", 189 | " \"\"\"\n", 190 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 191 | " \"\"\")),\n", 192 | " allow_delegation=False,\n", 193 | " verbose=True,\n", 194 | " # ↑ Whether the agent execution should be in verbose mode\n", 195 | " max_iter=3,\n", 196 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 197 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 198 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 199 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 200 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 201 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 202 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 203 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 204 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 205 | " # llm = ChatCohere(model=\"command\", max_tokens=256, temperature=0.75)\n", 206 | " # ↑ uncomment to use Cohere's API + \"command-r-plus\"\n", 207 | ")\n", 208 | "\n", 209 | "agent_3 = Agent(\n", 210 | " role=dedent((\n", 211 | " \"\"\"\n", 212 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 213 | " \"\"\")),\n", 214 | " backstory=dedent((\n", 215 | " \"\"\"\n", 216 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 217 | " \"\"\")),\n", 218 | " goal=dedent((\n", 219 | " \"\"\"\n", 220 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 221 | " \"\"\")),\n", 222 | " allow_delegation=False,\n", 223 | " verbose=True,\n", 224 | " # ↑ Whether the agent execution should be in verbose mode\n", 225 | " max_iter=3,\n", 226 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer\n", 227 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 228 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 229 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 230 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 231 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 232 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 233 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 234 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 235 | " # llm = ChatCohere(model=\"command\", max_tokens=256, temperature=0.75)\n", 236 | " # ↑ uncomment to use Cohere's API + \"command-r-plus\"\n", 237 | ")" 238 | ], 239 | "metadata": { 240 | "id": "hZJwUoXasrhx", 241 | "ExecuteTime": { 242 | "end_time": "2024-05-17T18:26:14.680431Z", 243 | "start_time": "2024-05-17T18:26:14.561004Z" 244 | }, 245 | "cellView": "form" 246 | }, 247 | "outputs": [], 248 | "execution_count": null 249 | }, 250 | { 251 | "metadata": {}, 252 | "cell_type": "markdown", 253 | "source": [ 254 | "## Define Tasks\n", 255 | "Tasks in CrewAI are specific assignments given to agents, detailing the actions they need to perform to achieve a particular goal. Tasks can have dependencies and context, and can be executed asynchronously to ensure an efficient workflow." 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "source": [ 261 | "# @title 📝 Define your tasks\n", 262 | "# Task Definitions\n", 263 | "\n", 264 | "task_1 = Task(\n", 265 | " description=dedent((\n", 266 | " \"\"\"\n", 267 | " A clear, concise statement of what the task entails.\n", 268 | " ---\n", 269 | " VARIABLE 1: \"{var_1}\"\n", 270 | " VARIABLE 2: \"{var_2}\"\n", 271 | " VARIABLE 3: \"{var_3}\"\n", 272 | " Add more variables if needed...\n", 273 | " \"\"\")),\n", 274 | " expected_output=dedent((\n", 275 | " \"\"\"\n", 276 | " A detailed description of what the task's completion looks like.\n", 277 | " \"\"\")),\n", 278 | " agent=agent_1,\n", 279 | ")\n", 280 | "\n", 281 | "task_2 = Task(\n", 282 | " description=dedent((\n", 283 | " \"\"\"\n", 284 | " A clear, concise statement of what the task entails.\n", 285 | " ---\n", 286 | " VARIABLE 1: \"{var_1}\"\n", 287 | " VARIABLE 2: \"{var_2}\"\n", 288 | " VARIABLE 3: \"{var_3}\"\n", 289 | " Add more variables if needed...\n", 290 | " \"\"\")),\n", 291 | " expected_output=dedent((\n", 292 | " f\"\"\"\n", 293 | " A detailed description of what the task's completion looks like.\n", 294 | " \"\"\")),\n", 295 | " agent=agent_2,\n", 296 | " context=[task_1],\n", 297 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 298 | ")\n", 299 | "\n", 300 | "task_3 = Task(\n", 301 | " description=dedent((\n", 302 | " \"\"\"\n", 303 | " A clear, concise statement of what the task entails.\n", 304 | " ---\n", 305 | " VARIABLE 1: \"{var_1}\"\n", 306 | " VARIABLE 2: \"{var_2}\"\n", 307 | " VARIABLE 3: \"{var_3}\"\n", 308 | " Add more variables if needed...\n", 309 | " \"\"\")),\n", 310 | " expected_output=dedent((\n", 311 | " \"\"\"\n", 312 | " A detailed description of what the task's completion looks like.\n", 313 | " \"\"\")),\n", 314 | " agent=agent_3,\n", 315 | " context=[task_2],\n", 316 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 317 | ")" 318 | ], 319 | "metadata": { 320 | "id": "dqtn3w1qs-Bu", 321 | "ExecuteTime": { 322 | "end_time": "2024-05-17T18:26:17.691Z", 323 | "start_time": "2024-05-17T18:26:17.687416Z" 324 | }, 325 | "cellView": "form" 326 | }, 327 | "outputs": [], 328 | "execution_count": null 329 | }, 330 | { 331 | "cell_type": "code", 332 | "source": [ 333 | "# @title ⌨️ Define any variables you have and input them\n", 334 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 335 | "print('-------------------------------------------')\n", 336 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 337 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 338 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 339 | "print(\"-------------------------------\")" 340 | ], 341 | "metadata": { 342 | "id": "HfJRdGHesMwn", 343 | "ExecuteTime": { 344 | "end_time": "2024-05-17T18:26:27.178968Z", 345 | "start_time": "2024-05-17T18:26:19.601235Z" 346 | }, 347 | "cellView": "form" 348 | }, 349 | "outputs": [], 350 | "execution_count": null 351 | }, 352 | { 353 | "cell_type": "code", 354 | "source": [ 355 | "# @title 🚀 Get your crew to work!\n", 356 | "def main():\n", 357 | " # Instantiate your crew with a sequential process\n", 358 | " crew = Crew(\n", 359 | " agents=[agent_1, agent_2, agent_3],\n", 360 | " tasks=[task_1, task_2, task_3],\n", 361 | " verbose=True, # You can set it to True or False\n", 362 | " # ↑ indicates the verbosity level for logging during execution.\n", 363 | " process=Process.sequential\n", 364 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 365 | " )\n", 366 | "\n", 367 | " inputs = {\n", 368 | " \"var_1\": var_1,\n", 369 | " \"var_2\": var_2,\n", 370 | " \"var_3\": var_3\n", 371 | " }\n", 372 | "\n", 373 | " result = crew.kickoff(inputs=inputs)\n", 374 | " print(\"\\n\\n########################\")\n", 375 | " print(\"## Here is your custom crew run result:\")\n", 376 | " print(\"########################\\n\")\n", 377 | " print(result)\n", 378 | "\n", 379 | " return result\n", 380 | "\n", 381 | "if __name__ == \"__main__\":\n", 382 | " result = main()" 383 | ], 384 | "metadata": { 385 | "id": "nrBn8dMlxfCn", 386 | "ExecuteTime": { 387 | "end_time": "2024-05-17T18:26:49.752419Z", 388 | "start_time": "2024-05-17T18:26:33.273949Z" 389 | }, 390 | "cellView": "form" 391 | }, 392 | "outputs": [], 393 | "execution_count": null 394 | }, 395 | { 396 | "cell_type": "code", 397 | "source": [ 398 | "# @title 🖥️ Display the results of your crew as markdown\n", 399 | "from IPython.display import display, Markdown\n", 400 | "\n", 401 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 402 | "\n", 403 | "# Display the markdown content\n", 404 | "display(Markdown(markdown_text))" 405 | ], 406 | "metadata": { 407 | "id": "gPQAfHJewy4E", 408 | "ExecuteTime": { 409 | "end_time": "2024-05-17T18:31:56.607199Z", 410 | "start_time": "2024-05-17T18:31:56.602349Z" 411 | }, 412 | "cellView": "form" 413 | }, 414 | "outputs": [], 415 | "execution_count": null 416 | } 417 | ] 418 | } 419 | -------------------------------------------------------------------------------- /crewai_sequential_BrowserbaseLoadTool_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# crewai-sequential-BrowserbaseLoadTool-quickstart\n", 33 | "By [Alex Fazio](https://www.x.com/alxfazio)\n", 34 | "\n", 35 | "📂 Github repo: https://github.com/alexfazio/crewai-quickstart\n", 36 | "\n", 37 | "Docs: https://docs.crewai.com/\n", 38 | "\n", 39 | "Simplified and tested template of a **sequential** CrewAI crew performing **web browsing** (BrowserbaseLoadTool).\n", 40 | "\n", 41 | "This crew uses the `BrowserbaseLoadTool` to run headless browsers on specific web pages.\n", 42 | "\n", 43 | "Browserbase is a serverless platform designed for operating headless browsers. It provides advanced debugging, session recordings, stealth mode, integrated proxies, and captcha solving.\n", 44 | "\n", 45 | "Requirements:\n", 46 | "- [OpenAI](https://platform.openai.com/playground)/[Groq](https://console.groq.com/settings/organization)/[Anthropic](https://console.anthropic.com/dashboard) API Key\n", 47 | "- Browserbase API Key: https://browserbase.com" 48 | ], 49 | "metadata": { 50 | "id": "ANCxcFs-qVl4" 51 | } 52 | }, 53 | { 54 | "metadata": { 55 | "cellView": "form", 56 | "id": "7wL1IPzxwCN8" 57 | }, 58 | "cell_type": "code", 59 | "outputs": [], 60 | "execution_count": null, 61 | "source": [ 62 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 63 | "# Warning control\n", 64 | "import warnings\n", 65 | "warnings.filterwarnings('ignore')" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "source": [ 71 | "# @title ⬇️ Install project dependencies by running this cell\n", 72 | "%pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 73 | "%pip install crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 74 | "print(\"---\")\n", 75 | "%pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 76 | ], 77 | "metadata": { 78 | "id": "P8iHNKCfk9Rv", 79 | "cellView": "form" 80 | }, 81 | "execution_count": null, 82 | "outputs": [] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": { 88 | "id": "BhAt-unGk4kA", 89 | "cellView": "form" 90 | }, 91 | "outputs": [], 92 | "source": [ 93 | "# @title 🔑 Input API Key by running this cell\n", 94 | "\n", 95 | "import os\n", 96 | "from getpass import getpass\n", 97 | "from crewai import Agent, Task, Crew, Process\n", 98 | "from textwrap import dedent\n", 99 | "from langchain_openai import ChatOpenAI\n", 100 | "# ↑ uncomment to use OpenAI's API\n", 101 | "# from langchain_groq import ChatGroq\n", 102 | "# ↑ uncomment to use Groq's API\n", 103 | "# from langchain_anthropic import ChatAnthropic\n", 104 | "# ↑ uncomment to use Antrhopic's API\n", 105 | "# from langchain_community.chat_models import ChatCohere\n", 106 | "# ↑ uncomment to use ChatCohere API\n", 107 | "\n", 108 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 109 | "# ↑ uncomment to use OpenAI's API\n", 110 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 111 | "# ↑ uncomment to use Groq's API\n", 112 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 113 | "# ↑ uncomment to use Anthropic's API\n", 114 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 115 | "# ↑ uncomment to use Cohere's API\n", 116 | "\n", 117 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 118 | "if not os.path.exists('output-files'):\n", 119 | " os.makedirs('output-files')" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "source": [ 125 | "# @title 🅱️ Input **BrowserBase** API Key by running this cell\n", 126 | "\n", 127 | "# @markdown Get an API key from https://browserbase.com.\n", 128 | "\n", 129 | "%pip install browserbase --quiet\n", 130 | "\n", 131 | "from crewai_tools import BrowserbaseLoadTool\n", 132 | "\n", 133 | "os.environ[\"BROWSERBASE_API_KEY\"] = getpass(\"Enter BROWSERBASE_API_KEY: \")\n", 134 | "\n", 135 | "browserbase_load_tool = BrowserbaseLoadTool()" 136 | ], 137 | "metadata": { 138 | "id": "IENZ1rmviDZY", 139 | "cellView": "form" 140 | }, 141 | "execution_count": null, 142 | "outputs": [] 143 | }, 144 | { 145 | "metadata": {}, 146 | "cell_type": "markdown", 147 | "source": [ 148 | "## Define Agents\n", 149 | "In CrewAI, agents are autonomous entities designed to perform specific roles and achieve particular goals. Each agent uses a language model (LLM) and may have specialized tools to help execute tasks." 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "source": [ 155 | "# @title 🕵🏻 Define your agents\n", 156 | "\n", 157 | "# Agent Definitions\n", 158 | "\n", 159 | "agent_1 = Agent(\n", 160 | " role=dedent((\n", 161 | " \"\"\"\n", 162 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 163 | " \"\"\")), # Think of this as the job title\n", 164 | " backstory=dedent((\n", 165 | " \"\"\"\n", 166 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 167 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 168 | " goal=dedent((\n", 169 | " \"\"\"\n", 170 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 171 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 172 | " tools=[browserbase_load_tool],\n", 173 | " allow_delegation=False,\n", 174 | " verbose=True,\n", 175 | " # ↑ Whether the agent execution should be in verbose mode\n", 176 | " max_iter=3,\n", 177 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 178 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 179 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 180 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 181 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 182 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 183 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 184 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 185 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 186 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 187 | ")\n", 188 | "\n", 189 | "agent_2 = Agent(\n", 190 | " role=dedent((\n", 191 | " \"\"\"\n", 192 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 193 | " \"\"\")), # Think of this as the job title\n", 194 | " backstory=dedent((\n", 195 | " \"\"\"\n", 196 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 197 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 198 | " goal=dedent((\n", 199 | " \"\"\"\n", 200 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 201 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 202 | " tools=[browserbase_load_tool],\n", 203 | " allow_delegation=False,\n", 204 | " verbose=True,\n", 205 | " # ↑ Whether the agent execution should be in verbose mode\n", 206 | " max_iter=3,\n", 207 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 208 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 209 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 210 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 211 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 212 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 213 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 214 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 215 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 216 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 217 | ")\n", 218 | "agent_3 = Agent(\n", 219 | " role=dedent((\n", 220 | " \"\"\"\n", 221 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 222 | " \"\"\")), # Think of this as the job title\n", 223 | " backstory=dedent((\n", 224 | " \"\"\"\n", 225 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 226 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 227 | " goal=dedent((\n", 228 | " \"\"\"\n", 229 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 230 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 231 | " tools=[browserbase_load_tool],\n", 232 | " allow_delegation=False,\n", 233 | " verbose=True,\n", 234 | " # ↑ Whether the agent execution should be in verbose mode\n", 235 | " max_iter=3,\n", 236 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 237 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 238 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 239 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 240 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 241 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 242 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 243 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 244 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 245 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 246 | ")" 247 | ], 248 | "metadata": { 249 | "id": "hZJwUoXasrhx", 250 | "cellView": "form" 251 | }, 252 | "execution_count": null, 253 | "outputs": [] 254 | }, 255 | { 256 | "metadata": {}, 257 | "cell_type": "markdown", 258 | "source": [ 259 | "## Define Tasks\n", 260 | "Tasks in CrewAI are specific assignments given to agents, detailing the actions they need to perform to achieve a particular goal. Tasks can have dependencies and context, and can be executed asynchronously to ensure an efficient workflow." 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "source": [ 266 | "# @title 📝 Define your tasks\n", 267 | "# Task Definitions\n", 268 | "\n", 269 | "task_1 = Task(\n", 270 | " description=dedent((\n", 271 | " \"\"\"\n", 272 | " A clear, concise statement of what the task entails.\n", 273 | " ---\n", 274 | " VARIABLE 1: \"{var_1}\"\n", 275 | " VARIABLE 2: \"{var_2}\"\n", 276 | " VARIABLE 3: \"{var_3}\"\n", 277 | " Add more variables if needed...\n", 278 | " \"\"\")),\n", 279 | " expected_output=dedent((\n", 280 | " \"\"\"\n", 281 | " A detailed description of what the task's completion looks like.\n", 282 | " \"\"\")),\n", 283 | " agent=agent_1,\n", 284 | " output_file=f'output-files/new_file_agent_1_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 285 | " # ↑ The output of each task iteration will be saved here\n", 286 | ")\n", 287 | "\n", 288 | "task_2 = Task(\n", 289 | " description=dedent((\n", 290 | " \"\"\"\n", 291 | " A clear, concise statement of what the task entails.\n", 292 | " ---\n", 293 | " VARIABLE 1: \"{var_1}\"\n", 294 | " VARIABLE 2: \"{var_2}\"\n", 295 | " VARIABLE 3: \"{var_3}\"\n", 296 | " Add more variables if needed...\n", 297 | " \"\"\")),\n", 298 | " expected_output=dedent((\n", 299 | " \"\"\"\n", 300 | " A detailed description of what the task's completion looks like.\n", 301 | " \"\"\")),\n", 302 | " agent=agent_2,\n", 303 | " context=[task_1],\n", 304 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 305 | " output_file=f'output-files/new_file_agent_2_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 306 | " # ↑ The output of each task iteration will be saved here\n", 307 | ")\n", 308 | "\n", 309 | "task_3 = Task(\n", 310 | " description=dedent((\n", 311 | " \"\"\"\n", 312 | " A clear, concise statement of what the task entails.\n", 313 | " ---\n", 314 | " VARIABLE 1: \"{var_1}\"\n", 315 | " VARIABLE 2: \"{var_2}\"\n", 316 | " VARIABLE 3: \"{var_3}\"\n", 317 | " Add more variables if needed...\n", 318 | " \"\"\")),\n", 319 | " expected_output=dedent((\n", 320 | " \"\"\"\n", 321 | " A detailed description of what the task's completion looks like.\n", 322 | " \"\"\")),\n", 323 | " agent=agent_3,\n", 324 | " context=[task_2],\n", 325 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 326 | " output_file=f'output-files/new_file_agent_3_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 327 | " # ↑ The output of each task iteration will be saved here\n", 328 | ")" 329 | ], 330 | "metadata": { 331 | "id": "dqtn3w1qs-Bu", 332 | "cellView": "form" 333 | }, 334 | "execution_count": null, 335 | "outputs": [] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "source": [ 340 | "# @title ⌨️ Define any variables you have and input them\n", 341 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 342 | "print('-------------------------------------------')\n", 343 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 344 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 345 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 346 | "print(\"-------------------------------\")" 347 | ], 348 | "metadata": { 349 | "id": "HfJRdGHesMwn", 350 | "cellView": "form" 351 | }, 352 | "execution_count": null, 353 | "outputs": [] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "source": [ 358 | "# @title 🚀 Get your crew to work!\n", 359 | "def main():\n", 360 | " # Instantiate your crew with a sequential process\n", 361 | " crew = Crew(\n", 362 | " agents=[agent_1, agent_2, agent_3],\n", 363 | " tasks=[task_1, task_2, task_3],\n", 364 | " verbose=True, # You can set it to True or False\n", 365 | " # ↑ indicates the verbosity level for logging during execution.\n", 366 | " process=Process.sequential\n", 367 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 368 | " )\n", 369 | "\n", 370 | " inputs = {\n", 371 | " \"var_1\": var_1,\n", 372 | " \"var_2\": var_2,\n", 373 | " \"var_3\": var_3\n", 374 | " }\n", 375 | "\n", 376 | " result = crew.kickoff(inputs=inputs)\n", 377 | " print(\"\\n\\n########################\")\n", 378 | " print(\"## Here is your custom crew run result:\")\n", 379 | " print(\"########################\\n\")\n", 380 | " print(result)\n", 381 | " \n", 382 | " return result\n", 383 | "\n", 384 | "if __name__ == \"__main__\":\n", 385 | " result = main()" 386 | ], 387 | "metadata": { 388 | "id": "nrBn8dMlxfCn", 389 | "cellView": "form" 390 | }, 391 | "execution_count": null, 392 | "outputs": [] 393 | }, 394 | { 395 | "cell_type": "code", 396 | "source": [ 397 | "# @title 🖥️ Display the results of your crew as markdown\n", 398 | "from IPython.display import display, Markdown\n", 399 | "\n", 400 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 401 | "\n", 402 | "# Display the markdown content\n", 403 | "display(Markdown(markdown_text))" 404 | ], 405 | "metadata": { 406 | "cellView": "form", 407 | "id": "oMHDoRY_xOZd" 408 | }, 409 | "execution_count": null, 410 | "outputs": [] 411 | } 412 | ] 413 | } 414 | -------------------------------------------------------------------------------- /crewai_sequential_SerperDevTool_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# crewai-sequential-SerperDevTool-quickstart\n", 33 | "By [Alex Fazio](https://www.x.com/alxfazio)\n", 34 | "\n", 35 | "Github repo: https://github.com/alexfazio/crewai-quickstart\n", 36 | "\n", 37 | "Docs: https://docs.crewai.com/\n", 38 | "\n", 39 | "Simplified and tested template of a **sequential** CrewAI crew performing **web searches** (SerperDevTool).\n", 40 | "\n", 41 | "Requirements:\n", 42 | "- [OpenAI](https://platform.openai.com/playground)/[Groq](https://console.groq.com/settings/organization)/[Anthropic](https://console.anthropic.com/dashboard) API Key\n", 43 | "- Serper API Key: https://serper.dev/" 44 | ], 45 | "metadata": { 46 | "id": "ANCxcFs-qVl4" 47 | } 48 | }, 49 | { 50 | "metadata": { 51 | "cellView": "form", 52 | "id": "43x2WAppv229" 53 | }, 54 | "cell_type": "code", 55 | "outputs": [], 56 | "execution_count": null, 57 | "source": [ 58 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 59 | "# Warning control\n", 60 | "import warnings\n", 61 | "warnings.filterwarnings('ignore')\n", 62 | "\n", 63 | "# To avoid the restart session warning in Colab, exclude the PIL and\n", 64 | "# pydevd_plugins packages from being imported. This is fine because\n", 65 | "# we didn't execute the code in the kernel session afterward.\n", 66 | "\n", 67 | "# import sys\n", 68 | "# sys.modules.pop('PIL', None)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "source": [ 74 | "# @title ⬇️ Install project dependencies by running this cell\n", 75 | "%pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 76 | "%pip install crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 77 | "print(\"---\")\n", 78 | "%pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 79 | ], 80 | "metadata": { 81 | "id": "P8iHNKCfk9Rv", 82 | "cellView": "form" 83 | }, 84 | "execution_count": null, 85 | "outputs": [] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": { 91 | "id": "BhAt-unGk4kA", 92 | "cellView": "form" 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "# @title 🔑 Input API Key by running this cell\n", 97 | "\n", 98 | "import os\n", 99 | "from getpass import getpass\n", 100 | "from crewai import Agent, Task, Crew, Process\n", 101 | "from textwrap import dedent\n", 102 | "from langchain_openai import ChatOpenAI\n", 103 | "# ↑ uncomment to use OpenAI's API\n", 104 | "# from langchain_groq import ChatGroq\n", 105 | "# ↑ uncomment to use Groq's API\n", 106 | "# from langchain_anthropic import ChatAnthropic\n", 107 | "# ↑ uncomment to use Antrhopic's API\n", 108 | "# from langchain_community.chat_models import ChatCohere\n", 109 | "# ↑ uncomment to use ChatCohere API\n", 110 | "\n", 111 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 112 | "# ↑ uncomment to use OpenAI's API\n", 113 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 114 | "# ↑ uncomment to use Groq's API\n", 115 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 116 | "# ↑ uncomment to use Anthropic's API\n", 117 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 118 | "# ↑ uncomment to use Cohere's API\n", 119 | "\n", 120 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 121 | "if not os.path.exists('output-files'):\n", 122 | " os.makedirs('output-files')" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "source": [ 128 | "# @title 🔑 Input **Serper** API Key by running this cell\n", 129 | "\n", 130 | "from crewai_tools import SerperDevTool\n", 131 | "\n", 132 | "# Instantiate tools\n", 133 | "\n", 134 | "# Set the SERPER_API_KEY environment variable by prompting the user to enter the key\n", 135 | "# The Serper API key is required to use the Serper search tool (https://serper.dev)\n", 136 | "os.environ[\"SERPER_API_KEY\"] = getpass(\"Enter SERPER_API_KEY: \")\n", 137 | "\n", 138 | "# Create an instance of the SerperDevTool class\n", 139 | "# This tool allows performing searches using the Serper API\n", 140 | "search_tool = SerperDevTool()" 141 | ], 142 | "metadata": { 143 | "id": "IENZ1rmviDZY", 144 | "cellView": "form" 145 | }, 146 | "execution_count": null, 147 | "outputs": [] 148 | }, 149 | { 150 | "metadata": {}, 151 | "cell_type": "markdown", 152 | "source": [ 153 | "## Define Agents\n", 154 | "In CrewAI, agents are autonomous entities designed to perform specific roles and achieve particular goals. Each agent uses a language model (LLM) and may have specialized tools to help execute tasks." 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "source": [ 160 | "# @title 🕵🏻 Define your agents\n", 161 | "\n", 162 | "# Agent Definitions\n", 163 | "\n", 164 | "agent_1 = Agent(\n", 165 | " role=dedent((\n", 166 | " \"\"\"\n", 167 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 168 | " \"\"\")), # Think of this as the job title\n", 169 | " backstory=dedent((\n", 170 | " \"\"\"\n", 171 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 172 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 173 | " goal=dedent((\n", 174 | " \"\"\"\n", 175 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 176 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 177 | " tools=[search_tool],\n", 178 | " allow_delegation=False,\n", 179 | " verbose=True,\n", 180 | " # ↑ Whether the agent execution should be in verbose mode\n", 181 | " max_iter=3,\n", 182 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 183 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 184 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 185 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 186 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 187 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 188 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 189 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 190 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 191 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 192 | ")\n", 193 | "\n", 194 | "agent_2 = Agent(\n", 195 | " role=dedent((\n", 196 | " \"\"\"\n", 197 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 198 | " \"\"\")), # Think of this as the job title\n", 199 | " backstory=dedent((\n", 200 | " \"\"\"\n", 201 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 202 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 203 | " goal=dedent((\n", 204 | " \"\"\"\n", 205 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 206 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 207 | " tools=[search_tool],\n", 208 | " allow_delegation=False,\n", 209 | " verbose=True,\n", 210 | " # ↑ Whether the agent execution should be in verbose mode\n", 211 | " max_iter=3,\n", 212 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 213 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 214 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 215 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 216 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 217 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 218 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 219 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 220 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 221 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 222 | ")\n", 223 | "agent_3 = Agent(\n", 224 | " role=dedent((\n", 225 | " \"\"\"\n", 226 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 227 | " \"\"\")), # Think of this as the job title\n", 228 | " backstory=dedent((\n", 229 | " \"\"\"\n", 230 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 231 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 232 | " goal=dedent((\n", 233 | " \"\"\"\n", 234 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 235 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 236 | " tools=[search_tool],\n", 237 | " allow_delegation=False,\n", 238 | " verbose=True,\n", 239 | " # ↑ Whether the agent execution should be in verbose mode\n", 240 | " max_iter=3,\n", 241 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 242 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 243 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 244 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 245 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 246 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 247 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 248 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 249 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 250 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 251 | ")" 252 | ], 253 | "metadata": { 254 | "id": "hZJwUoXasrhx", 255 | "cellView": "form" 256 | }, 257 | "execution_count": null, 258 | "outputs": [] 259 | }, 260 | { 261 | "metadata": {}, 262 | "cell_type": "markdown", 263 | "source": [ 264 | "## Define Tasks\n", 265 | "Tasks in CrewAI are specific assignments given to agents, detailing the actions they need to perform to achieve a particular goal. Tasks can have dependencies and context, and can be executed asynchronously to ensure an efficient workflow." 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "source": [ 271 | "# @title 📝 Define your tasks\n", 272 | "# Task Definitions\n", 273 | "\n", 274 | "import datetime\n", 275 | "\n", 276 | "task_1 = Task(\n", 277 | " description=dedent((\n", 278 | " \"\"\"\n", 279 | " A clear, concise statement of what the task entails.\n", 280 | " ---\n", 281 | " VARIABLE 1: \"{var_1}\"\n", 282 | " VARIABLE 2: \"{var_2}\"\n", 283 | " VARIABLE 3: \"{var_3}\"\n", 284 | " Add more variables if needed...\n", 285 | " \"\"\")),\n", 286 | " expected_output=dedent((\n", 287 | " \"\"\"\n", 288 | " A detailed description of what the task's completion looks like.\n", 289 | " \"\"\")),\n", 290 | " agent=agent_1,\n", 291 | " output_file=f'output-files/new_file_agent_1_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 292 | " # ↑ The output of each task iteration will be saved here\n", 293 | ")\n", 294 | "\n", 295 | "task_2 = Task(\n", 296 | " description=dedent((\n", 297 | " \"\"\"\n", 298 | " A clear, concise statement of what the task entails.\n", 299 | " ---\n", 300 | " VARIABLE 1: \"{var_1}\"\n", 301 | " VARIABLE 2: \"{var_2}\"\n", 302 | " VARIABLE 3: \"{var_3}\"\n", 303 | " Add more variables if needed...\n", 304 | " \"\"\")),\n", 305 | " expected_output=dedent((\n", 306 | " \"\"\"\n", 307 | " A detailed description of what the task's completion looks like.\n", 308 | " \"\"\")),\n", 309 | " agent=agent_2,\n", 310 | " context=[task_1],\n", 311 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 312 | " output_file=f'output-files/new_file_agent_2_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 313 | " # ↑ The output of each task iteration will be saved here\n", 314 | ")\n", 315 | "\n", 316 | "task_3 = Task(\n", 317 | " description=dedent((\n", 318 | " \"\"\"\n", 319 | " A clear, concise statement of what the task entails.\n", 320 | " ---\n", 321 | " VARIABLE 1: \"{var_1}\"\n", 322 | " VARIABLE 2: \"{var_2}\"\n", 323 | " VARIABLE 3: \"{var_3}\"\n", 324 | " Add more variables if needed...\n", 325 | " \"\"\")),\n", 326 | " expected_output=dedent((\n", 327 | " \"\"\"\n", 328 | " A detailed description of what the task's completion looks like.\n", 329 | " \"\"\")),\n", 330 | " agent=agent_3,\n", 331 | " context=[task_2],\n", 332 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 333 | " output_file=f'output-files/new_file_agent_3_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 334 | " # ↑ The output of each task iteration will be saved here\n", 335 | ")" 336 | ], 337 | "metadata": { 338 | "id": "dqtn3w1qs-Bu", 339 | "cellView": "form" 340 | }, 341 | "execution_count": null, 342 | "outputs": [] 343 | }, 344 | { 345 | "cell_type": "code", 346 | "source": [ 347 | "# @title ⌨️ Define any variables you have and input them\n", 348 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 349 | "print('-------------------------------------------')\n", 350 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 351 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 352 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 353 | "print(\"-------------------------------\")" 354 | ], 355 | "metadata": { 356 | "id": "HfJRdGHesMwn", 357 | "cellView": "form" 358 | }, 359 | "execution_count": null, 360 | "outputs": [] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "source": [ 365 | "# @title 🚀 Get your crew to work!\n", 366 | "def main():\n", 367 | " # Instantiate your crew with a sequential process\n", 368 | " crew = Crew(\n", 369 | " agents=[agent_1, agent_2, agent_3],\n", 370 | " tasks=[task_1, task_2, task_3],\n", 371 | " verbose=True, # You can set it to True or False\n", 372 | " # ↑ indicates the verbosity level for logging during execution.\n", 373 | " process=Process.sequential\n", 374 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 375 | " )\n", 376 | "\n", 377 | " inputs = {\n", 378 | " \"var_1\": var_1,\n", 379 | " \"var_2\": var_2,\n", 380 | " \"var_3\": var_3\n", 381 | " }\n", 382 | "\n", 383 | " result = crew.kickoff(inputs=inputs)\n", 384 | " print(\"\\n\\n########################\")\n", 385 | " print(\"## Here is your custom crew run result:\")\n", 386 | " print(\"########################\\n\")\n", 387 | " print(result)\n", 388 | " \n", 389 | " return result\n", 390 | "\n", 391 | "if __name__ == \"__main__\":\n", 392 | " result = main()" 393 | ], 394 | "metadata": { 395 | "id": "nrBn8dMlxfCn", 396 | "cellView": "form" 397 | }, 398 | "execution_count": null, 399 | "outputs": [] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "source": [ 404 | "# @title 🖥️ Display the results of your crew as markdown\n", 405 | "from IPython.display import display, Markdown\n", 406 | "\n", 407 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 408 | "\n", 409 | "# Display the markdown content\n", 410 | "display(Markdown(markdown_text))" 411 | ], 412 | "metadata": { 413 | "cellView": "form", 414 | "id": "r-Xl4P3AxFSJ" 415 | }, 416 | "execution_count": null, 417 | "outputs": [] 418 | } 419 | ] 420 | } 421 | -------------------------------------------------------------------------------- /crewai_sequential_composio_core_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# crewai_sequential_composio_core_quickstart\n", 33 | "By [Alex Fazio](https://www.x.com/alxfazio)\n", 34 | "\n", 35 | "Github repo: https://github.com/alexfazio/crewai-quickstart\n", 36 | "\n", 37 | "Docs: https://docs.crewai.com/tools/ComposioTool\n", 38 | "\n", 39 | "Simplified and tested template of a **sequential** CrewAI crew using the ComposioTool to provide the agent with access to a wide variety of tools from the **Composio SDK**.\n", 40 | "\n", 41 | "Requirements:\n", 42 | "- [OpenAI](https://platform.openai.com/playground)/[Groq](https://console.groq.com/settings/organization)/[Anthropic](https://console.anthropic.com/dashboard) API Key\n", 43 | "- Serper API Key: https://serper.dev/" 44 | ], 45 | "metadata": { 46 | "id": "ANCxcFs-qVl4" 47 | } 48 | }, 49 | { 50 | "metadata": { 51 | "id": "43x2WAppv229" 52 | }, 53 | "cell_type": "code", 54 | "outputs": [], 55 | "execution_count": null, 56 | "source": [ 57 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 58 | "# Warning control\n", 59 | "import warnings\n", 60 | "warnings.filterwarnings('ignore')\n", 61 | "\n", 62 | "# To avoid the restart session warning in Colab, exclude the PIL and\n", 63 | "# pydevd_plugins packages from being imported. This is fine because\n", 64 | "# we didn't execute the code in the kernel session afterward.\n", 65 | "\n", 66 | "# import sys\n", 67 | "# sys.modules.pop('PIL', None)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "source": [ 73 | "# @title ⬇️ Install project dependencies by running this cell\n", 74 | "\n", 75 | "!pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 76 | "!pip install crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 77 | "print(\"---\")\n", 78 | "!pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 79 | ], 80 | "metadata": { 81 | "id": "P8iHNKCfk9Rv", 82 | "cellView": "form" 83 | }, 84 | "execution_count": null, 85 | "outputs": [] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": { 91 | "id": "BhAt-unGk4kA", 92 | "cellView": "form" 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "# @title 🔑 Input LLM API Key by running this cell\n", 97 | "\n", 98 | "import os\n", 99 | "from getpass import getpass\n", 100 | "from crewai import Agent, Task, Crew, Process\n", 101 | "from textwrap import dedent\n", 102 | "from langchain_openai import ChatOpenAI\n", 103 | "# ↑ uncomment to use OpenAI's API\n", 104 | "# from langchain_groq import ChatGroq\n", 105 | "# ↑ uncomment to use Groq's API\n", 106 | "# from langchain_anthropic import ChatAnthropic\n", 107 | "# ↑ uncomment to use Antrhopic's API\n", 108 | "# from langchain_community.chat_models import ChatCohere\n", 109 | "# ↑ uncomment to use ChatCohere API\n", 110 | "\n", 111 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 112 | "# ↑ uncomment to use OpenAI's API\n", 113 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 114 | "# ↑ uncomment to use Groq's API\n", 115 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 116 | "# ↑ uncomment to use Anthropic's API\n", 117 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 118 | "# ↑ uncomment to use Cohere's API\n", 119 | "\n", 120 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 121 | "if not os.path.exists('output-files'):\n", 122 | " os.makedirs('output-files')" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "source": [ 128 | "# @title 🔑 Input **Composio** API Key by running this cell\n", 129 | "\n", 130 | "# Set the COMPOSIO_API_KEY environment variable by prompting the user to enter the key\n", 131 | "# The COMPOSIO_API_KEY key is required to use the Composio SDK tool (https://app.composio.dev/)\n", 132 | "os.environ[\"COMPOSIO_API_KEY\"] = getpass(\"Enter COMPOSIO_API_KEY: \")" 133 | ], 134 | "metadata": { 135 | "id": "IENZ1rmviDZY", 136 | "cellView": "form" 137 | }, 138 | "execution_count": null, 139 | "outputs": [] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "source": [ 144 | "# @title 🧩 Instantiate `ComposioTool`\n", 145 | "\n", 146 | "%pip install composio_crewai composio-core --quiet\n", 147 | "!composio apps update\n", 148 | "!composio add {tool.app}\n", 149 | "\n", 150 | "from composio import App\n", 151 | "from composio_crewai import ComposioToolSet, Action\n", 152 | "from crewai_tools import ComposioTool\n", 153 | "\n", 154 | "# Define which Composio action you wish to use (https://app.composio.dev/apps)\n", 155 | "action = Action.SERPAPI_SEARCH\n", 156 | "\n", 157 | "# Create an instance of the ComposioTool class\n", 158 | "composio_tool = [ComposioTool.from_action(action)]" 159 | ], 160 | "metadata": { 161 | "cellView": "form", 162 | "id": "40zyverY4Eu8" 163 | }, 164 | "execution_count": null, 165 | "outputs": [] 166 | }, 167 | { 168 | "metadata": {}, 169 | "cell_type": "markdown", 170 | "source": [ 171 | "## Define Agents\n", 172 | "In CrewAI, agents are autonomous entities designed to perform specific roles and achieve particular goals. Each agent uses a language model (LLM) and may have specialized tools to help execute tasks." 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "source": [ 178 | "# @title 🕵🏻 Define your agents\n", 179 | "\n", 180 | "# Agent Definitions\n", 181 | "\n", 182 | "agent_1 = Agent(\n", 183 | " role=dedent((\n", 184 | " \"\"\"\n", 185 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 186 | " \"\"\")), # Think of this as the job title\n", 187 | " backstory=dedent((\n", 188 | " \"\"\"\n", 189 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 190 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 191 | " goal=dedent((\n", 192 | " \"\"\"\n", 193 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 194 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 195 | " tools=composio_tool,\n", 196 | " allow_delegation=False,\n", 197 | " verbose=True,\n", 198 | " # ↑ Whether the agent execution should be in verbose mode\n", 199 | " max_iter=3,\n", 200 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 201 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 202 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 203 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 204 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 205 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 206 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 207 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 208 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 209 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 210 | ")\n", 211 | "\n", 212 | "agent_2 = Agent(\n", 213 | " role=dedent((\n", 214 | " \"\"\"\n", 215 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 216 | " \"\"\")), # Think of this as the job title\n", 217 | " backstory=dedent((\n", 218 | " \"\"\"\n", 219 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 220 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 221 | " goal=dedent((\n", 222 | " \"\"\"\n", 223 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 224 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 225 | " tools=composio_tool,\n", 226 | " allow_delegation=False,\n", 227 | " verbose=True,\n", 228 | " # ↑ Whether the agent execution should be in verbose mode\n", 229 | " max_iter=3,\n", 230 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 231 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 232 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 233 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 234 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 235 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 236 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 237 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 238 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 239 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 240 | ")\n", 241 | "agent_3 = Agent(\n", 242 | " role=dedent((\n", 243 | " \"\"\"\n", 244 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 245 | " \"\"\")), # Think of this as the job title\n", 246 | " backstory=dedent((\n", 247 | " \"\"\"\n", 248 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 249 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 250 | " goal=dedent((\n", 251 | " \"\"\"\n", 252 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 253 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 254 | " tools=composio_tool,\n", 255 | " allow_delegation=False,\n", 256 | " verbose=True,\n", 257 | " # ↑ Whether the agent execution should be in verbose mode\n", 258 | " max_iter=3,\n", 259 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 260 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 261 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 262 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 263 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 264 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 265 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 266 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 267 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 268 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 269 | ")" 270 | ], 271 | "metadata": { 272 | "id": "hZJwUoXasrhx", 273 | "cellView": "form" 274 | }, 275 | "execution_count": null, 276 | "outputs": [] 277 | }, 278 | { 279 | "metadata": {}, 280 | "cell_type": "markdown", 281 | "source": [ 282 | "## Define Tasks\n", 283 | "Tasks in CrewAI are specific assignments given to agents, detailing the actions they need to perform to achieve a particular goal. Tasks can have dependencies and context, and can be executed asynchronously to ensure an efficient workflow." 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "source": [ 289 | "# @title 📝 Define your tasks\n", 290 | "# Task Definitions\n", 291 | "\n", 292 | "import datetime\n", 293 | "\n", 294 | "task_1 = Task(\n", 295 | " description=dedent((\n", 296 | " \"\"\"\n", 297 | " A clear, concise statement of what the task entails.\n", 298 | " ---\n", 299 | " VARIABLE 1: \"{var_1}\"\n", 300 | " VARIABLE 2: \"{var_2}\"\n", 301 | " VARIABLE 3: \"{var_3}\"\n", 302 | " Add more variables if needed...\n", 303 | " \"\"\")),\n", 304 | " expected_output=dedent((\n", 305 | " \"\"\"\n", 306 | " A detailed description of what the task's completion looks like.\n", 307 | " \"\"\")),\n", 308 | " agent=agent_1,\n", 309 | " output_file=f'output-files/new_file_agent_1_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 310 | " # ↑ The output of each task iteration will be saved here\n", 311 | ")\n", 312 | "\n", 313 | "task_2 = Task(\n", 314 | " description=dedent((\n", 315 | " \"\"\"\n", 316 | " A clear, concise statement of what the task entails.\n", 317 | " ---\n", 318 | " VARIABLE 1: \"{var_1}\"\n", 319 | " VARIABLE 2: \"{var_2}\"\n", 320 | " VARIABLE 3: \"{var_3}\"\n", 321 | " Add more variables if needed...\n", 322 | " \"\"\")),\n", 323 | " expected_output=dedent((\n", 324 | " \"\"\"\n", 325 | " A detailed description of what the task's completion looks like.\n", 326 | " \"\"\")),\n", 327 | " agent=agent_2,\n", 328 | " context=[task_1],\n", 329 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 330 | " output_file=f'output-files/new_file_agent_2_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 331 | " # ↑ The output of each task iteration will be saved here\n", 332 | ")\n", 333 | "\n", 334 | "task_3 = Task(\n", 335 | " description=dedent((\n", 336 | " \"\"\"\n", 337 | " A clear, concise statement of what the task entails.\n", 338 | " ---\n", 339 | " VARIABLE 1: \"{var_1}\"\n", 340 | " VARIABLE 2: \"{var_2}\"\n", 341 | " VARIABLE 3: \"{var_3}\"\n", 342 | " Add more variables if needed...\n", 343 | " \"\"\")),\n", 344 | " expected_output=dedent((\n", 345 | " \"\"\"\n", 346 | " A detailed description of what the task's completion looks like.\n", 347 | " \"\"\")),\n", 348 | " agent=agent_3,\n", 349 | " context=[task_2],\n", 350 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 351 | " output_file=f'output-files/new_file_agent_3_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 352 | " # ↑ The output of each task iteration will be saved here\n", 353 | ")" 354 | ], 355 | "metadata": { 356 | "id": "dqtn3w1qs-Bu", 357 | "cellView": "form" 358 | }, 359 | "execution_count": null, 360 | "outputs": [] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "source": [ 365 | "# @title ⌨️ Define any variables you have and input them\n", 366 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 367 | "print('-------------------------------------------')\n", 368 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 369 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 370 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 371 | "print(\"-------------------------------\")" 372 | ], 373 | "metadata": { 374 | "id": "HfJRdGHesMwn", 375 | "cellView": "form" 376 | }, 377 | "execution_count": null, 378 | "outputs": [] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "source": [ 383 | "# @title 🚀 Get your crew to work!\n", 384 | "def main():\n", 385 | " # Instantiate your crew with a sequential process\n", 386 | " crew = Crew(\n", 387 | " agents=[agent_1, agent_2, agent_3],\n", 388 | " tasks=[task_1, task_2, task_3],\n", 389 | " verbose=True, # You can set it to True or False\n", 390 | " # ↑ indicates the verbosity level for logging during execution.\n", 391 | " process=Process.sequential\n", 392 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 393 | " )\n", 394 | "\n", 395 | " inputs = {\n", 396 | " \"var_1\": var_1,\n", 397 | " \"var_2\": var_2,\n", 398 | " \"var_3\": var_3\n", 399 | " }\n", 400 | "\n", 401 | " result = crew.kickoff(inputs=inputs)\n", 402 | " print(\"\\n\\n########################\")\n", 403 | " print(\"## Here is your custom crew run result:\")\n", 404 | " print(\"########################\\n\")\n", 405 | " print(result)\n", 406 | "\n", 407 | " return result\n", 408 | "\n", 409 | "if __name__ == \"__main__\":\n", 410 | " result = main()" 411 | ], 412 | "metadata": { 413 | "id": "nrBn8dMlxfCn", 414 | "cellView": "form" 415 | }, 416 | "execution_count": null, 417 | "outputs": [] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "source": [ 422 | "# @title 🖥️ Display the results of your crew as markdown\n", 423 | "from IPython.display import display, Markdown\n", 424 | "\n", 425 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 426 | "\n", 427 | "# Display the markdown content\n", 428 | "display(Markdown(markdown_text))" 429 | ], 430 | "metadata": { 431 | "cellView": "form", 432 | "id": "r-Xl4P3AxFSJ" 433 | }, 434 | "execution_count": null, 435 | "outputs": [] 436 | } 437 | ] 438 | } 439 | -------------------------------------------------------------------------------- /crewai_sequential_CodeInterpreterTool_quickstart.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "private_outputs": true, 7 | "provenance": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# crewai-sequential-CodeInterpreterTool-quickstart\n", 33 | "By [Alex Fazio](https://www.x.com/in/alxfazio)\n", 34 | "\n", 35 | "📂 Github repo: https://github.com/alexfazio/CodeInterpreterTool-quickstart\n", 36 | "\n", 37 | "Simplified and tested template of a **sequential** CodeInterpreterTool for interpreting **Python code**.\n", 38 | "\n", 39 | "This tool is used to give the Agent the ability to run code (Python3) from the code generated by the Agent itself. The code is executed in a sandboxed environment, so it is safe to run any code.\n", 40 | "\n", 41 | "It is incredible useful since it allows the Agent to generate code, run it in the same environment, get the result and use it to make decisions.\n", 42 | "\n", 43 | "Extra Requirements:\n", 44 | "- [OpenAI](https://platform.openai.com/playground)/[Groq](https://console.groq.com/settings/organization)/[Anthropic](https://console.anthropic.com/dashboard) API Key\n", 45 | "\n", 46 | "📚 CodeInterpreterTool docs: https://docs.crewai.com/tools/CodeInterpreterTool/\n", 47 | "\n", 48 | "📚 Python Interpreter docs: https://docs.python.org/3/\n" 49 | ], 50 | "metadata": { 51 | "id": "ANCxcFs-qVl4" 52 | } 53 | }, 54 | { 55 | "metadata": { 56 | "id": "PkwONSCBwAdO", 57 | "cellView": "form" 58 | }, 59 | "cell_type": "code", 60 | "outputs": [], 61 | "execution_count": null, 62 | "source": [ 63 | "# @title 👨‍🦯 Run this cell to hide all warnings (optional)\n", 64 | "# Warning control\n", 65 | "\n", 66 | "import warnings\n", 67 | "warnings.filterwarnings('ignore')\n", 68 | "\n", 69 | "# To avoid the restart session warning in Colab, exclude the PIL and\n", 70 | "# pydevd_plugins packages from being imported. This is fine because\n", 71 | "# we didn't execute the code in the kernel session afterward.\n", 72 | "# import sys\n", 73 | "# sys.modules.pop('PIL', None)" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "source": [ 79 | "# @title ⬇️ Install project dependencies by running this cell\n", 80 | "# @markdown 🔄 Restart the session and rerun the cell **if Colab requires it**.\n", 81 | "\n", 82 | "%pip install git+https://github.com/joaomdmoura/crewAI.git --quiet\n", 83 | "%pip install crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere --quiet\n", 84 | "print(\"---\")\n", 85 | "%pip show crewAI crewai_tools langchain_openai langchain_groq langchain_anthropic langchain_community cohere" 86 | ], 87 | "metadata": { 88 | "id": "P8iHNKCfk9Rv", 89 | "cellView": "form" 90 | }, 91 | "execution_count": null, 92 | "outputs": [] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": { 98 | "id": "BhAt-unGk4kA", 99 | "cellView": "form" 100 | }, 101 | "outputs": [], 102 | "source": [ 103 | "# @title 🔑 Input API Key by running this cell\n", 104 | "\n", 105 | "import os\n", 106 | "from getpass import getpass\n", 107 | "from crewai import Agent, Task, Crew, Process\n", 108 | "from textwrap import dedent\n", 109 | "from langchain_openai import ChatOpenAI\n", 110 | "# ↑ uncomment to use OpenAI's API\n", 111 | "# from langchain_groq import ChatGroq\n", 112 | "# ↑ uncomment to use Groq's API\n", 113 | "# from langchain_anthropic import ChatAnthropic\n", 114 | "# ↑ uncomment to use Antrhopic's API\n", 115 | "# from langchain_community.chat_models import ChatCohere\n", 116 | "# ↑ uncomment to use ChatCohere API\n", 117 | "\n", 118 | "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter OPENAI_API_KEY: \")\n", 119 | "# ↑ uncomment to use OpenAI's API\n", 120 | "# os.environ[\"GROQ_API_KEY\"] = getpass(\"Enter GROQ_API_KEY: \")\n", 121 | "# ↑ uncomment to use Groq's API\n", 122 | "# os.environ[\"ANTHROPIC_API_KEY\"] = getpass(\"Enter ANTHROPIC_API_KEY: \")\n", 123 | "# ↑ uncomment to use Anthropic's API\n", 124 | "# os.environ[\"COHERE_API_KEY\"] = getpass(\"Enter COHERE_API_KEY: \")\n", 125 | "# ↑ uncomment to use Cohere's API\n", 126 | "\n", 127 | "# Check if the 'output-files' directory exists, and create it if it doesn't\n", 128 | "if not os.path.exists('output-files'):\n", 129 | " os.makedirs('output-files')" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "source": [ 135 | "# @title Instantiate `CodeInterpreterTool`\n", 136 | "\n", 137 | "from crewai import Agent, Task, Crew, Process\n", 138 | "from langchain_community.chat_models import ChatOpenAI\n", 139 | "from crewai_tools import CodeInterpreterTool\n", 140 | "\n", 141 | "# Instantiate tools\n", 142 | "\n", 143 | "# This tool is used to give the Agent the ability to run code (Python3) from the code generated by the Agent itself. The code is executed in a sandboxed environment, so it is safe to run any code.\n", 144 | "\n", 145 | "code_interpreter_tool = CodeInterpreterTool()" 146 | ], 147 | "metadata": { 148 | "id": "IENZ1rmviDZY", 149 | "cellView": "form" 150 | }, 151 | "execution_count": null, 152 | "outputs": [] 153 | }, 154 | { 155 | "metadata": {}, 156 | "cell_type": "markdown", 157 | "source": [ 158 | "## Define Agents\n", 159 | "In CrewAI, agents are autonomous entities designed to perform specific roles and achieve particular goals. Each agent uses a language model (LLM) and may have specialized tools to help execute tasks." 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "source": [ 165 | "# @title 🕵🏻 Define your agents\n", 166 | "\n", 167 | "# from langchain_groq import ChatGroq\n", 168 | "# ↑ Uncomment to use Groq's API\n", 169 | "# from langchain_anthropic import ChatAnthropic\n", 170 | "# ↑ Uncomment to use Anthropic's API\n", 171 | "\n", 172 | "agent_1 = Agent(\n", 173 | " role=dedent((\n", 174 | " \"\"\"\n", 175 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 176 | " \"\"\")), # Think of this as the job title\n", 177 | " backstory=dedent((\n", 178 | " \"\"\"\n", 179 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 180 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 181 | " goal=dedent((\n", 182 | " \"\"\"\n", 183 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 184 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 185 | " tools=[code_interpreter_tool],\n", 186 | " allow_delegation=False,\n", 187 | " verbose=True,\n", 188 | " # ↑ Whether the agent execution should be in verbose mode\n", 189 | " max_iter=3,\n", 190 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 191 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 192 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 193 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 194 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 195 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 196 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 197 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 198 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 199 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 200 | ")\n", 201 | "\n", 202 | "agent_2 = Agent(\n", 203 | " role=dedent((\n", 204 | " \"\"\"\n", 205 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 206 | " \"\"\")), # Think of this as the job title\n", 207 | " backstory=dedent((\n", 208 | " \"\"\"\n", 209 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 210 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 211 | " goal=dedent((\n", 212 | " \"\"\"\n", 213 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 214 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 215 | " tools=[code_interpreter_tool],\n", 216 | " allow_delegation=False,\n", 217 | " verbose=True,\n", 218 | " # ↑ Whether the agent execution should be in verbose mode\n", 219 | " max_iter=3,\n", 220 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 221 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 222 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 223 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 224 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 225 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 226 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 227 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 228 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 229 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 230 | ")\n", 231 | "\n", 232 | "agent_3 = Agent(\n", 233 | " role=dedent((\n", 234 | " \"\"\"\n", 235 | " Defines the agent's function within the crew. It determines the kind of tasks the agent is best suited for.\n", 236 | " \"\"\")), # Think of this as the job title\n", 237 | " backstory=dedent((\n", 238 | " \"\"\"\n", 239 | " Provides context to the agent's role and goal, enriching the interaction and collaboration dynamics.\n", 240 | " \"\"\")), # This is the backstory of the agent, this helps the agent to understand the context of the task\n", 241 | " goal=dedent((\n", 242 | " \"\"\"\n", 243 | " The individual objective that the agent aims to achieve. It guides the agent's decision-making process.\n", 244 | " \"\"\")), # This is the goal that the agent is trying to achieve\n", 245 | " tools=[code_interpreter_tool],\n", 246 | " allow_delegation=False,\n", 247 | " verbose=True,\n", 248 | " # ↑ Whether the agent execution should be in verbose mode\n", 249 | " max_iter=3,\n", 250 | " # ↑ maximum number of iterations the agent can perform before being forced to give its best answer (generate the output)\n", 251 | " max_rpm=100, # This is the maximum number of requests per minute that the agent can make to the language model\n", 252 | " llm=ChatOpenAI(model_name=\"gpt-4o\", temperature=0.8)\n", 253 | " # ↑ uncomment to use OpenAI API + \"gpt-4o\"\n", 254 | " # llm=ChatGroq(temperature=0.8, model_name=\"mixtral-8x7b-32768\"),\n", 255 | " # ↑ uncomment to use Groq's API + \"llama3-70b-8192\"\n", 256 | " # llm=ChatGroq(temperature=0.6, model_name=\"llama3-70b-8192\"),\n", 257 | " # ↑ uncomment to use Groq's API + \"mixtral-8x7b-32768\"\n", 258 | " # llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0.8),\n", 259 | " # ↑ uncomment to use Anthropic's API + \"claude-3-opus-20240229\"\n", 260 | ")" 261 | ], 262 | "metadata": { 263 | "id": "hZJwUoXasrhx", 264 | "cellView": "form" 265 | }, 266 | "execution_count": null, 267 | "outputs": [] 268 | }, 269 | { 270 | "metadata": {}, 271 | "cell_type": "markdown", 272 | "source": [ 273 | "## Define Tasks\n", 274 | "Tasks in CrewAI are specific assignments given to agents, detailing the actions they need to perform to achieve a particular goal. Tasks can have dependencies and context, and can be executed asynchronously to ensure an efficient workflow." 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "source": [ 280 | "# @title 📝 Define your tasks\n", 281 | "\n", 282 | "import datetime\n", 283 | "\n", 284 | "task_1 = Task(\n", 285 | " description=dedent((\n", 286 | " \"\"\"\n", 287 | " A clear, concise statement of what the task entails.\n", 288 | " ---\n", 289 | " VARIABLE 1: \"{var_1}\"\n", 290 | " VARIABLE 2: \"{var_2}\"\n", 291 | " VARIABLE 3: \"{var_3}\"\n", 292 | " Add more variables if needed...\n", 293 | " \"\"\")),\n", 294 | " expected_output=dedent((\n", 295 | " \"\"\"\n", 296 | " A detailed description of what the task's completion looks like.\n", 297 | " \"\"\")),\n", 298 | " agent=agent_1,\n", 299 | " output_file=f'output-files/agent_1-output_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 300 | " # ↑ The output of each task iteration will be saved here\n", 301 | ")\n", 302 | "\n", 303 | "task_2 = Task(\n", 304 | " description=dedent((\n", 305 | " \"\"\"\n", 306 | " A clear, concise statement of what the task entails.\n", 307 | " ---\n", 308 | " VARIABLE 1: \"{var_1}\"\n", 309 | " VARIABLE 2: \"{var_2}\"\n", 310 | " VARIABLE 3: \"{var_3}\"\n", 311 | " Add more variables if needed...\n", 312 | " \"\"\")),\n", 313 | " expected_output=dedent((\n", 314 | " \"\"\"\n", 315 | " A detailed description of what the task's completion looks like.\n", 316 | " \"\"\")),\n", 317 | " agent=agent_2,\n", 318 | " context=[task_1],\n", 319 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 320 | " output_file=f'output-files/agent_2-output_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 321 | " # ↑ The output of each task iteration will be saved here\n", 322 | ")\n", 323 | "\n", 324 | "task_3 = Task(\n", 325 | " description=dedent((\n", 326 | " \"\"\"\n", 327 | " A clear, concise statement of what the task entails.\n", 328 | " ---\n", 329 | " VARIABLE 1: \"{var_1}\"\n", 330 | " VARIABLE 2: \"{var_2}\"\n", 331 | " VARIABLE 3: \"{var_3}\"\n", 332 | " Add more variables if needed...\n", 333 | " \"\"\")),\n", 334 | " expected_output=dedent((\n", 335 | " \"\"\"\n", 336 | " A detailed description of what the task's completion looks like.\n", 337 | " \"\"\")),\n", 338 | " agent=agent_3,\n", 339 | " context=[task_2],\n", 340 | " # ↑ specify which task's output should be used as context for subsequent tasks\n", 341 | " output_file=f'output-files/agent_3-output_{datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")}.md'\n", 342 | " # ↑ The output of each task iteration will be saved here\n", 343 | ")" 344 | ], 345 | "metadata": { 346 | "id": "dqtn3w1qs-Bu", 347 | "cellView": "form" 348 | }, 349 | "execution_count": null, 350 | "outputs": [] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "source": [ 355 | "# @title ⌨️ Define any variables you have and input them\n", 356 | "print(\"## Welcome to the YOUR_CREW_NAME\")\n", 357 | "print('-------------------------------------------')\n", 358 | "var_1 = input(\"What is the to pass to your crew?\\n\"),\n", 359 | "var_2 = input(\"What is the to pass to your crew?\\n\"),\n", 360 | "var_3 = input(\"What is the to pass to your crew?\\n\"),\n", 361 | "print(\"-------------------------------\")" 362 | ], 363 | "metadata": { 364 | "id": "HfJRdGHesMwn", 365 | "cellView": "form" 366 | }, 367 | "execution_count": null, 368 | "outputs": [] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "source": [ 373 | "# @title 🚀 Get your crew to work!\n", 374 | "def main():\n", 375 | " # Instantiate your crew with a sequential process\n", 376 | " crew = Crew(\n", 377 | " agents=[agent_1, agent_2, agent_3],\n", 378 | " tasks=[task_1, task_2, task_3],\n", 379 | " verbose=True, # You can set it to True or False\n", 380 | " # ↑ indicates the verbosity level for logging during execution.\n", 381 | " process=Process.sequential\n", 382 | " # ↑ the process flow that the crew will follow (e.g., sequential, hierarchical).\n", 383 | " )\n", 384 | "\n", 385 | " inputs = {\n", 386 | " \"var_1\": var_1,\n", 387 | " \"var_2\": var_2,\n", 388 | " \"var_3\": var_3\n", 389 | " }\n", 390 | "\n", 391 | " result = crew.kickoff(inputs=inputs)\n", 392 | " print(\"\\n\\n########################\")\n", 393 | " print(\"## Here is your custom crew run result:\")\n", 394 | " print(\"########################\\n\")\n", 395 | " print(result)\n", 396 | "\n", 397 | " return result\n", 398 | "\n", 399 | "if __name__ == \"__main__\":\n", 400 | " result = main()" 401 | ], 402 | "metadata": { 403 | "id": "nrBn8dMlxfCn", 404 | "cellView": "form" 405 | }, 406 | "execution_count": null, 407 | "outputs": [] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "source": [ 412 | "# @title 🖥️ Display the results of your crew as markdown\n", 413 | "from IPython.display import display, Markdown\n", 414 | "\n", 415 | "markdown_text = result.raw # Adjust this based on the actual attribute\n", 416 | "\n", 417 | "# Display the markdown content\n", 418 | "display(Markdown(markdown_text))" 419 | ], 420 | "metadata": { 421 | "cellView": "form", 422 | "id": "ty33sg3MxNZU" 423 | }, 424 | "execution_count": null, 425 | "outputs": [] 426 | } 427 | ] 428 | } 429 | --------------------------------------------------------------------------------