### Project Setup and Execution Commands Source: https://context7.com/crewaiinc/crewai-examples/llms.txt Provides commands for cloning the CrewAI examples repository, installing dependencies using UV or Poetry, configuring environment variables, and running the marketing posts application. ```bash # Clone and navigate to example git clone https://github.com/crewAIInc/crewAI-examples.git cd crewAI-examples/crews/marketing_strategy # Install dependencies with UV (recommended) uv sync # Or with Poetry poetry lock && poetry install # Configure environment variables cp .env.example .env # Edit .env with your API keys: # OPENAI_API_KEY=your_openai_key # SERPER_API_KEY=your_serper_key # Run the crew poetry run marketing_posts # Or with UV uv run python src/marketing_posts/main.py # For Flows, use crewai CLI cd flows/self_evaluation_loop_flow crewai install crewai flow kickoff # Generate flow visualization crewai flow plot ``` -------------------------------- ### Install Dependencies with UV Source: https://github.com/crewaiinc/crewai-examples/blob/main/README.md Install all project dependencies and set up the virtual environment using the UV package manager. This command ensures all necessary libraries are available for the example to run. ```bash uv sync # Installs all dependencies and creates virtual environment ``` -------------------------------- ### Install Weaviate Client Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/industry-agents/industry-specialized-agents.ipynb Installs the specified version of the weaviate-client library. Use this to ensure compatibility with the example. ```python !pip install --quiet weaviate-client==4.15.4 ``` -------------------------------- ### Navigate to Specific Example Directory Source: https://github.com/crewaiinc/crewai-examples/blob/main/README.md After cloning the repository, navigate into the directory of the specific example you wish to explore. Replace 'crews/marketing_strategy' with the path to your chosen example. ```bash cd crews/marketing_strategy # or any other example ``` -------------------------------- ### Setup NVIDIA API Key Source: https://github.com/crewaiinc/crewai-examples/blob/main/integrations/nvidia_models/marketing_strategy/marketing_posts.ipynb Sets up the NVIDIA API key from environment variables or prompts the user for input. Asserts that the key starts with 'nvapi-'. ```python import getpass import os # del os.environ['NVIDIA_API_KEY'] ## delete key and reset if os.environ.get("NVIDIA_API_KEY", "").startswith("nvapi-"): print("Valid NVIDIA_API_KEY already in environment. Delete to reset") else: nvapi_key = getpass.getpass("NVAPI Key (starts with nvapi-): ") assert nvapi_key.startswith( "nvapi-" ), f"{nvapi_key[:5]}... is not a valid key" os.environ["NVIDIA_API_KEY"] = nvapi_key ``` -------------------------------- ### Setup RAG Chain with LCEL Source: https://github.com/crewaiinc/crewai-examples/blob/main/notebooks/Coding Assistant/coding_assistant_eval.ipynb This example outlines the setup for a Retrieval-Augmented Generation (RAG) chain using LCEL. It involves defining retrievers, prompts, and LLMs to fetch relevant documents and generate answers. ```python from langchain_community.document_loaders import WebBaseLoader from langchain_community.vectorstores import Chroma from langchain_openai import OpenAIEmbeddings, ChatOpenAI from langchain_core.runnables import RunnablePassthrough from langchain_core.prompts import ChatPromptTemplate from langchain.text_splitter import RecursiveCharacterTextSplitter # 1. Load documents loader = WebBaseLoader("https://docs.smith.langchain.com") docs = loader.load() # 2. Split documents text_splitter = RecursiveCharacterTextSplitter() chunks = text_splitter.split_documents(docs) # 3. Create embeddings and vector store vectorstore = Chroma.from_documents(chunks, OpenAIEmbeddings()) retriever = vectorstore.as_retriever() # 4. Setup LLM and prompt llm = ChatOpenAI(model="gpt-3.5-turbo") prompt = ChatPromptTemplate.from_template(""" Answer the question based only on the following context: {context} Question: {question} """") # 5. Define the RAG chain def format_docs(docs): return "\n\n".join(doc.page_content for doc in docs) rag_chain = ( { "context": retriever | format_docs, "question": RunnablePassthrough(), } | prompt | llm | StrOutputKey("answer") # Assuming StrOutputKey is defined or using .content ) # Example usage: # print(rag_chain.invoke("What is LangSmith?")) ``` -------------------------------- ### Install Marketing Posts Package Source: https://github.com/crewaiinc/crewai-examples/blob/main/integrations/nvidia_models/marketing_strategy/marketing_posts.ipynb Installs the necessary package for generating marketing posts. ```python %pip install --upgrade --quiet marketing_posts ``` -------------------------------- ### Install Dependencies with Make Source: https://github.com/crewaiinc/crewai-examples/blob/main/integrations/nvidia_models/intro/README.md Run this command to install the necessary dependencies for the project. Ensure you have a Makefile configured. ```bash make install ``` -------------------------------- ### Install Groq Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install the Groq Python package using pip. Ensure your Python environment is set up. ```bash pip install groq ``` -------------------------------- ### Install Dependencies with Poetry Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/match_profile_to_positions/README.md Install project dependencies using Poetry. Ensure you have Poetry installed and run this command in your project's root directory. ```bash poetry lock && poetry install ``` -------------------------------- ### Clone CrewAI Examples Repository Source: https://github.com/crewaiinc/crewai-examples/blob/main/README.md Use this bash command to clone the CrewAI examples repository to your local machine. This is the first step to accessing and running the provided examples. ```bash git clone https://github.com/crewAIInc/crewAI-examples.git cd crewAI-examples ``` -------------------------------- ### Install Git on Linux (Ubuntu) Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install Git on Ubuntu systems using the apt package manager. ```sh sudo apt install git ``` -------------------------------- ### CrewAI Agent Started Log Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/industry-agents/industry-specialized-agents.ipynb Example log output showing an agent starting a task, including the agent's role and the specific task assigned. This log is part of the verbose output during CrewAI execution. ```text Result:\n╭─╮╭─╮────────────────────────────────────────────── 🤖 Agent Started ───────────────────────────────────────────────╭─╮\n│ │ │\n│ Agent: Industry researcher focused on biomedical trends and their applications in AI │\n│ │\n│ Task: │\n│ Conduct a thorough research about MUVERA │\n│ Make sure you find any interesting and relevant information using the web and Weaviate blogs. │\n│  │\n│ │\n╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Install and Configure CrewAI Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Installs the CrewAI library and sets up initial configuration for agent roles, capabilities, and goals. Ensure you have Python and pip installed. ```python # Install CrewAI !pip install crewai # Configure Settings crewai_config = { 'agent_roles': ['Data Analyst', 'Manager'], 'agent_capabilities': ['data_analysis', 'task_management'], 'goals': ['generate_insights', 'optimize_team_performance'] } # Initialize Agents data_analyst_agent = CrewAIAgent(role='Data Analyst') manager_agent = CrewAIAgent(role='Manager') ``` -------------------------------- ### Install Project Dependencies with UV Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/meta_quest_knowledge/README.md Navigate to your project directory and use UV to install the project's dependencies. This command can also lock dependencies. ```bash crewai install ``` -------------------------------- ### Install UV Package Manager Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/meta_quest_knowledge/README.md Install the UV package manager, which is recommended for dependency management in this project. Ensure you have Python 3.10 to 3.13 installed. ```bash pip install uv ``` -------------------------------- ### Initialize CrewAI and Groq Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Initialize CrewAI and Groq with their respective API keys. This setup is necessary before using their services. ```python import crewai import groq crewai.init(api_key='YOUR_CREWAI_API_KEY') groq.init(api_key='YOUR_GROQ_API_KEY') ``` -------------------------------- ### Install Python, venv, and pip on Linux (Ubuntu) Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Update package lists and install Python, the virtual environment module, and pip on Ubuntu systems. ```sh sudo apt update sudo apt install python3 python3-venv python3-pip ``` -------------------------------- ### Stock Analysis Crew Setup Source: https://context7.com/crewaiinc/crewai-examples/llms.txt Initializes a CrewAI setup for financial analysis, integrating custom SEC filing tools. It loads environment variables and configures an LLM using Ollama. ```python from crewai import Agent, Crew, Process, Task from crewai.project import CrewBase, agent, crew, task from crewai_tools import WebsiteSearchTool, ScrapeWebsiteTool from tools.calculator_tool import CalculatorTool from tools.sec_tools import SEC10KTool, SEC10QTool from dotenv import load_dotenv from langchain.llms import Ollama load_dotenv() ``` -------------------------------- ### Run CrewAI Application (Windows) Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Starts the CrewAI application after installation and dependency setup. ```sh python run.py ``` -------------------------------- ### Copy and Configure Environment File Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/instagram_post/README.md Copy the example environment file and set up necessary environment variables for tools like Browseless and Serper. ```bash cp .env.example .env ``` -------------------------------- ### Install CrewAI Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/industry-agents/industry-specialized-agents.ipynb Installs the specified version of the crewai library. Ensure this version is used for the example to function correctly. ```python !pip install --quiet crewai==0.134.0 ``` -------------------------------- ### Customer Support Agent Setup Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Initialize a Support Agent with a role, add query handling capability, and set a goal to resolve customer issues. ```python support_agent = CrewAIAgent(role='Support Agent') support_agent.add_capability('query_handling') support_agent.set_goal('resolve_customer_issues') ``` -------------------------------- ### Configure and Run Stock Analysis Script Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/stock_analysis/README.md Instructions for setting up environment variables, installing dependencies, and executing the main Python script for stock analysis. ```bash poetry install --no-root ``` ```bash poetry run python3 main.py ``` ```bash python main.py ``` -------------------------------- ### Define a Task for an Agent Source: https://github.com/crewaiinc/crewai-examples/blob/main/notebooks/Coding Assistant/coding_assistant_eval.ipynb This example defines a task for an agent, specifying the description, expected output, and the agent assigned to it. The 'expected_output' helps guide the agent's response. ```python from crewai import Task # Define a task for the researcher agent research_task = Task( description='Identify the top 5 emerging trends in AI and machine learning in 2024.', expected_output='A list of the top 5 emerging trends with a brief explanation for each.', agent=researcher ) ``` -------------------------------- ### LCEL Chain Output as String Source: https://github.com/crewaiinc/crewai-examples/blob/main/notebooks/Coding Assistant/coding_assistant_eval.ipynb This example demonstrates how to ensure the output of an LCEL chain is a string. By default, LLM outputs are often Pydantic objects or similar; this shows how to get a plain string. ```python from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI # Setup LLM and prompt llm = ChatOpenAI(model="gpt-3.5-turbo") prompt = ChatPromptTemplate.from_template("Write a short sentence about {topic}.") # Create the chain chain = prompt | llm # Invoke the chain and get the string output # The .invoke() method on a chain with an LLM typically returns a AIMessage object. # To get the string content, you access the 'content' attribute. result_message = chain.invoke({"topic": "the sun"}) result_string = result_message.content print(f"Output as string: {result_string}") ``` -------------------------------- ### Install CrewAI Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install the latest version of CrewAI using pip. Ensure you have Python and pip installed. ```bash pip install crewai ``` -------------------------------- ### Manager Agent Setup Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Initialize a Manager Agent with a role, add performance tracking capability, and set a goal to improve support efficiency. ```python manager_agent = CrewAIAgent(role='Manager') manager_agent.add_capability('performance_tracking') manager_agent.set_goal('improve_support_efficiency') ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/crewaiinc/crewai-examples/blob/main/integrations/azure_model/README.md Copy the example environment file and set your Azure OpenAI model, endpoint URL, and API key. ```bash .env.example ``` -------------------------------- ### Run the Book Writing Flow Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/write_a_book_with_flows/README.md Execute the book writing flow from your project's root folder to start the AI agent orchestration. ```bash crewai flow kickoff ``` -------------------------------- ### Clone CrewAI Repository and Install Dependencies (Windows) Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Clones the CrewAI GitHub repository and installs necessary Python packages. This step requires Git to be installed. ```sh git clone https://github.com/crewAIInc/crewAI.git cd crewAI ``` ```sh pip install -r requirements.txt ``` -------------------------------- ### Langgraph Workflow Setup Source: https://github.com/crewaiinc/crewai-examples/blob/main/notebooks/Coding Assistant/coding_assistant_eval.ipynb This snippet demonstrates how to set up a Langgraph workflow by defining the state, creating a StateGraph, and adding nodes for 'generate', 'check_code', and 'reflect'. ```python from langgraph.graph import END, StateGraph, START workflow = StateGraph(GraphState) # Define the nodes workflow.add_node("generate", generate) # generation solution workflow.add_node("check_code", code_check) # check code workflow.add_node("reflect", reflect) # reflect ``` -------------------------------- ### Install CrewAI Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/email_auto_responder_flow/README.md Install the CrewAI library using pip. Ensure you have Python 3.10 or higher. ```bash pip install crewai==0.130.0 ``` -------------------------------- ### Start CrewAI Agent Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Initiate the agent's processing tasks by calling the `start()` method. ```python agent.start() ``` -------------------------------- ### Data Analyst Agent Setup Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Initialize a Data Analyst Agent with a role, add data analysis capability, and set a goal to generate insights. ```python data_analyst_agent = CrewAIAgent(role='Data Analyst') data_analyst_agent.add_capability('data_analysis') data_analyst_agent.set_goal('generate_insights') ``` -------------------------------- ### YAML Agent Configuration Example Source: https://context7.com/crewaiinc/crewai-examples/llms.txt Shows how agents are defined in YAML files using role, goal, and backstory properties. This allows for easy customization without modifying Python code. ```yaml role: Lead Market Analyst goal: Identify emerging market trends and provide data-driven insights. backstory: You are an expert market analyst with a keen eye for detail and a deep understanding of consumer behavior. verbose: true allow_delegation: false ``` -------------------------------- ### Install CrewAI Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install the CrewAI library using pip. Use the '[tools]' extra for additional functionalities. ```sh pip install crewai ``` ```sh pip install 'crewai[tools]' ``` -------------------------------- ### Example CrewAI Configuration File Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Define custom tool settings, database URIs, API keys, and user preferences in a `config.py` file. ```python # config.py DATABASE_URI = 'your_database_uri' API_KEY = 'your_api_key' USER_PREFERENCES = { 'theme': 'dark', 'notifications': True, } ``` -------------------------------- ### Install CrewAI Dependencies Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install all required Python packages for CrewAI using the provided requirements file. ```sh pip install -r requirements.txt ``` -------------------------------- ### Initialize CrewAI Agent with Configuration Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Create an instance of the CrewAI class, passing configuration parameters like database URI, API key, and user preferences imported from `config.py`. ```python from crewai import CrewAI from config import DATABASE_URI, API_KEY, USER_PREFERENCES agent = CrewAI(database_uri=DATABASE_URI, api_key=API_KEY, user_preferences=USER_PREFERENCES) ``` -------------------------------- ### Install Git with Homebrew Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Install Git on macOS using Homebrew. Git is necessary for cloning the CrewAI repository. ```sh brew install git ``` -------------------------------- ### Initialize Serper Search Tool Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/industry-agents/industry-specialized-agents.ipynb Initializes the SerperDevTool for web searching. This tool requires a SERPER_API_KEY to be set in the environment variables. ```python search_tool = SerperDevTool() ``` -------------------------------- ### Install Python with Homebrew Source: https://github.com/crewaiinc/crewai-examples/blob/main/flows/lead-score-flow/Automating_Tasks_with_CrewAI.md Use Homebrew to install the latest version of Python on macOS. This is recommended over the pre-installed version. ```sh brew install python ``` -------------------------------- ### Install Dependencies with Poetry Source: https://github.com/crewaiinc/crewai-examples/blob/main/crews/instagram_post/README.md Install project dependencies using Poetry. Ensure you have CrewAI version 0.130.0 or later. ```bash poetry install --no-root ```