-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
861 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Deploy MkDocs | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# What is a Tool? | ||
|
||
A tool in CrewAI is a function or capability that an agent can utilize to perform actions, gather information, or interact with external systems, behind the scenes tools are [LangChain Tools](https://python.langchain.com/docs/modules/agents/tools/). | ||
These tools can be as straightforward as a search function or as sophisticated as integrations with other chains or APIs. | ||
|
||
## Key Characteristics of Tools | ||
|
||
- **Utility**: Tools are designed to serve specific purposes, such as searching the web, analyzing data, or generating content. | ||
- **Integration**: Tools can be integrated into agents to extend their capabilities beyond their basic functions. | ||
- **Customizability**: Developers can create custom tools tailored to the specific needs of their agents or use pre-built LangChain ones available in the ecosystem. | ||
|
||
# Creating your own Tools | ||
|
||
You can easily create your own tool using [LangChain Tool Custom Tool Creation](https://python.langchain.com/docs/modules/agents/tools/custom_tools). | ||
|
||
Example: | ||
```python | ||
import json | ||
import requests | ||
|
||
from crewai import Agent | ||
from langchain.tools import tool | ||
from unstructured.partition.html import partition_html | ||
|
||
class BrowserTools(): | ||
@tool("Scrape website content") | ||
def scrape_website(website): | ||
"""Useful to scrape a website content""" | ||
url = f"https://chrome.browserless.io/content?token={config('BROWSERLESS_API_KEY')}" | ||
payload = json.dumps({"url": website}) | ||
headers = { | ||
'cache-control': 'no-cache', | ||
'content-type': 'application/json' | ||
} | ||
response = requests.request("POST", url, headers=headers, data=payload) | ||
elements = partition_html(text=response.text) | ||
content = "\n\n".join([str(el) for el in elements]) | ||
|
||
# Return only the first 5k characters | ||
return content[:5000] | ||
|
||
|
||
# Create an agent and assign the scrapping tool | ||
agent = Agent( | ||
role='Research Analyst', | ||
goal='Provide up-to-date market analysis', | ||
backstory='An expert analyst with a keen eye for market trends.', | ||
tools=[BrowserTools().scrape_website] | ||
) | ||
``` | ||
|
||
# Using Existing Tools | ||
|
||
Check [LangChain Integration](https://python.langchain.com/docs/integrations/tools/) for a set of useful existing tools. | ||
To assign a tool to an agent, you'd provide it as part of the agent's properties during initialization. | ||
|
||
```python | ||
from crewai import Agent | ||
from langchain.agents import Tool | ||
from langchain.utilities import GoogleSerperAPIWrapper | ||
|
||
# Initialize SerpAPI tool with your API key | ||
os.environ["OPENAI_API_KEY"] = "Your Key" | ||
os.environ["SERPER_API_KEY"] = "Your Key" | ||
|
||
search = GoogleSerperAPIWrapper() | ||
|
||
# Create tool to be used by agent | ||
serper_tool = Tool( | ||
name="Intermediate Answer", | ||
func=search.run, | ||
description="useful for when you need to ask with search", | ||
) | ||
|
||
# Create an agent and assign the search tool | ||
agent = Agent( | ||
role='Research Analyst', | ||
goal='Provide up-to-date market analysis', | ||
backstory='An expert analyst with a keen eye for market trends.', | ||
tools=[serper_tool] | ||
) | ||
``` | ||
|
||
# Tool Interaction | ||
|
||
Tools enhance an agent's ability to perform tasks autonomously or in collaboration with other agents. For instance, an agent might use a search tool to gather information, then pass that data to another agent specialized in analysis. | ||
|
||
# Conclusion | ||
|
||
Tools are vital components that expand the functionality of agents within the CrewAI framework. They enable agents to perform a wide range of actions and collaborate effectively with one another. As you build with CrewAI, consider the array of tools you can leverage to empower your agents and how they can be interwoven to create a robust AI ecosystem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# What is a Task? | ||
|
||
A Task in CrewAI is essentially a job or an assignment that an AI agent needs to complete. It's defined by what needs to be done and can include additional information like which agent should do it and what tools they might need. | ||
|
||
# Task Properties | ||
|
||
- **Description**: A clear, concise statement of what the task entails. | ||
- **Agent**: Optionally, you can specify which agent is responsible for the task. If not, the crew's process will determine who takes it on. | ||
- **Tools**: These are the functions or capabilities the agent can utilize to perform the task. They can be anything from simple actions like 'search' to more complex interactions with other agents or APIs. | ||
|
||
# Integrating Tools with Tasks | ||
|
||
In CrewAI, tools are functions from the `langchain` toolkit that agents can use to interact with the world. These can be generic utilities or specialized functions designed for specific actions. When you assign tools to a task, they empower the agent to perform its duties more effectively. | ||
|
||
## Example of Creating a Task with Tools | ||
|
||
```python | ||
from crewai import Task | ||
from langchain.agents import Tool | ||
from langchain.utilities import GoogleSerperAPIWrapper | ||
|
||
# Initialize SerpAPI tool with your API key | ||
os.environ["OPENAI_API_KEY"] = "Your Key" | ||
os.environ["SERPER_API_KEY"] = "Your Key" | ||
|
||
search = GoogleSerperAPIWrapper() | ||
|
||
# Create tool to be used by agent | ||
serper_tool = Tool( | ||
name="Intermediate Answer", | ||
func=search.run, | ||
description="useful for when you need to ask with search", | ||
) | ||
|
||
# Create a task with a description and the search tool | ||
task = Task( | ||
description='Find and summarize the latest and most relevant news on AI', | ||
tools=[serper_tool] | ||
) | ||
``` | ||
|
||
When the task is executed by an agent, the tools specified in the task will override the agent's default tools. This means that for the duration of this task, the agent will use the search tool provided, even if it has other tools assigned to it. | ||
|
||
# Tool Override Mechanism | ||
|
||
The ability to override an agent's tools with those specified in a task allows for greater flexibility. An agent might generally use a set of standard tools, but for certain tasks, you may want it to use a particular tool that is more suited to the task at hand. | ||
|
||
# Conclusion | ||
|
||
Creating tasks with the right tools is crucial in CrewAI. It ensures that your agents are not only aware of what they need to do but are also equipped with the right functions to do it effectively. This feature underlines the flexibility and power of the CrewAI system, where tasks can be tailored with specific tools to achieve the best outcome. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Overview of a Task | ||
|
||
In the CrewAI framework, tasks are the individual assignments that agents are responsible for completing. They are the fundamental units of work that your AI crew will undertake. Understanding how to define and manage tasks is key to leveraging the full potential of CrewAI. | ||
|
||
A task in CrewAI encapsulates all the information needed for an agent to execute it, including a description, the agent assigned to it, and any specific tools required. Tasks are designed to be flexible, allowing for both simple and complex actions depending on your needs. | ||
|
||
# Properties of a Task | ||
|
||
Every task in CrewAI has several properties: | ||
|
||
- **Description**: A clear and concise statement of what needs to be done. | ||
- **Agent**: The agent assigned to the task (optional). If no agent is specified, the task can be picked up by any agent based on the process defined. | ||
- **Tools**: A list of tools (optional) that the agent can use to complete the task. These can override the agent's default tools if necessary. | ||
|
||
# Creating a Task | ||
|
||
Creating a task is straightforward. You define what needs to be done and, optionally, who should do it and what tools they should use. Here’s a conceptual guide: | ||
|
||
```python | ||
from crewai import Task | ||
|
||
# Define a task with a designated agent and specific tools | ||
task = Task(description='Generate monthly sales report', agent=sales_agent, tools=[reporting_tool]) | ||
``` | ||
|
||
# Task Assignment | ||
|
||
Tasks can be assigned to agents in several ways: | ||
|
||
- Directly, by specifying the agent when creating the task. | ||
- [WIP] Through the Crew's process, which can assign tasks based on agent roles, availability, or other criteria. | ||
|
||
# Task Execution | ||
|
||
Once a task has been defined and assigned, it's ready to be executed. Execution is typically handled by the Crew object, which manages the workflow and ensures that tasks are completed according to the defined process. | ||
|
||
# Task Collaboration | ||
|
||
Tasks in CrewAI can be designed to require collaboration between agents. For example, one agent might gather data while another analyzes it. This collaborative approach can be defined within the task properties and managed by the Crew's process. | ||
|
||
# Conclusion | ||
Tasks are the driving force behind the actions of agents in CrewAI. By properly defining tasks, you set the stage for your AI agents to work effectively, either independently or as a collaborative unit. In the following sections, we will explore how tasks fit into the larger picture of processes and crew management. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# How Agents Collaborate: | ||
|
||
In CrewAI, collaboration is the cornerstone of agent interaction. Agents are designed to work together by sharing information, requesting assistance, and combining their skills to complete tasks more efficiently. | ||
|
||
- **Information Sharing**: Agents can share findings and data amongst themselves to ensure all members are informed and can contribute effectively. | ||
- **Task Assistance**: If an agent encounters a task that requires additional expertise, it can seek the help of another agent with the necessary skill set. | ||
- **Resource Allocation**: Agents can share or allocate resources such as tools or processing power to optimize task execution. | ||
|
||
Collaboration is embedded in the DNA of CrewAI, enabling a dynamic and adaptive approach to problem-solving. | ||
|
||
# Delegation: Dividing to Conquer | ||
|
||
Delegation is the process by which an agent assigns a task to another agent, or just ask another agent, it's an intelligent decision-making process that enhances the crew's functionality. | ||
By default all agents can delegate work and ask questions, so if you want an agent to work alone make sure to set that option when initializing an Agent, this is useful to prevent deviations if the task is supposed to be straightforward. | ||
|
||
## Implementing Collaboration and Delegation | ||
|
||
When setting up your crew, you'll define the roles and capabilities of each agent. CrewAI's infrastructure takes care of the rest, managing the complex interplay of agents as they work together. | ||
|
||
## Example Scenario: | ||
|
||
Imagine a scenario where you have a researcher agent that gathers data and a writer agent that compiles reports. The writer can autonomously ask question or delegate more in depth research work depending on its needs as it tries to complete its task. | ||
|
||
# Conclusion | ||
|
||
Collaboration and delegation are what transform a collection of AI agents into a unified, intelligent crew. With CrewAI, you have a framework that not only simplifies these interactions but also makes them more effective, paving the way for sophisticated AI systems that can tackle complex, multi-dimensional tasks. |
Oops, something went wrong.