Compare commits
35 Commits
0.117.1
...
lg-agent-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
615eb0afb7 | ||
|
|
c403497cf4 | ||
|
|
fed397f745 | ||
|
|
d55e596800 | ||
|
|
f700e014c9 | ||
|
|
4e496d7a20 | ||
|
|
8663c7e1c2 | ||
|
|
cb1a98cabf | ||
|
|
369e6d109c | ||
|
|
2c011631f9 | ||
|
|
d3fc2b4477 | ||
|
|
516d45deaa | ||
|
|
7ad51d9d05 | ||
|
|
e3887ae36e | ||
|
|
e23bc2aaa7 | ||
|
|
7fc405408e | ||
|
|
cac06adc6c | ||
|
|
c8ec03424a | ||
|
|
bfea85d22c | ||
|
|
836e9fc545 | ||
|
|
c3726092fd | ||
|
|
dabf02a90d | ||
|
|
2912c93d77 | ||
|
|
17474a3a0c | ||
|
|
f89c2bfb7e | ||
|
|
2902201bfa | ||
|
|
378dcc79bb | ||
|
|
d348d5f20e | ||
|
|
bc24bc64cd | ||
|
|
015e1a41b2 | ||
|
|
94b1a6cfb8 | ||
|
|
1c2976c4d1 | ||
|
|
25c8155609 | ||
|
|
55b07506c2 | ||
|
|
59f34d900a |
38
.github/security.md
vendored
@@ -1,19 +1,27 @@
|
||||
CrewAI takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organization.
|
||||
If you believe you have found a security vulnerability in any CrewAI product or service, please report it to us as described below.
|
||||
## CrewAI Security Vulnerability Reporting Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
Please do not report security vulnerabilities through public GitHub issues.
|
||||
To report a vulnerability, please email us at security@crewai.com.
|
||||
Please include the requested information listed below so that we can triage your report more quickly
|
||||
CrewAI prioritizes the security of our software products, services, and GitHub repositories. To promptly address vulnerabilities, follow these steps for reporting security issues:
|
||||
|
||||
- Type of issue (e.g. SQL injection, cross-site scripting, etc.)
|
||||
- Full paths of source file(s) related to the manifestation of the issue
|
||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||
- Any special configuration required to reproduce the issue
|
||||
- Step-by-step instructions to reproduce the issue (please include screenshots if needed)
|
||||
- Proof-of-concept or exploit code (if possible)
|
||||
- Impact of the issue, including how an attacker might exploit the issue
|
||||
### Reporting Process
|
||||
Do **not** report vulnerabilities via public GitHub issues.
|
||||
|
||||
Once we have received your report, we will respond to you at the email address you provide. If the issue is confirmed, we will release a patch as soon as possible depending on the complexity of the issue.
|
||||
Email all vulnerability reports directly to:
|
||||
**security@crewai.com**
|
||||
|
||||
At this time, we are not offering a bug bounty program. Any rewards will be at our discretion.
|
||||
### Required Information
|
||||
To help us quickly validate and remediate the issue, your report must include:
|
||||
|
||||
- **Vulnerability Type:** Clearly state the vulnerability type (e.g., SQL injection, XSS, privilege escalation).
|
||||
- **Affected Source Code:** Provide full file paths and direct URLs (branch, tag, or commit).
|
||||
- **Reproduction Steps:** Include detailed, step-by-step instructions. Screenshots are recommended.
|
||||
- **Special Configuration:** Document any special settings or configurations required to reproduce.
|
||||
- **Proof-of-Concept (PoC):** Provide exploit or PoC code (if available).
|
||||
- **Impact Assessment:** Clearly explain the severity and potential exploitation scenarios.
|
||||
|
||||
### Our Response
|
||||
- We will acknowledge receipt of your report promptly via your provided email.
|
||||
- Confirmed vulnerabilities will receive priority remediation based on severity.
|
||||
- Patches will be released as swiftly as possible following verification.
|
||||
|
||||
### Reward Notice
|
||||
Currently, we do not offer a bug bounty program. Rewards, if issued, are discretionary.
|
||||
|
||||
25
.github/workflows/linter.yml
vendored
@@ -5,12 +5,29 @@ on: [pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Requirements
|
||||
- name: Fetch Target Branch
|
||||
run: git fetch origin $TARGET_BRANCH --depth=1
|
||||
|
||||
- name: Install Ruff
|
||||
run: pip install ruff
|
||||
|
||||
- name: Get Changed Python Files
|
||||
id: changed-files
|
||||
run: |
|
||||
pip install ruff
|
||||
merge_base=$(git merge-base origin/"$TARGET_BRANCH" HEAD)
|
||||
changed_files=$(git diff --name-only --diff-filter=ACMRTUB "$merge_base" | grep '\.py$' || true)
|
||||
echo "files<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$changed_files" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Run Ruff Linter
|
||||
run: ruff check
|
||||
- name: Run Ruff on Changed Files
|
||||
if: ${{ steps.changed-files.outputs.files != '' }}
|
||||
run: |
|
||||
echo "${{ steps.changed-files.outputs.files }}" | tr " " "\n" | xargs -I{} ruff check "{}"
|
||||
|
||||
2
.github/workflows/tests.yml
vendored
@@ -31,4 +31,4 @@ jobs:
|
||||
run: uv sync --dev --all-extras
|
||||
|
||||
- name: Run tests
|
||||
run: uv run pytest tests -vv
|
||||
run: uv run pytest --block-network --timeout=60 -vv
|
||||
|
||||
@@ -2,8 +2,3 @@ exclude = [
|
||||
"templates",
|
||||
"__init__.py",
|
||||
]
|
||||
|
||||
[lint]
|
||||
select = [
|
||||
"I", # isort rules
|
||||
]
|
||||
|
||||
@@ -504,7 +504,7 @@ This example demonstrates how to:
|
||||
|
||||
CrewAI supports using various LLMs through a variety of connection options. By default your agents will use the OpenAI API when querying the model. However, there are several other ways to allow your agents to connect to models. For example, you can configure your agents to use a local model via the Ollama tool.
|
||||
|
||||
Please refer to the [Connect CrewAI to LLMs](https://docs.crewai.com/how-to/LLM-Connections/) page for details on configuring you agents' connections to models.
|
||||
Please refer to the [Connect CrewAI to LLMs](https://docs.crewai.com/how-to/LLM-Connections/) page for details on configuring your agents' connections to models.
|
||||
|
||||
## How CrewAI Compares
|
||||
|
||||
|
||||
@@ -4,12 +4,69 @@ description: View the latest updates and changes to CrewAI
|
||||
icon: timeline
|
||||
---
|
||||
|
||||
<Update label="2025-04-30" description="v0.117.1">
|
||||
## Release Highlights
|
||||
<Frame>
|
||||
<img src="/images/releases/v01171.png" />
|
||||
</Frame>
|
||||
|
||||
<div style={{ textAlign: 'center', marginBottom: '1rem' }}>
|
||||
<a href="https://github.com/crewAIInc/crewAI/releases/tag/0.117.1">View on GitHub</a>
|
||||
</div>
|
||||
|
||||
**Core Improvements & Fixes**
|
||||
- Upgraded **crewai-tools** to latest version
|
||||
- Upgraded **liteLLM** to latest version
|
||||
- Fixed **Mem0 OSS**
|
||||
</Update>
|
||||
|
||||
<Update label="2025-04-28" description="v0.117.0">
|
||||
## Release Highlights
|
||||
<Frame>
|
||||
<img src="/images/releases/v01170.png" />
|
||||
</Frame>
|
||||
|
||||
<div style={{ textAlign: 'center', marginBottom: '1rem' }}>
|
||||
<a href="https://github.com/crewAIInc/crewAI/releases/tag/0.117.0">View on GitHub</a>
|
||||
</div>
|
||||
|
||||
**New Features & Enhancements**
|
||||
- Added `result_as_answer` parameter support in `@tool` decorator.
|
||||
- Introduced support for new language models: GPT-4.1, Gemini-2.0, and Gemini-2.5 Pro.
|
||||
- Enhanced knowledge management capabilities.
|
||||
- Added Huggingface provider option in CLI.
|
||||
- Improved compatibility and CI support for Python 3.10+.
|
||||
|
||||
**Core Improvements & Fixes**
|
||||
- Fixed issues with incorrect template parameters and missing inputs.
|
||||
- Improved asynchronous flow handling with coroutine condition checks.
|
||||
- Enhanced memory management with isolated configuration and correct memory object copying.
|
||||
- Fixed initialization of lite agents with correct references.
|
||||
- Addressed Python type hint issues and removed redundant imports.
|
||||
- Updated event placement for improved tool usage tracking.
|
||||
- Raised explicit exceptions when flows fail.
|
||||
- Removed unused code and redundant comments from various modules.
|
||||
- Updated GitHub App token action to v2.
|
||||
|
||||
**Documentation & Guides**
|
||||
- Enhanced documentation structure, including enterprise deployment instructions.
|
||||
- Automatically create output folders for documentation generation.
|
||||
- Fixed broken link in WeaviateVectorSearchTool documentation.
|
||||
- Fixed guardrail documentation usage and import paths for JSON search tools.
|
||||
- Updated documentation for CodeInterpreterTool.
|
||||
- Improved SEO, contextual navigation, and error handling for documentation pages.
|
||||
</Update>
|
||||
|
||||
<Update label="2025-04-07" description="v0.114.0">
|
||||
## Release Highlights
|
||||
<Frame>
|
||||
<img src="/images/v01140.png" />
|
||||
<img src="/images/releases/v01140.png" />
|
||||
</Frame>
|
||||
|
||||
<div style={{ textAlign: 'center', marginBottom: '1rem' }}>
|
||||
<a href="https://github.com/crewAIInc/crewAI/releases/tag/0.114.0">View on GitHub</a>
|
||||
</div>
|
||||
|
||||
**New Features & Enhancements**
|
||||
- Agents as an atomic unit. (`Agent(...).kickoff()`)
|
||||
- Support for [Custom LLM implementations](https://docs.crewai.com/guides/advanced/custom-llm).
|
||||
@@ -35,7 +92,16 @@ icon: timeline
|
||||
</Update>
|
||||
|
||||
<Update label="2025-03-17" description="v0.108.0">
|
||||
**Features**
|
||||
## Release Highlights
|
||||
<Frame>
|
||||
<img src="/images/releases/v01080.png" />
|
||||
</Frame>
|
||||
|
||||
<div style={{ textAlign: 'center', marginBottom: '1rem' }}>
|
||||
<a href="https://github.com/crewAIInc/crewAI/releases/tag/0.108.0">View on GitHub</a>
|
||||
</div>
|
||||
|
||||
**New Features & Enhancements**
|
||||
- Converted tabs to spaces in `crew.py` template
|
||||
- Enhanced LLM Streaming Response Handling and Event System
|
||||
- Included `model_name`
|
||||
|
||||
@@ -255,7 +255,11 @@ custom_agent = Agent(
|
||||
- `response_template`: Formats agent responses
|
||||
|
||||
<Note>
|
||||
When using custom templates, you can use variables like `{role}`, `{goal}`, and `{input}` in your templates. These will be automatically populated during execution.
|
||||
When using custom templates, ensure that both `system_template` and `prompt_template` are defined. The `response_template` is optional but recommended for consistent output formatting.
|
||||
</Note>
|
||||
|
||||
<Note>
|
||||
When using custom templates, you can use variables like `{role}`, `{goal}`, and `{backstory}` in your templates. These will be automatically populated during execution.
|
||||
</Note>
|
||||
|
||||
## Agent Tools
|
||||
|
||||
@@ -27,7 +27,7 @@ A crew in crewAI represents a collaborative group of agents working together to
|
||||
| **Step Callback** _(optional)_ | `step_callback` | A function that is called after each step of every agent. This can be used to log the agent's actions or to perform other operations; it won't override the agent-specific `step_callback`. |
|
||||
| **Task Callback** _(optional)_ | `task_callback` | A function that is called after the completion of each task. Useful for monitoring or additional operations post-task execution. |
|
||||
| **Share Crew** _(optional)_ | `share_crew` | Whether you want to share the complete crew information and execution with the crewAI team to make the library better, and allow us to train models. |
|
||||
| **Output Log File** _(optional)_ | `output_log_file` | Set to True to save logs as logs.txt in the current directory or provide a file path. Logs will be in JSON format if the filename ends in .json, otherwise .txt. Defautls to `None`. |
|
||||
| **Output Log File** _(optional)_ | `output_log_file` | Set to True to save logs as logs.txt in the current directory or provide a file path. Logs will be in JSON format if the filename ends in .json, otherwise .txt. Defaults to `None`. |
|
||||
| **Manager Agent** _(optional)_ | `manager_agent` | `manager` sets a custom agent that will be used as a manager. |
|
||||
| **Prompt File** _(optional)_ | `prompt_file` | Path to the prompt JSON file to be used for the crew. |
|
||||
| **Planning** *(optional)* | `planning` | Adds planning ability to the Crew. When activated before each Crew iteration, all Crew data is sent to an AgentPlanner that will plan the tasks and this plan will be added to each task description. |
|
||||
@@ -246,7 +246,7 @@ print(f"Token Usage: {crew_output.token_usage}")
|
||||
You can see real time log of the crew execution, by setting `output_log_file` as a `True(Boolean)` or a `file_name(str)`. Supports logging of events as both `file_name.txt` and `file_name.json`.
|
||||
In case of `True(Boolean)` will save as `logs.txt`.
|
||||
|
||||
In case of `output_log_file` is set as `False(Booelan)` or `None`, the logs will not be populated.
|
||||
In case of `output_log_file` is set as `False(Boolean)` or `None`, the logs will not be populated.
|
||||
|
||||
```python Code
|
||||
# Save crew logs
|
||||
|
||||
@@ -397,6 +397,53 @@ result = crew.kickoff(inputs={"question": "What city does John live in and how o
|
||||
John is 30 years old and lives in San Francisco.
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
## Query Rewriting
|
||||
|
||||
CrewAI implements an intelligent query rewriting mechanism to optimize knowledge retrieval. When an agent needs to search through knowledge sources, the raw task prompt is automatically transformed into a more effective search query.
|
||||
|
||||
### How Query Rewriting Works
|
||||
|
||||
1. When an agent executes a task with knowledge sources available, the `_get_knowledge_search_query` method is triggered
|
||||
2. The agent's LLM is used to transform the original task prompt into an optimized search query
|
||||
3. This optimized query is then used to retrieve relevant information from knowledge sources
|
||||
|
||||
### Benefits of Query Rewriting
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Improved Retrieval Accuracy" icon="bullseye-arrow">
|
||||
By focusing on key concepts and removing irrelevant content, query rewriting helps retrieve more relevant information.
|
||||
</Card>
|
||||
<Card title="Context Awareness" icon="brain">
|
||||
The rewritten queries are designed to be more specific and context-aware for vector database retrieval.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
### Implementation Details
|
||||
|
||||
Query rewriting happens transparently using a system prompt that instructs the LLM to:
|
||||
|
||||
- Focus on key words of the intended task
|
||||
- Make the query more specific and context-aware
|
||||
- Remove irrelevant content like output format instructions
|
||||
- Generate only the rewritten query without preamble or postamble
|
||||
|
||||
<Tip>
|
||||
This mechanism is fully automatic and requires no configuration from users. The agent's LLM is used to perform the query rewriting, so using a more capable LLM can improve the quality of rewritten queries.
|
||||
</Tip>
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
# Original task prompt
|
||||
task_prompt = "Answer the following questions about the user's favorite movies: What movie did John watch last week? Format your answer in JSON."
|
||||
|
||||
# Behind the scenes, this might be rewritten as:
|
||||
rewritten_query = "What movies did John watch last week?"
|
||||
```
|
||||
|
||||
The rewritten query is more focused on the core information need and removes irrelevant instructions about output formatting.
|
||||
|
||||
## Clearing Knowledge
|
||||
|
||||
If you need to clear the knowledge stored in CrewAI, you can use the `crewai reset-memories` command with the `--knowledge` option.
|
||||
@@ -653,4 +700,11 @@ recent_news = SpaceNewsKnowledgeSource(
|
||||
- Configure appropriate embedding models
|
||||
- Consider using local embedding providers for faster processing
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="One Time Knowledge">
|
||||
- With the typical file structure provided by CrewAI, knowledge sources are embedded every time the kickoff is triggered.
|
||||
- If the knowledge sources are large, this leads to inefficiency and increased latency, as the same data is embedded each time.
|
||||
- To resolve this, directly initialize the knowledge parameter instead of the knowledge_sources parameter.
|
||||
- Link to the issue to get complete idea [Github Issue](https://github.com/crewAIInc/crewAI/issues/2755)
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
@@ -27,23 +27,19 @@ Large Language Models (LLMs) are the core intelligence behind CrewAI agents. The
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Setting Up Your LLM
|
||||
## Setting up your LLM
|
||||
|
||||
There are three ways to configure LLMs in CrewAI. Choose the method that best fits your workflow:
|
||||
There are different places in CrewAI code where you can specify the model to use. Once you specify the model you are using, you will need to provide the configuration (like an API key) for each of the model providers you use. See the [provider configuration examples](#provider-configuration-examples) section for your provider.
|
||||
|
||||
<Tabs>
|
||||
<Tab title="1. Environment Variables">
|
||||
The simplest way to get started. Set these variables in your environment:
|
||||
The simplest way to get started. Set the model in your environment directly, through an `.env` file or in your app code. If you used `crewai create` to bootstrap your project, it will be set already.
|
||||
|
||||
```bash
|
||||
# Required: Your API key for authentication
|
||||
OPENAI_API_KEY=<your-api-key>
|
||||
```bash .env
|
||||
MODEL=model-id # e.g. gpt-4o, gemini-2.0-flash, claude-3-sonnet-...
|
||||
|
||||
# Optional: Default model selection
|
||||
OPENAI_MODEL_NAME=gpt-4o-mini # Default if not set
|
||||
|
||||
# Optional: Organization ID (if applicable)
|
||||
OPENAI_ORGANIZATION_ID=<your-org-id>
|
||||
# Be sure to set your API keys here too. See the Provider
|
||||
# section below.
|
||||
```
|
||||
|
||||
<Warning>
|
||||
@@ -53,13 +49,13 @@ There are three ways to configure LLMs in CrewAI. Choose the method that best fi
|
||||
<Tab title="2. YAML Configuration">
|
||||
Create a YAML file to define your agent configurations. This method is great for version control and team collaboration:
|
||||
|
||||
```yaml
|
||||
```yaml agents.yaml {6}
|
||||
researcher:
|
||||
role: Research Specialist
|
||||
goal: Conduct comprehensive research and analysis
|
||||
backstory: A dedicated research professional with years of experience
|
||||
verbose: true
|
||||
llm: openai/gpt-4o-mini # your model here
|
||||
llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude...
|
||||
# (see provider configuration examples below for more)
|
||||
```
|
||||
|
||||
@@ -74,23 +70,23 @@ There are three ways to configure LLMs in CrewAI. Choose the method that best fi
|
||||
<Tab title="3. Direct Code">
|
||||
For maximum flexibility, configure LLMs directly in your Python code:
|
||||
|
||||
```python
|
||||
```python {4,8}
|
||||
from crewai import LLM
|
||||
|
||||
# Basic configuration
|
||||
llm = LLM(model="gpt-4")
|
||||
llm = LLM(model="model-id-here") # gpt-4o, gemini-2.0-flash, anthropic/claude...
|
||||
|
||||
# Advanced configuration with detailed parameters
|
||||
llm = LLM(
|
||||
model="gpt-4o-mini",
|
||||
model="model-id-here", # gpt-4o, gemini-2.0-flash, anthropic/claude...
|
||||
temperature=0.7, # Higher for more creative outputs
|
||||
timeout=120, # Seconds to wait for response
|
||||
max_tokens=4000, # Maximum length of response
|
||||
top_p=0.9, # Nucleus sampling parameter
|
||||
frequency_penalty=0.1, # Reduce repetition
|
||||
presence_penalty=0.1, # Encourage topic diversity
|
||||
timeout=120, # Seconds to wait for response
|
||||
max_tokens=4000, # Maximum length of response
|
||||
top_p=0.9, # Nucleus sampling parameter
|
||||
frequency_penalty=0.1 , # Reduce repetition
|
||||
presence_penalty=0.1, # Encourage topic diversity
|
||||
response_format={"type": "json"}, # For structured outputs
|
||||
seed=42 # For reproducible results
|
||||
seed=42 # For reproducible results
|
||||
)
|
||||
```
|
||||
|
||||
@@ -110,7 +106,6 @@ There are three ways to configure LLMs in CrewAI. Choose the method that best fi
|
||||
|
||||
## Provider Configuration Examples
|
||||
|
||||
|
||||
CrewAI supports a multitude of LLM providers, each offering unique features, authentication methods, and model capabilities.
|
||||
In this section, you'll find detailed examples that help you select, configure, and optimize the LLM that best fits your project's needs.
|
||||
|
||||
@@ -174,19 +169,55 @@ In this section, you'll find detailed examples that help you select, configure,
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Google">
|
||||
Set the following environment variables in your `.env` file:
|
||||
<Accordion title="Google (Gemini API)">
|
||||
Set your API key in your `.env` file. If you need a key, or need to find an
|
||||
existing key, check [AI Studio](https://aistudio.google.com/apikey).
|
||||
|
||||
```toml Code
|
||||
# Option 1: Gemini accessed with an API key.
|
||||
```toml .env
|
||||
# https://ai.google.dev/gemini-api/docs/api-key
|
||||
GEMINI_API_KEY=<your-api-key>
|
||||
|
||||
# Option 2: Vertex AI IAM credentials for Gemini, Anthropic, and Model Garden.
|
||||
# https://cloud.google.com/vertex-ai/generative-ai/docs/overview
|
||||
```
|
||||
|
||||
Get credentials from your Google Cloud Console and save it to a JSON file with the following code:
|
||||
Example usage in your CrewAI project:
|
||||
```python Code
|
||||
from crewai import LLM
|
||||
|
||||
llm = LLM(
|
||||
model="gemini/gemini-2.0-flash",
|
||||
temperature=0.7,
|
||||
)
|
||||
```
|
||||
|
||||
### Gemini models
|
||||
|
||||
Google offers a range of powerful models optimized for different use cases.
|
||||
|
||||
| Model | Context Window | Best For |
|
||||
|--------------------------------|----------------|-------------------------------------------------------------------|
|
||||
| gemini-2.5-flash-preview-04-17 | 1M tokens | Adaptive thinking, cost efficiency |
|
||||
| gemini-2.5-pro-preview-05-06 | 1M tokens | Enhanced thinking and reasoning, multimodal understanding, advanced coding, and more |
|
||||
| gemini-2.0-flash | 1M tokens | Next generation features, speed, thinking, and realtime streaming |
|
||||
| gemini-2.0-flash-lite | 1M tokens | Cost efficiency and low latency |
|
||||
| gemini-1.5-flash | 1M tokens | Balanced multimodal model, good for most tasks |
|
||||
| gemini-1.5-flash-8B | 1M tokens | Fastest, most cost-efficient, good for high-frequency tasks |
|
||||
| gemini-1.5-pro | 2M tokens | Best performing, wide variety of reasoning tasks including logical reasoning, coding, and creative collaboration |
|
||||
|
||||
The full list of models is available in the [Gemini model docs](https://ai.google.dev/gemini-api/docs/models).
|
||||
|
||||
### Gemma
|
||||
|
||||
The Gemini API also allows you to use your API key to access [Gemma models](https://ai.google.dev/gemma/docs) hosted on Google infrastructure.
|
||||
|
||||
| Model | Context Window |
|
||||
|----------------|----------------|
|
||||
| gemma-3-1b-it | 32k tokens |
|
||||
| gemma-3-4b-it | 32k tokens |
|
||||
| gemma-3-12b-it | 32k tokens |
|
||||
| gemma-3-27b-it | 128k tokens |
|
||||
|
||||
</Accordion>
|
||||
<Accordion title="Google (Vertex AI)">
|
||||
Get credentials from your Google Cloud Console and save it to a JSON file, then load it with the following code:
|
||||
```python Code
|
||||
import json
|
||||
|
||||
@@ -210,14 +241,18 @@ In this section, you'll find detailed examples that help you select, configure,
|
||||
vertex_credentials=vertex_credentials_json
|
||||
)
|
||||
```
|
||||
|
||||
Google offers a range of powerful models optimized for different use cases:
|
||||
|
||||
| Model | Context Window | Best For |
|
||||
|-----------------------|----------------|------------------------------------------------------------------|
|
||||
| gemini-2.0-flash-exp | 1M tokens | Higher quality at faster speed, multimodal model, good for most tasks |
|
||||
| gemini-1.5-flash | 1M tokens | Balanced multimodal model, good for most tasks |
|
||||
| gemini-1.5-flash-8B | 1M tokens | Fastest, most cost-efficient, good for high-frequency tasks |
|
||||
| gemini-1.5-pro | 2M tokens | Best performing, wide variety of reasoning tasks including logical reasoning, coding, and creative collaboration |
|
||||
| Model | Context Window | Best For |
|
||||
|--------------------------------|----------------|-------------------------------------------------------------------|
|
||||
| gemini-2.5-flash-preview-04-17 | 1M tokens | Adaptive thinking, cost efficiency |
|
||||
| gemini-2.5-pro-preview-05-06 | 1M tokens | Enhanced thinking and reasoning, multimodal understanding, advanced coding, and more |
|
||||
| gemini-2.0-flash | 1M tokens | Next generation features, speed, thinking, and realtime streaming |
|
||||
| gemini-2.0-flash-lite | 1M tokens | Cost efficiency and low latency |
|
||||
| gemini-1.5-flash | 1M tokens | Balanced multimodal model, good for most tasks |
|
||||
| gemini-1.5-flash-8B | 1M tokens | Fastest, most cost-efficient, good for high-frequency tasks |
|
||||
| gemini-1.5-pro | 2M tokens | Best performing, wide variety of reasoning tasks including logical reasoning, coding, and creative collaboration |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Azure">
|
||||
@@ -383,7 +418,7 @@ In this section, you'll find detailed examples that help you select, configure,
|
||||
| microsoft/phi-3-medium-4k-instruct | 4,096 tokens | Lightweight, state-of-the-art open LLM with strong math and logical reasoning skills. |
|
||||
| microsoft/phi-3-medium-128k-instruct | 128K tokens | Lightweight, state-of-the-art open LLM with strong math and logical reasoning skills. |
|
||||
| microsoft/phi-3.5-mini-instruct | 128K tokens | Lightweight multilingual LLM powering AI applications in latency bound, memory/compute constrained environments |
|
||||
| microsoft/phi-3.5-moe-instruct | 128K tokens | Advanced LLM based on Mixture of Experts architecure to deliver compute efficient content generation |
|
||||
| microsoft/phi-3.5-moe-instruct | 128K tokens | Advanced LLM based on Mixture of Experts architecture to deliver compute efficient content generation |
|
||||
| microsoft/kosmos-2 | 1,024 tokens | Groundbreaking multimodal model designed to understand and reason about visual elements in images. |
|
||||
| microsoft/phi-3-vision-128k-instruct | 128k tokens | Cutting-edge open multimodal model exceling in high-quality reasoning from images. |
|
||||
| microsoft/phi-3.5-vision-instruct | 128k tokens | Cutting-edge open multimodal model exceling in high-quality reasoning from images. |
|
||||
@@ -407,19 +442,19 @@ In this section, you'll find detailed examples that help you select, configure,
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Local NVIDIA NIM Deployed using WSL2">
|
||||
|
||||
NVIDIA NIM enables you to run powerful LLMs locally on your Windows machine using WSL2 (Windows Subsystem for Linux).
|
||||
This approach allows you to leverage your NVIDIA GPU for private, secure, and cost-effective AI inference without relying on cloud services.
|
||||
|
||||
NVIDIA NIM enables you to run powerful LLMs locally on your Windows machine using WSL2 (Windows Subsystem for Linux).
|
||||
This approach allows you to leverage your NVIDIA GPU for private, secure, and cost-effective AI inference without relying on cloud services.
|
||||
Perfect for development, testing, or production scenarios where data privacy or offline capabilities are required.
|
||||
|
||||
|
||||
Here is a step-by-step guide to setting up a local NVIDIA NIM model:
|
||||
|
||||
|
||||
1. Follow installation instructions from [NVIDIA Website](https://docs.nvidia.com/nim/wsl2/latest/getting-started.html)
|
||||
|
||||
2. Install the local model. For Llama 3.1-8b follow [instructions](https://build.nvidia.com/meta/llama-3_1-8b-instruct/deploy)
|
||||
|
||||
3. Configure your crewai local models:
|
||||
|
||||
|
||||
```python Code
|
||||
from crewai.llm import LLM
|
||||
|
||||
@@ -441,7 +476,7 @@ In this section, you'll find detailed examples that help you select, configure,
|
||||
config=self.agents_config['researcher'], # type: ignore[index]
|
||||
llm=local_nvidia_nim_llm
|
||||
)
|
||||
|
||||
|
||||
# ...
|
||||
```
|
||||
</Accordion>
|
||||
@@ -637,19 +672,19 @@ CrewAI supports streaming responses from LLMs, allowing your application to rece
|
||||
|
||||
When streaming is enabled, responses are delivered in chunks as they're generated, creating a more responsive user experience.
|
||||
</Tab>
|
||||
|
||||
|
||||
<Tab title="Event Handling">
|
||||
CrewAI emits events for each chunk received during streaming:
|
||||
|
||||
|
||||
```python
|
||||
from crewai import LLM
|
||||
from crewai.utilities.events import EventHandler, LLMStreamChunkEvent
|
||||
|
||||
|
||||
class MyEventHandler(EventHandler):
|
||||
def on_llm_stream_chunk(self, event: LLMStreamChunkEvent):
|
||||
# Process each chunk as it arrives
|
||||
print(f"Received chunk: {event.chunk}")
|
||||
|
||||
|
||||
# Register the event handler
|
||||
from crewai.utilities.events import crewai_event_bus
|
||||
crewai_event_bus.register_handler(MyEventHandler())
|
||||
@@ -785,7 +820,7 @@ Learn how to get the most out of your LLM configuration:
|
||||
<Tip>
|
||||
Use larger context models for extensive tasks
|
||||
</Tip>
|
||||
|
||||
|
||||
```python
|
||||
# Large context model
|
||||
llm = LLM(model="openai/gpt-4o") # 128K tokens
|
||||
|
||||
@@ -322,6 +322,10 @@ blog_task = Task(
|
||||
- On success: it returns a tuple of `(bool, Any)`. For example: `(True, validated_result)`
|
||||
- On Failure: it returns a tuple of `(bool, str)`. For example: `(False, "Error message explain the failure")`
|
||||
|
||||
### LLMGuardrail
|
||||
|
||||
The `LLMGuardrail` class offers a robust mechanism for validating task outputs.
|
||||
|
||||
### Error Handling Best Practices
|
||||
|
||||
1. **Structured Error Responses**:
|
||||
@@ -750,6 +754,8 @@ Task guardrails provide a powerful way to validate, transform, or filter task ou
|
||||
|
||||
### Basic Usage
|
||||
|
||||
#### Define your own logic to validate
|
||||
|
||||
```python Code
|
||||
from typing import Tuple, Union
|
||||
from crewai import Task
|
||||
@@ -769,6 +775,57 @@ task = Task(
|
||||
)
|
||||
```
|
||||
|
||||
#### Leverage a no-code approach for validation
|
||||
|
||||
```python Code
|
||||
from crewai import Task
|
||||
|
||||
task = Task(
|
||||
description="Generate JSON data",
|
||||
expected_output="Valid JSON object",
|
||||
guardrail="Ensure the response is a valid JSON object"
|
||||
)
|
||||
```
|
||||
|
||||
#### Using YAML
|
||||
|
||||
```yaml
|
||||
research_task:
|
||||
...
|
||||
guardrail: make sure each bullet contains a minimum of 100 words
|
||||
...
|
||||
```
|
||||
|
||||
```python Code
|
||||
@CrewBase
|
||||
class InternalCrew:
|
||||
agents_config = "config/agents.yaml"
|
||||
tasks_config = "config/tasks.yaml"
|
||||
|
||||
...
|
||||
@task
|
||||
def research_task(self):
|
||||
return Task(config=self.tasks_config["research_task"]) # type: ignore[index]
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
#### Use custom models for code generation
|
||||
|
||||
```python Code
|
||||
from crewai import Task
|
||||
from crewai.llm import LLM
|
||||
|
||||
task = Task(
|
||||
description="Generate JSON data",
|
||||
expected_output="Valid JSON object",
|
||||
guardrail=LLMGuardrail(
|
||||
description="Ensure the response is a valid JSON object",
|
||||
llm=LLM(model="gpt-4o-mini"),
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
### How Guardrails Work
|
||||
|
||||
1. **Optional Attribute**: Guardrails are an optional attribute at the task level, allowing you to add validation only where needed.
|
||||
|
||||
@@ -190,48 +190,6 @@ def my_tool(question: str) -> str:
|
||||
return "Result from your custom tool"
|
||||
```
|
||||
|
||||
### Structured Tools
|
||||
|
||||
The `StructuredTool` class wraps functions as tools, providing flexibility and validation while reducing boilerplate. It supports custom schemas and dynamic logic for seamless integration of complex functionalities.
|
||||
|
||||
#### Example:
|
||||
Using `StructuredTool.from_function`, you can wrap a function that interacts with an external API or system, providing a structured interface. This enables robust validation and consistent execution, making it easier to integrate complex functionalities into your applications as demonstrated in the following example:
|
||||
|
||||
```python
|
||||
from crewai.tools.structured_tool import CrewStructuredTool
|
||||
from pydantic import BaseModel
|
||||
|
||||
# Define the schema for the tool's input using Pydantic
|
||||
class APICallInput(BaseModel):
|
||||
endpoint: str
|
||||
parameters: dict
|
||||
|
||||
# Wrapper function to execute the API call
|
||||
def tool_wrapper(*args, **kwargs):
|
||||
# Here, you would typically call the API using the parameters
|
||||
# For demonstration, we'll return a placeholder string
|
||||
return f"Call the API at {kwargs['endpoint']} with parameters {kwargs['parameters']}"
|
||||
|
||||
# Create and return the structured tool
|
||||
def create_structured_tool():
|
||||
return CrewStructuredTool.from_function(
|
||||
name='Wrapper API',
|
||||
description="A tool to wrap API calls with structured input.",
|
||||
args_schema=APICallInput,
|
||||
func=tool_wrapper,
|
||||
)
|
||||
|
||||
# Example usage
|
||||
structured_tool = create_structured_tool()
|
||||
|
||||
# Execute the tool with structured input
|
||||
result = structured_tool._run(**{
|
||||
"endpoint": "https://example.com/api",
|
||||
"parameters": {"key1": "value1", "key2": "value2"}
|
||||
})
|
||||
print(result) # Output: Call the API at https://example.com/api with parameters {'key1': 'value1', 'key2': 'value2'}
|
||||
```
|
||||
|
||||
### Custom Caching Mechanism
|
||||
|
||||
<Tip>
|
||||
|
||||
70
docs/enterprise/features/agent-repository.mdx
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
title: "Agent Repository"
|
||||
description: "Store and retrieve agents for your CrewAI projects"
|
||||
---
|
||||
|
||||
# Agent Repository
|
||||
|
||||
The Agent Repository allows you to store, manage, and reuse agents across your CrewAI projects. This feature streamlines the development process by enabling you to configure agents once and use them in multiple projects.
|
||||
|
||||
## How It Works
|
||||
|
||||
When you create an agent in the CrewAI interface, it's stored in the Agent Repository. You can then initialize these agents in your code using the `from_repository` parameter.
|
||||
|
||||
## Usage
|
||||
|
||||
To use an agent from the repository in your CrewAI project, initialize it with the following code:
|
||||
|
||||
```python
|
||||
from crewai import Agent
|
||||
|
||||
# Initialize the agent with its role
|
||||
agent = Agent(from_repository="python-job-researcher")
|
||||
```
|
||||
|
||||
### Creating a Crew with Repository Agents
|
||||
|
||||
```python
|
||||
from crewai import Agent, Crew, Task
|
||||
|
||||
agent = Agent(from_repository="python-job-researcher")
|
||||
|
||||
job_search_task = Task(
|
||||
description="Search for recent Python developer job listings online",
|
||||
expected_output="Markdown list of 5 recent Python developer jobs with details.",
|
||||
agent=agent,
|
||||
)
|
||||
|
||||
crew = Crew(agents=[agent], tasks=[job_search_task], verbose=True)
|
||||
|
||||
result = crew.kickoff()
|
||||
print(result)
|
||||
```
|
||||
|
||||
## Important Notes
|
||||
|
||||
- The `from_repository` value must match the agent's role in a URL-safe format.
|
||||
- If you change an agent's role after creation, you must update the `from_repository` value in your code accordingly, or you won't be able to find the agent anymore.
|
||||
- Make sure you have permission to use the agent as mentioned in the key points.
|
||||
|
||||
## Agent Configuration
|
||||
|
||||
When configuring an agent in the repository, you can specify:
|
||||
|
||||
1. **Role** - The agent's primary function (e.g., "Python Job Researcher")
|
||||
2. **Goal** - What the agent aims to achieve (e.g., "Find Python developer job opportunities")
|
||||
3. **Backstory** - Context for the agent's behavior
|
||||
4. **Tools** - Available capabilities for the agent to use when performing tasks
|
||||
5. **Visibility Controls** - Who can access and use the agent
|
||||
|
||||
## Managing Agents
|
||||
|
||||
The Agent Repository interface provides functionality to:
|
||||
|
||||
- View all available agents
|
||||
- Add new agents
|
||||
- Edit existing agents
|
||||
- Delete agents
|
||||
- View agent details including usage examples
|
||||
|
||||
By leveraging the Agent Repository, you can build more modular and reusable AI workflows while maintaining a central location for managing your agents.
|
||||
@@ -4,16 +4,16 @@ description: "A Crew is a group of agents that work together to complete a task.
|
||||
icon: "people-arrows"
|
||||
---
|
||||
|
||||
<Tip>
|
||||
## Overview
|
||||
|
||||
[CrewAI Enterprise](https://app.crewai.com) streamlines the process of **creating**, **deploying**, and **managing** your AI agents in production environments.
|
||||
</Tip>
|
||||
|
||||
## Getting Started
|
||||
|
||||
<iframe
|
||||
width="100%"
|
||||
height="400"
|
||||
src="https://www.youtube.com/embed/d1Yp8eeknDk?si=tIxnTRI5UlyCp3z_"
|
||||
src="https://www.youtube.com/embed/-kSOTtYzgEw"
|
||||
title="Building Crews with CrewAI CLI"
|
||||
frameborder="0"
|
||||
style={{ borderRadius: '10px' }}
|
||||
|
||||
@@ -4,12 +4,12 @@ description: "Deploy your local CrewAI project to the Enterprise platform"
|
||||
icon: "cloud-arrow-up"
|
||||
---
|
||||
|
||||
## Option 1: CLI Deployment
|
||||
## Overview
|
||||
|
||||
<Tip>
|
||||
This video tutorial walks you through the process of deploying your locally developed CrewAI project to the CrewAI Enterprise platform,
|
||||
This guide will walk you through the process of deploying your locally developed CrewAI project to the CrewAI Enterprise platform,
|
||||
transforming it into a production-ready API endpoint.
|
||||
</Tip>
|
||||
|
||||
## Option 1: CLI Deployment
|
||||
|
||||
<iframe
|
||||
width="100%"
|
||||
@@ -22,7 +22,7 @@ transforming it into a production-ready API endpoint.
|
||||
allowfullscreen
|
||||
></iframe>
|
||||
|
||||
## Prerequisites
|
||||
### Prerequisites
|
||||
|
||||
Before starting the deployment process, make sure you have:
|
||||
|
||||
@@ -35,138 +35,159 @@ For a quick reference project, you can clone our example repository at [github.c
|
||||
</Note>
|
||||
|
||||
|
||||
<Steps>
|
||||
|
||||
### Step 1: Authenticate with the Enterprise Platform
|
||||
<Step title="Authenticate with the Enterprise Platform">
|
||||
First, you need to authenticate your CLI with the CrewAI Enterprise platform:
|
||||
|
||||
First, you need to authenticate your CLI with the CrewAI Enterprise platform:
|
||||
```bash
|
||||
# If you already have a CrewAI Enterprise account
|
||||
crewai login
|
||||
|
||||
```bash
|
||||
# If you already have a CrewAI Enterprise account
|
||||
crewai login
|
||||
# If you're creating a new account
|
||||
crewai signup
|
||||
```
|
||||
|
||||
# If you're creating a new account
|
||||
crewai signup
|
||||
```
|
||||
When you run either command, the CLI will:
|
||||
1. Display a URL and a unique device code
|
||||
2. Open your browser to the authentication page
|
||||
3. Prompt you to confirm the device
|
||||
4. Complete the authentication process
|
||||
|
||||
When you run either command, the CLI will:
|
||||
1. Display a URL and a unique device code
|
||||
2. Open your browser to the authentication page
|
||||
3. Prompt you to confirm the device
|
||||
4. Complete the authentication process
|
||||
Upon successful authentication, you'll see a confirmation message in your terminal!
|
||||
|
||||
Upon successful authentication, you'll see a confirmation message in your terminal!
|
||||
</Step>
|
||||
|
||||
### Step 2: Create a Deployment
|
||||
<Step title="Create a Deployment">
|
||||
|
||||
From your project directory, run:
|
||||
From your project directory, run:
|
||||
|
||||
```bash
|
||||
crewai deploy create
|
||||
```
|
||||
```bash
|
||||
crewai deploy create
|
||||
```
|
||||
|
||||
This command will:
|
||||
1. Detect your GitHub repository information
|
||||
2. Identify environment variables in your local `.env` file
|
||||
3. Securely transfer these variables to the Enterprise platform
|
||||
4. Create a new deployment with a unique identifier
|
||||
This command will:
|
||||
1. Detect your GitHub repository information
|
||||
2. Identify environment variables in your local `.env` file
|
||||
3. Securely transfer these variables to the Enterprise platform
|
||||
4. Create a new deployment with a unique identifier
|
||||
|
||||
On successful creation, you'll see a message like:
|
||||
```shell
|
||||
Deployment created successfully!
|
||||
Name: your_project_name
|
||||
Deployment ID: 01234567-89ab-cdef-0123-456789abcdef
|
||||
Current Status: Deploy Enqueued
|
||||
```
|
||||
On successful creation, you'll see a message like:
|
||||
```shell
|
||||
Deployment created successfully!
|
||||
Name: your_project_name
|
||||
Deployment ID: 01234567-89ab-cdef-0123-456789abcdef
|
||||
Current Status: Deploy Enqueued
|
||||
```
|
||||
|
||||
### Step 3: Monitor Deployment Progress
|
||||
</Step>
|
||||
|
||||
Track the deployment status with:
|
||||
<Step title="Monitor Deployment Progress">
|
||||
|
||||
```bash
|
||||
crewai deploy status
|
||||
```
|
||||
Track the deployment status with:
|
||||
|
||||
For detailed logs of the build process:
|
||||
```bash
|
||||
crewai deploy status
|
||||
```
|
||||
|
||||
```bash
|
||||
crewai deploy logs
|
||||
```
|
||||
For detailed logs of the build process:
|
||||
|
||||
<Tip>
|
||||
The first deployment typically takes 10-15 minutes as it builds the container images. Subsequent deployments are much faster.
|
||||
</Tip>
|
||||
```bash
|
||||
crewai deploy logs
|
||||
```
|
||||
|
||||
### Additional CLI Commands
|
||||
<Tip>
|
||||
The first deployment typically takes 10-15 minutes as it builds the container images. Subsequent deployments are much faster.
|
||||
</Tip>
|
||||
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
## Additional CLI Commands
|
||||
|
||||
The CrewAI CLI offers several commands to manage your deployments:
|
||||
|
||||
```bash
|
||||
# List all your deployments
|
||||
crewai deploy list
|
||||
```bash
|
||||
# List all your deployments
|
||||
crewai deploy list
|
||||
|
||||
# Get the status of your deployment
|
||||
crewai deploy status
|
||||
# Get the status of your deployment
|
||||
crewai deploy status
|
||||
|
||||
# View the logs of your deployment
|
||||
crewai deploy logs
|
||||
# View the logs of your deployment
|
||||
crewai deploy logs
|
||||
|
||||
# Push updates after code changes
|
||||
crewai deploy push
|
||||
# Push updates after code changes
|
||||
crewai deploy push
|
||||
|
||||
# Remove a deployment
|
||||
crewai deploy remove <deployment_id>
|
||||
```
|
||||
# Remove a deployment
|
||||
crewai deploy remove <deployment_id>
|
||||
```
|
||||
|
||||
## Option 2: Deploy Directly via Web Interface
|
||||
|
||||
You can also deploy your crews directly through the CrewAI Enterprise web interface by connecting your GitHub account. This approach doesn't require using the CLI on your local machine.
|
||||
|
||||
### Step 1: Pushing to GitHub
|
||||
<Steps>
|
||||
|
||||
First, you need to push your crew to a GitHub repository. If you haven't created a crew yet, you can [follow this tutorial](/quickstart).
|
||||
<Step title="Pushing to GitHub">
|
||||
|
||||
### Step 2: Connecting GitHub to CrewAI Enterprise
|
||||
You need to push your crew to a GitHub repository. If you haven't created a crew yet, you can [follow this tutorial](/quickstart).
|
||||
|
||||
1. Log in to [CrewAI Enterprise](https://app.crewai.com)
|
||||
2. Click on the button "Connect GitHub"
|
||||
</Step>
|
||||
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
<Step title="Connecting GitHub to CrewAI Enterprise">
|
||||
|
||||
### Step 3: Select the Repository
|
||||
1. Log in to [CrewAI Enterprise](https://app.crewai.com)
|
||||
2. Click on the button "Connect GitHub"
|
||||
|
||||
After connecting your GitHub account, you'll be able to select which repository to deploy:
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
</Step>
|
||||
|
||||
### Step 4: Set Environment Variables
|
||||
<Step title="Select the Repository">
|
||||
|
||||
Before deploying, you'll need to set up your environment variables to connect to your LLM provider or other services:
|
||||
After connecting your GitHub account, you'll be able to select which repository to deploy:
|
||||
|
||||
1. You can add variables individually or in bulk
|
||||
2. Enter your environment variables in `KEY=VALUE` format (one per line)
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
</Step>
|
||||
|
||||
### Step 5: Deploy Your Crew
|
||||
<Step title="Set Environment Variables">
|
||||
|
||||
1. Click the "Deploy" button to start the deployment process
|
||||
2. You can monitor the progress through the progress bar
|
||||
3. The first deployment typically takes around 10-15 minutes; subsequent deployments will be faster
|
||||
Before deploying, you'll need to set up your environment variables to connect to your LLM provider or other services:
|
||||
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
1. You can add variables individually or in bulk
|
||||
2. Enter your environment variables in `KEY=VALUE` format (one per line)
|
||||
|
||||
Once deployment is complete, you'll see:
|
||||
- Your crew's unique URL
|
||||
- A Bearer token to protect your crew API
|
||||
- A "Delete" button if you need to remove the deployment
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Deploy Your Crew">
|
||||
|
||||
1. Click the "Deploy" button to start the deployment process
|
||||
2. You can monitor the progress through the progress bar
|
||||
3. The first deployment typically takes around 10-15 minutes; subsequent deployments will be faster
|
||||
|
||||
<Frame>
|
||||

|
||||
</Frame>
|
||||
|
||||
Once deployment is complete, you'll see:
|
||||
- Your crew's unique URL
|
||||
- A Bearer token to protect your crew API
|
||||
- A "Delete" button if you need to remove the deployment
|
||||
|
||||
</Step>
|
||||
|
||||
</Steps>
|
||||
|
||||
### Interact with Your Deployed Crew
|
||||
|
||||
@@ -193,7 +214,7 @@ From the Enterprise dashboard, you can:
|
||||
3. Enter the required inputs in the modal that appears
|
||||
4. Monitor progress as the execution moves through the pipeline
|
||||
|
||||
## Monitoring and Analytics
|
||||
### Monitoring and Analytics
|
||||
|
||||
The Enterprise platform provides comprehensive observability features:
|
||||
|
||||
@@ -202,7 +223,7 @@ The Enterprise platform provides comprehensive observability features:
|
||||
- **Metrics**: Token usage, execution times, and costs
|
||||
- **Timeline View**: Visual representation of task sequences
|
||||
|
||||
## Advanced Features
|
||||
### Advanced Features
|
||||
|
||||
The Enterprise platform also offers:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ description: "Kickoff a Crew on CrewAI Enterprise"
|
||||
icon: "flag-checkered"
|
||||
---
|
||||
|
||||
# Kickoff a Crew on CrewAI Enterprise
|
||||
## Overview
|
||||
|
||||
Once you've deployed your crew to the CrewAI Enterprise platform, you can kickoff executions through the web interface or the API. This guide covers both approaches.
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ icon: "globe"
|
||||
|
||||
CrewAI Enterprise provides a platform for deploying, monitoring, and scaling your crews and agents in a production environment.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crewai-enterprise-dashboard.png" alt="CrewAI Enterprise Dashboard" />
|
||||
</Frame>
|
||||
|
||||
CrewAI Enterprise extends the power of the open-source framework with features designed for production deployments, collaboration, and scalability. Deploy your crews to a managed infrastructure and monitor their execution in real-time.
|
||||
|
||||
## Key Features
|
||||
@@ -52,15 +56,43 @@ CrewAI Enterprise extends the power of the open-source framework with features d
|
||||
<Steps>
|
||||
<Step title="Sign up for an account">
|
||||
Create your account at [app.crewai.com](https://app.crewai.com)
|
||||
<Card
|
||||
title="Sign Up"
|
||||
icon="user"
|
||||
href="https://app.crewai.com/signup"
|
||||
>
|
||||
Sign Up
|
||||
</Card>
|
||||
</Step>
|
||||
<Step title="Create your first crew">
|
||||
Use code or Crew Studio to create your crew
|
||||
<Card
|
||||
title="Create Crew"
|
||||
icon="paintbrush"
|
||||
href="/enterprise/guides/create-crew"
|
||||
>
|
||||
Create Crew
|
||||
</Card>
|
||||
</Step>
|
||||
<Step title="Deploy your crew">
|
||||
Deploy your crew to the Enterprise platform
|
||||
<Card
|
||||
title="Deploy Crew"
|
||||
icon="rocket"
|
||||
href="/enterprise/guides/deploy-crew"
|
||||
>
|
||||
Deploy Crew
|
||||
</Card>
|
||||
</Step>
|
||||
<Step title="Access your crew">
|
||||
Integrate with your crew via the generated API endpoints
|
||||
<Card
|
||||
title="API Access"
|
||||
icon="code"
|
||||
href="/enterprise/guides/use-crew-api"
|
||||
>
|
||||
Use the Crew API
|
||||
</Card>
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
|
||||
@@ -93,12 +93,6 @@ icon: "code"
|
||||
<Card href="https://docs.crewai.com/concepts/memory" icon="brain">CrewAI Memory</Card>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How can I create custom tools for my CrewAI agents?">
|
||||
You can create custom tools by subclassing the `BaseTool` class provided by CrewAI or by using the tool decorator. Subclassing involves defining a new class that inherits from `BaseTool`, specifying the name, description, and the `_run` method for operational logic. The tool decorator allows you to create a `Tool` object directly with the required attributes and a functional logic.
|
||||
Click here for more details:
|
||||
<Card href="https://docs.crewai.com/how-to/create-custom-tools" icon="code">CrewAI Tools</Card>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How do I use Output Pydantic in a Task?">
|
||||
To use Output Pydantic in a task, you need to define the expected output of the task as a Pydantic model. Here's an example:
|
||||
<Steps>
|
||||
@@ -178,4 +172,793 @@ icon: "code"
|
||||
allowfullscreen></iframe>
|
||||
</Frame>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How can I create custom tools for my CrewAI agents?">
|
||||
You can create custom tools by subclassing the `BaseTool` class provided by CrewAI or by using the tool decorator. Subclassing involves defining a new class that inherits from `BaseTool`, specifying the name, description, and the `_run` method for operational logic. The tool decorator allows you to create a `Tool` object directly with the required attributes and a functional logic.
|
||||
Click here for more details:
|
||||
<Card href="https://docs.crewai.com/how-to/create-custom-tools" icon="code">CrewAI Tools</Card>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to Kickoff a Crew from Slack">
|
||||
This guide explains how to start a crew directly from Slack using the CrewAI integration.
|
||||
|
||||
**Prerequisites:**
|
||||
<ul>
|
||||
<li>CrewAI integration installed and connected to your Slack workspace</li>
|
||||
<li>At least one crew configured in CrewAI</li>
|
||||
</ul>
|
||||
|
||||
**Steps:**
|
||||
<Steps>
|
||||
<Step title="Ensure the CrewAI Slack integration is set up">
|
||||
In the CrewAI dashboard, navigate to the **Integrations** section.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/slack-integration.png" alt="CrewAI Slack Integration" />
|
||||
</Frame>
|
||||
|
||||
Verify that Slack is listed and is connected.
|
||||
</Step>
|
||||
<Step title="Open your Slack channel">
|
||||
- Navigate to the channel where you want to kickoff the crew.
|
||||
- Type the slash command "**/kickoff**" to initiate the crew kickoff process.
|
||||
- You should see a "**Kickoff crew**" appear as you type:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/kickoff-slack-crew.png" alt="Kickoff crew" />
|
||||
</Frame>
|
||||
- Press Enter or select the "**Kickoff crew**" option. A dialog box titled "**Kickoff an AI Crew**" will appear.
|
||||
</Step>
|
||||
<Step title="Select the crew you want to start">
|
||||
- In the dropdown menu labeled "**Select of the crews online:**", choose the crew you want to start.
|
||||
- In the example below, "**prep-for-meeting**" is selected:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/kickoff-slack-crew-dropdown.png" alt="Kickoff crew dropdown" />
|
||||
</Frame>
|
||||
- If your crew requires any inputs, click the "**Add Inputs**" button to provide them.
|
||||
<Note>
|
||||
The "**Add Inputs**" button is shown in the example above but is not yet clicked.
|
||||
</Note>
|
||||
</Step>
|
||||
<Step title="Click Kickoff and wait for the crew to complete">
|
||||
- Once you've selected the crew and added any necessary inputs, click "**Kickoff**" to start the crew.
|
||||
<Frame>
|
||||
<img src="/images/enterprise/kickoff-slack-crew-kickoff.png" alt="Kickoff crew" />
|
||||
</Frame>
|
||||
- The crew will start executing and you will see the results in the Slack channel.
|
||||
<Frame>
|
||||
<img src="/images/enterprise/kickoff-slack-crew-results.png" alt="Kickoff crew results" />
|
||||
</Frame>
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
<Tip>
|
||||
- Make sure you have the necessary permissions to use the `/kickoff` command in your Slack workspace.
|
||||
|
||||
- If you don't see your desired crew in the dropdown, ensure it's properly configured and online in CrewAI.
|
||||
</Tip>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to export and use a React Component">
|
||||
Click on the ellipsis (three dots on the right of your deployed crew) and select the export option and save the file locally. We will be using `CrewLead.jsx` for our example.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/export-react-component.png" alt="Export React Component" />
|
||||
</Frame>
|
||||
|
||||
To run this React component locally, you'll need to set up a React development environment and integrate this component into a React project. Here's a step-by-step guide to get you started:
|
||||
|
||||
<Steps>
|
||||
<Step title="Install Node.js">
|
||||
- Download and install Node.js from the official website: https://nodejs.org/
|
||||
- Choose the LTS (Long Term Support) version for stability.
|
||||
</Step>
|
||||
|
||||
<Step title="Create a new React project">
|
||||
- Open Command Prompt or PowerShell
|
||||
- Navigate to the directory where you want to create your project
|
||||
- Run the following command to create a new React project:
|
||||
|
||||
```bash
|
||||
npx create-react-app my-crew-app
|
||||
```
|
||||
- Change into the project directory:
|
||||
|
||||
```bash
|
||||
cd my-crew-app
|
||||
```
|
||||
</Step>
|
||||
|
||||
<Step title="Install necessary dependencies">
|
||||
|
||||
```bash
|
||||
npm install react-dom
|
||||
```
|
||||
</Step>
|
||||
|
||||
<Step title="Create the CrewLead component">
|
||||
- Move the downloaded file `CrewLead.jsx` into the `src` folder of your project,
|
||||
</Step>
|
||||
|
||||
<Step title="Modify your `App.js` to use the `CrewLead` component">
|
||||
- Open `src/App.js`
|
||||
- Replace its contents with something like this:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import CrewLead from './CrewLead';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<CrewLead baseUrl="YOUR_API_BASE_URL" bearerToken="YOUR_BEARER_TOKEN" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
```
|
||||
- Replace `YOUR_API_BASE_URL` and `YOUR_BEARER_TOKEN` with the actual values for your API.
|
||||
</Step>
|
||||
|
||||
<Step title="Start the development server">
|
||||
- In your project directory, run:
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
- This will start the development server, and your default web browser should open automatically to http://localhost:3000, where you'll see your React app running.
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
You can then customise the `CrewLead.jsx` to add color, title etc
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/customise-react-component.png" alt="Customise React Component" />
|
||||
</Frame>
|
||||
<Frame>
|
||||
<img src="/images/enterprise/customise-react-component-2.png" alt="Customise React Component" />
|
||||
</Frame>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to Invite Team Members to Your CrewAI Enterprise Organization">
|
||||
As an administrator of a CrewAI Enterprise account, you can easily invite new team members to join your organization. This article will guide you through the process step-by-step.
|
||||
<Steps>
|
||||
<Step title="Access the Settings Page">
|
||||
- Log in to your CrewAI Enterprise account
|
||||
- Look for the gear icon (⚙️) in the top right corner of the dashboard
|
||||
- Click on the gear icon to access the **Settings** page:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/settings-page.png" alt="Settings Page" />
|
||||
</Frame>
|
||||
</Step>
|
||||
<Step title="Navigate to the Members Section">
|
||||
- On the Settings page, you'll see a `General configuration` header
|
||||
- Below this, find and click on the `Members` tab
|
||||
</Step>
|
||||
<Step title="Invite New Members">
|
||||
- In the Members section, you'll see a list of current members (including yourself)
|
||||
- At the bottom of the list, locate the `Email` input field
|
||||
- Enter the email address of the person you want to invite
|
||||
- Click the `Invite` button next to the email field
|
||||
</Step>
|
||||
<Step title="Repeat as Needed">
|
||||
- You can repeat this process to invite multiple team members
|
||||
- Each invited member will receive an email invitation to join your organization
|
||||
</Step>
|
||||
<Step title="Important Notes">
|
||||
- Only users with administrative privileges can invite new members
|
||||
- Ensure you have the correct email addresses for your team members
|
||||
- Invited members will need to accept the invitation to join your organization
|
||||
- You may want to inform your team members to check their email (including spam folders) for the invitation
|
||||
</Step>
|
||||
</Steps>
|
||||
By following these steps, you can easily expand your team and collaborate more effectively within your CrewAI Enterprise organization.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Using Webhooks in CrewAI Enterprise">
|
||||
CrewAI Enterprise allows you to automate your workflow using webhooks.
|
||||
This article will guide you through the process of setting up and using webhooks to kickoff your crew execution, with a focus on integration with ActivePieces,
|
||||
a workflow automation platform similar to Zapier and Make.com. We will be setting up webhooks in the CrewAI Enterprise UI.
|
||||
|
||||
<Steps>
|
||||
<Step title="Accessing the Kickoff Interface">
|
||||
- Navigate to the CrewAI Enterprise dashboard
|
||||
- Look for the `/kickoff` section, which is used to start the crew execution
|
||||
<Frame>
|
||||
<img src="/images/enterprise/kickoff-interface.png" alt="Kickoff Interface" />
|
||||
</Frame>
|
||||
</Step>
|
||||
|
||||
<Step title="Configuring the JSON Content">
|
||||
In the JSON Content section, you'll need to provide the following information:
|
||||
|
||||
- **inputs**: A JSON object containing:
|
||||
- `company`: The name of the company (e.g., "tesla")
|
||||
- `product_name`: The name of the product (e.g., "crewai")
|
||||
- `form_response`: The type of response (e.g., "financial")
|
||||
- `icp_description`: A brief description of the Ideal Customer Profile
|
||||
- `product_description`: A short description of the product
|
||||
- `taskWebhookUrl`, `stepWebhookUrl`, `crewWebhookUrl`: URLs for various webhook endpoints (ActivePieces, Zapier, Make.com or another compatible platform)
|
||||
</Step>
|
||||
|
||||
<Step title="Integrating with ActivePieces">
|
||||
In this example we will be using ActivePieces. You can use other platforms such as Zapier and Make.com
|
||||
|
||||
To integrate with ActivePieces:
|
||||
|
||||
1. Set up a new flow in ActivePieces
|
||||
2. Add a trigger (e.g., `Every Day` schedule)
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-trigger.png" alt="ActivePieces Trigger" />
|
||||
</Frame>
|
||||
|
||||
3. Add an HTTP action step
|
||||
- Set the action to `Send HTTP request`
|
||||
- Use `POST` as the method
|
||||
- Set the URL to your CrewAI Enterprise kickoff endpoint
|
||||
- Add necessary headers (e.g., `Bearer Token`)
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-headers.png" alt="ActivePieces Headers" />
|
||||
</Frame>
|
||||
|
||||
- In the body, include the JSON content as configured in step 2
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-body.png" alt="ActivePieces Body" />
|
||||
</Frame>
|
||||
|
||||
- The crew will then kickoff at the pre-defined time.
|
||||
</Step>
|
||||
|
||||
<Step title="Setting Up the Webhook">
|
||||
1. Create a new flow in ActivePieces and name it
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-flow.png" alt="ActivePieces Flow" />
|
||||
</Frame>
|
||||
|
||||
2. Add a webhook step as the trigger:
|
||||
- Select `Catch Webhook` as the trigger type
|
||||
- This will generate a unique URL that will receive HTTP requests and trigger your flow
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-webhook.png" alt="ActivePieces Webhook" />
|
||||
</Frame>
|
||||
|
||||
- Configure the email to use crew webhook body text
|
||||
<Frame>
|
||||
<img src="/images/enterprise/activepieces-email.png" alt="ActivePieces Email" />
|
||||
</Frame>
|
||||
</Step>
|
||||
<Step title="Generated output">
|
||||
1. `stepWebhookUrl` - Callback that will be executed upon each agent inner thought
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "**Preliminary Research Report on the Financial Industry for crewai Enterprise Solution**\n1. Industry Overview and Trends\nThe financial industry in ....\nConclusion:\nThe financial industry presents a fertile ground for implementing AI solutions like crewai, particularly in areas such as digital customer engagement, risk management, and regulatory compliance. Further engagement with the lead is recommended to better tailor the crewai solution to their specific needs and scale.",
|
||||
"task_id": "97eba64f-958c-40a0-b61c-625fe635a3c0"
|
||||
}
|
||||
```
|
||||
|
||||
2. `taskWebhookUrl` - Callback that will be executed upon the end of each task
|
||||
|
||||
```json
|
||||
{
|
||||
"description": "Using the information gathered from the lead's data, conduct preliminary research on the lead's industry, company background, and potential use cases for crewai. Focus on finding relevant data that can aid in scoring the lead and planning a strategy to pitch them crewai.The financial industry presents a fertile ground for implementing AI solutions like crewai, particularly in areas such as digital customer engagement, risk management, and regulatory compliance. Further engagement with the lead is recommended to better tailor the crewai solution to their specific needs and scale.",
|
||||
"task_id": "97eba64f-958c-40a0-b61c-625fe635a3c0"
|
||||
}
|
||||
```
|
||||
|
||||
3. `crewWebhookUrl` - Callback that will be executed upon the end of the crew execution
|
||||
|
||||
```json
|
||||
{
|
||||
"task_id": "97eba64f-958c-40a0-b61c-625fe635a3c0",
|
||||
"result": {
|
||||
"lead_score": "Customer service enhancement, and compliance are particularly relevant.",
|
||||
"talking_points": [
|
||||
"Highlight how crewai's AI solutions can transform customer service with automated, personalized experiences and 24/7 support, improving both customer satisfaction and operational efficiency.",
|
||||
"Discuss crewai's potential to help the institution achieve its sustainability goals through better data analysis and decision-making, contributing to responsible investing and green initiatives.",
|
||||
"Emphasize crewai's ability to enhance compliance with evolving regulations through efficient data processing and reporting, reducing the risk of non-compliance penalties.",
|
||||
"Stress the adaptability of crewai to support both extensive multinational operations and smaller, targeted projects, ensuring the solution grows with the institution's needs."
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
</Step>
|
||||
</Steps>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to use the crewai custom GPT to create a crew">
|
||||
<Steps>
|
||||
<Step title="Navigate to the CrewAI custom GPT">
|
||||
Click here https://chatgpt.com/g/g-qqTuUWsBY-crewai-assistant to access the CrewAI custom GPT
|
||||
<Card href="https://chatgpt.com/g/g-qqTuUWsBY-crewai-assistant" icon="comments">CrewAI custom GPT</Card>
|
||||
</Step>
|
||||
<Step title="Describe your project idea">
|
||||
For example:
|
||||
```text
|
||||
Suggest some agents and tasks to retrieve LinkedIn profile details for a given person and a domain.
|
||||
```
|
||||
</Step>
|
||||
<Step title="The GPT will provide you with a list of suggested agents and tasks">
|
||||
Here's an example of the response you will get:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crewai-custom-gpt-1.png" alt="CrewAI custom GPT 1" />
|
||||
</Frame>
|
||||
</Step>
|
||||
<Step title="Create the project structure in your terminal by entering:">
|
||||
```bash
|
||||
crewai create crew linkedin-profile
|
||||
```
|
||||
This will create a new crew called `linkedin-profile` in the current directory.
|
||||
|
||||
Follow the full instructions in the https://docs.crewai.com/quickstart to create a crew.
|
||||
<Card href="https://docs.crewai.com/quickstart" icon="code">CrewAI Docs</Card>
|
||||
</Step>
|
||||
<Step title="Ask the GPT to convert the agents and tasks to YAML format.">
|
||||
Here's an example of the final output you will have to save in the `agents.yaml` and `tasks.yaml` files:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crewai-custom-gpt-2.png" alt="CrewAI custom GPT 2" />
|
||||
</Frame>
|
||||
- Now replace the `agents.yaml` and `tasks.yaml` with the above code
|
||||
- Ask GPT to create the custom LinkedIn Tool
|
||||
- Ask the GPT to put everything together into the `crew.py` file
|
||||
- You will now have a fully working crew.
|
||||
</Step>
|
||||
</Steps>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to generate images using Dall-E">
|
||||
CrewAI supports integration with OpenAI's DALL-E, allowing your AI agents to generate images as part of their tasks. This guide will walk you through how to set up and use the DALL-E tool in your CrewAI projects.
|
||||
|
||||
**Prerequisites**
|
||||
- crewAI installed (latest version)
|
||||
- OpenAI API key with access to DALL-E
|
||||
|
||||
**Setting Up the DALL-E Tool**
|
||||
To use the DALL-E tool in your CrewAI project, follow these steps:
|
||||
<Steps>
|
||||
<Step title="Import the DALL-E tool">
|
||||
|
||||
```python
|
||||
from crewai_tools import DallETool
|
||||
```
|
||||
</Step>
|
||||
|
||||
<Step title="Add the DALL-E tool to your agent configuration">
|
||||
|
||||
```python
|
||||
@agent
|
||||
def researcher(self) -> Agent:
|
||||
return Agent(
|
||||
config=self.agents_config['researcher'],
|
||||
tools=[SerperDevTool(), DallETool()], # Add DallETool to the list of tools
|
||||
allow_delegation=False,
|
||||
verbose=True
|
||||
)
|
||||
```
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
**Using the DALL-E Tool**
|
||||
|
||||
Once you've added the DALL-E tool to your agent, it can generate images based on text prompts.
|
||||
The tool will return a URL to the generated image, which can be used in the agent's output or passed to other agents for further processing.
|
||||
|
||||
Example usage within a task:
|
||||
```YAML
|
||||
role: >
|
||||
LinkedIn Profile Senior Data Researcher
|
||||
goal: >
|
||||
Uncover detailed LinkedIn profiles based on provided name {name} and domain {domain}
|
||||
Generate a Dall-e image based on domain {domain}
|
||||
backstory: >
|
||||
You're a seasoned researcher with a knack for uncovering the most relevant LinkedIn profiles.
|
||||
Known for your ability to navigate LinkedIn efficiently, you excel at gathering and presenting
|
||||
professional information clearly and concisely.
|
||||
```
|
||||
|
||||
The agent with the DALL-E tool will be able to generate the image and provide a URL in its response. You can then download the image.
|
||||
<Frame>
|
||||
<img src="/images/enterprise/dall-e-image.png" alt="DALL-E Image" />
|
||||
</Frame>
|
||||
|
||||
**Best Practices**
|
||||
|
||||
1. Be specific in your image generation prompts to get the best results.
|
||||
2. Remember that image generation can take some time, so factor this into your task planning.
|
||||
3. Always comply with OpenAI's usage policies when generating images.
|
||||
|
||||
**Troubleshooting**
|
||||
1. Ensure your OpenAI API key has access to DALL-E.
|
||||
2. Check that you're using the latest version of crewAI and crewai-tools.
|
||||
3. Verify that the DALL-E tool is correctly added to the agent's tool list.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to use Annotations in crew.py">
|
||||
This guide explains how to use annotations to properly reference **agents**, **tasks**, and other components in the `crew.py` file.
|
||||
|
||||
**Introduction**
|
||||
|
||||
Annotations in the framework are used to decorate classes and methods, providing metadata and functionality to various components of your crew.
|
||||
These annotations help in organizing and structuring your code, making it more readable and maintainable.
|
||||
|
||||
**Available Annotations**
|
||||
|
||||
The CrewAI framework provides the following annotations:
|
||||
|
||||
- `@CrewBase`: Used to decorate the main crew class.
|
||||
- `@agent`: Decorates methods that define and return Agent objects.
|
||||
- `@task`: Decorates methods that define and return Task objects.
|
||||
- `@crew`: Decorates the method that creates and returns the Crew object.
|
||||
- `@llm`: Decorates methods that initialize and return Language Model objects.
|
||||
- `@tool`: Decorates methods that initialize and return Tool objects.
|
||||
- `@callback`: (Not shown in the example, but available) Used for defining callback methods.
|
||||
- `@output_json`: (Not shown in the example, but available) Used for methods that output JSON data.
|
||||
- `@output_pydantic`: (Not shown in the example, but available) Used for methods that output Pydantic models.
|
||||
- `@cache_handler`: (Not shown in the example, but available) Used for defining cache handling methods.
|
||||
|
||||
**Usage Examples**
|
||||
|
||||
Let's go through examples of how to use these annotations based on the provided LinkedinProfileCrew class:
|
||||
|
||||
**1. Crew Base Class**
|
||||
```python
|
||||
@CrewBase
|
||||
class LinkedinProfileCrew():
|
||||
"""LinkedinProfile crew"""
|
||||
agents_config = 'config/agents.yaml'
|
||||
tasks_config = 'config/tasks.yaml'
|
||||
```
|
||||
|
||||
The `@CrewBase` annotation is used to decorate the main crew class.
|
||||
This class typically contains configurations and methods for creating agents, tasks, and the crew itself.
|
||||
|
||||
**2. Tool Definition**
|
||||
```python
|
||||
@tool
|
||||
def myLinkedInProfileTool(self):
|
||||
return LinkedInProfileTool()
|
||||
```
|
||||
|
||||
The `@tool` annotation is used to decorate methods that return tool objects. These tools can be used by agents to perform specific tasks.
|
||||
|
||||
**3. LLM Definition**
|
||||
```python
|
||||
@llm
|
||||
def groq_llm(self):
|
||||
api_key = os.getenv('api_key')
|
||||
return ChatGroq(api_key=api_key, temperature=0, model_name="mixtral-8x7b-32768")
|
||||
```
|
||||
|
||||
The `@llm` annotation is used to decorate methods that initialize and return Language Model objects. These LLMs are used by agents for natural language processing tasks.
|
||||
|
||||
**4. Agent Definition**
|
||||
```python
|
||||
@agent
|
||||
def researcher(self) -> Agent:
|
||||
return Agent(
|
||||
config=self.agents_config['researcher']
|
||||
)
|
||||
```
|
||||
|
||||
The `@agent` annotation is used to decorate methods that define and return Agent objects.
|
||||
|
||||
**5. Task Definition**
|
||||
```python
|
||||
@task
|
||||
def research_task(self) -> Task:
|
||||
return Task(
|
||||
config=self.tasks_config['research_linkedin_task'],
|
||||
agent=self.researcher()
|
||||
)
|
||||
```
|
||||
|
||||
The `@task` annotation is used to decorate methods that define and return Task objects. These methods specify the task configuration and the agent responsible for the task.
|
||||
|
||||
**6. Crew Creation**
|
||||
```python
|
||||
@crew
|
||||
def crew(self) -> Crew:
|
||||
"""Creates the LinkedinProfile crew"""
|
||||
return Crew(
|
||||
agents=self.agents,
|
||||
tasks=self.tasks,
|
||||
process=Process.sequential,
|
||||
verbose=True
|
||||
)
|
||||
```
|
||||
|
||||
The `@crew` annotation is used to decorate the method that creates and returns the `Crew` object. This method assembles all the components (agents and tasks) into a functional crew.
|
||||
|
||||
**YAML Configuration**
|
||||
|
||||
The agent configurations are typically stored in a YAML file. Here's an example of how the `agents.yaml` file might look for the researcher agent:
|
||||
|
||||
```yaml
|
||||
researcher:
|
||||
role: >
|
||||
LinkedIn Profile Senior Data Researcher
|
||||
goal: >
|
||||
Uncover detailed LinkedIn profiles based on provided name {name} and domain {domain}
|
||||
Generate a Dall-E image based on domain {domain}
|
||||
backstory: >
|
||||
You're a seasoned researcher with a knack for uncovering the most relevant LinkedIn profiles.
|
||||
Known for your ability to navigate LinkedIn efficiently, you excel at gathering and presenting
|
||||
professional information clearly and concisely.
|
||||
allow_delegation: False
|
||||
verbose: True
|
||||
llm: groq_llm
|
||||
tools:
|
||||
- myLinkedInProfileTool
|
||||
- mySerperDevTool
|
||||
- myDallETool
|
||||
```
|
||||
|
||||
This YAML configuration corresponds to the researcher agent defined in the `LinkedinProfileCrew` class. The configuration specifies the agent's role, goal, backstory, and other properties such as the LLM and tools it uses.
|
||||
|
||||
Note how the `llm` and `tools` in the YAML file correspond to the methods decorated with `@llm` and `@tool` in the Python class. This connection allows for a flexible and modular design where you can easily update agent configurations without changing the core code.
|
||||
|
||||
**Best Practices**
|
||||
- **Consistent Naming**: Use clear and consistent naming conventions for your methods. For example, agent methods could be named after their roles (e.g., researcher, reporting_analyst).
|
||||
- **Environment Variables**: Use environment variables for sensitive information like API keys.
|
||||
- **Flexibility**: Design your crew to be flexible by allowing easy addition or removal of agents and tasks.
|
||||
- **YAML-Code Correspondence**: Ensure that the names and structures in your YAML files correspond correctly to the decorated methods in your Python code.
|
||||
|
||||
By following these guidelines and properly using annotations, you can create well-structured and maintainable crews using the CrewAI framework.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to Integrate CrewAI Enterprise with Zapier">
|
||||
This guide will walk you through the process of integrating CrewAI Enterprise with Zapier, allowing you to automate workflows between CrewAI Enterprise and other applications.
|
||||
|
||||
**Prerequisites**
|
||||
- A CrewAI Enterprise account
|
||||
- A Zapier account
|
||||
- A Slack account (for this specific integration)
|
||||
|
||||
**Step-by-Step Guide**
|
||||
<Steps>
|
||||
<Step title="Set Up the Slack Trigger">
|
||||
|
||||
- In Zapier, create a new Zap.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-1.png" alt="Zapier 1" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Choose Slack as your trigger app.">
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-2.png" alt="Zapier 2" />
|
||||
</Frame>
|
||||
- Select `New Pushed Message` as the Trigger Event.
|
||||
- Connect your Slack account if you haven't already.
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Configure the CrewAI Enterprise Action">
|
||||
|
||||
- Add a new action step to your Zap.
|
||||
- Choose CrewAI+ as your action app and Kickoff as the Action Event
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-3.png" alt="Zapier 5" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Connect your CrewAI Enterprise account.">
|
||||
|
||||
- Connect your CrewAI Enterprise account.
|
||||
- Select the appropriate Crew for your workflow.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-4.png" alt="Zapier 6" />
|
||||
</Frame>
|
||||
- Configure the inputs for the Crew using the data from the Slack message.
|
||||
</Step>
|
||||
|
||||
<Step title="Format the CrewAI Enterprise Output">
|
||||
|
||||
- Add another action step to format the text output from CrewAI Enterprise.
|
||||
- Use Zapier's formatting tools to convert the Markdown output to HTML.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-5.png" alt="Zapier 8" />
|
||||
</Frame>
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-6.png" alt="Zapier 9" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Send the Output via Email">
|
||||
- Add a final action step to send the formatted output via email.
|
||||
- Choose your preferred email service (e.g., Gmail, Outlook).
|
||||
- Configure the email details, including recipient, subject, and body.
|
||||
- Insert the formatted CrewAI Enterprise output into the email body.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-7.png" alt="Zapier 7" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Kick Off the crew from Slack">
|
||||
|
||||
- Enter the text in your Slack channel
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-7b.png" alt="Zapier 10" />
|
||||
</Frame>
|
||||
|
||||
- Select the 3 ellipsis button and then chose Push to Zapier
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-8.png" alt="Zapier 11" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Select the crew and then Push to Kick Off">
|
||||
|
||||
<Frame>
|
||||
<img src="/images/enterprise/zapier-9.png" alt="Zapier 12" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
|
||||
</Steps>
|
||||
|
||||
**Tips for Success**
|
||||
|
||||
- Ensure that your CrewAI Enterprise inputs are correctly mapped from the Slack message.
|
||||
- Test your Zap thoroughly before turning it on to catch any potential issues.
|
||||
- Consider adding error handling steps to manage potential failures in the workflow.
|
||||
|
||||
By following these steps, you'll have successfully integrated CrewAI Enterprise with Zapier, allowing for automated workflows triggered by Slack messages and resulting in email notifications with CrewAI Enterprise output.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to Integrate CrewAI Enterprise with HubSpot">
|
||||
This guide provides a step-by-step process to integrate CrewAI Enterprise with HubSpot, enabling you to initiate crews directly from HubSpot Workflows.
|
||||
|
||||
**Prerequisites**
|
||||
|
||||
- A CrewAI Enterprise account
|
||||
- A HubSpot account with the [HubSpot Workflows](https://knowledge.hubspot.com/workflows/create-workflows) feature
|
||||
|
||||
**Step-by-Step Guide**
|
||||
<Steps>
|
||||
<Step title="Connect your HubSpot account with CrewAI Enterprise">
|
||||
|
||||
- Log in to your `CrewAI Enterprise account > Integrations`
|
||||
- Select `HubSpot` from the list of available integrations
|
||||
- Choose the HubSpot account you want to integrate with CrewAI Enterprise
|
||||
- Follow the on-screen prompts to authorize CrewAI Enterprise access to your HubSpot account
|
||||
- A confirmation message will appear once HubSpot is successfully linked with CrewAI Enterprise
|
||||
|
||||
</Step>
|
||||
<Step title="Create a HubSpot Workflow">
|
||||
|
||||
- Log in to your `HubSpot account > Automations > Workflows > New workflow`
|
||||
- Select the workflow type that fits your needs (e.g., Start from scratch)
|
||||
- In the workflow builder, click the Plus (+) icon to add a new action.
|
||||
- Choose `Integrated apps > CrewAI > Kickoff a Crew`.
|
||||
- Select the Crew you want to initiate.
|
||||
- Click `Save` to add the action to your workflow
|
||||
<Frame>
|
||||
<img src="/images/enterprise/hubspot-workflow-1.png" alt="HubSpot Workflow 1" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
<Step title="Use Crew results with other actions">
|
||||
|
||||
- After the Kickoff a Crew step, click the Plus (+) icon to add a new action.
|
||||
- For example, to send an internal email notification, choose `Communications > Send internal email notification`
|
||||
- In the Body field, click `Insert data`, select `View properties or action outputs from > Action outputs > Crew Result` to include Crew data in the email
|
||||
<Frame>
|
||||
<img src="/images/enterprise/hubspot-workflow-2.png" alt="HubSpot Workflow 2" />
|
||||
</Frame>
|
||||
- Configure any additional actions as needed
|
||||
- Review your workflow steps to ensure everything is set up correctly
|
||||
- Activate the workflow
|
||||
<Frame>
|
||||
<img src="/images/enterprise/hubspot-workflow-3.png" alt="HubSpot Workflow 3" />
|
||||
</Frame>
|
||||
|
||||
</Step>
|
||||
</Steps>
|
||||
For more detailed information on available actions and customization options, refer to the [HubSpot Workflows Documentation](https://knowledge.hubspot.com/workflows/create-workflows).
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to connect Azure OpenAI with Crew Studio?">
|
||||
1. In Azure, go to `Azure AI Services > select your deployment > open Azure OpenAI Studio`.
|
||||
2. On the left menu, click `Deployments`. If you don’t have one, create a deployment with your desired model.
|
||||
3. Once created, select your deployment and locate the `Target URI` and `Key` on the right side of the page. Keep this page open, as you’ll need this information.
|
||||
<Frame>
|
||||
<img src="/images/enterprise/azure-openai-studio.png" alt="Azure OpenAI Studio" />
|
||||
</Frame>
|
||||
4. In another tab, open `CrewAI Enterprise > LLM Connections`. Name your LLM Connection, select Azure as the provider, and choose the same model you selected in Azure.
|
||||
5. On the same page, add environment variables from step 3:
|
||||
- One named `AZURE_DEPLOYMENT_TARGET_URL` (using the Target URI). The URL should look like this: https://your-deployment.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview
|
||||
- Another named `AZURE_API_KEY` (using the Key).
|
||||
6. Click `Add Connection` to save your LLM Connection.
|
||||
7. In `CrewAI Enterprise > Settings > Defaults > Crew Studio LLM Settings`, set the new LLM Connection and model as defaults.
|
||||
8. Ensure network access settings:
|
||||
- In Azure, go to `Azure OpenAI > select your deployment`.
|
||||
- Navigate to `Resource Management > Networking`.
|
||||
- Ensure that `Allow access from all networks` is enabled. If this setting is restricted, CrewAI may be blocked from accessing your Azure OpenAI endpoint.
|
||||
|
||||
You're all set! Crew Studio will now use your Azure OpenAI connection.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to use HITL?">
|
||||
Human-in-the-Loop (HITL) Instructions
|
||||
HITL is a powerful approach that combines artificial intelligence with human expertise to enhance decision-making and improve task outcomes. Follow these steps to implement HITL within CrewAI:
|
||||
<Steps>
|
||||
<Step title="Configure Your Task">
|
||||
Set up your task with human input enabled:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crew-human-input.png" alt="Crew Human Input" />
|
||||
</Frame>
|
||||
</Step>
|
||||
|
||||
<Step title="Provide Webhook URL">
|
||||
When kicking off your crew, include a webhook URL for human input:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crew-webhook-url.png" alt="Crew Webhook URL" />
|
||||
</Frame>
|
||||
</Step>
|
||||
|
||||
<Step title="Receive Webhook Notification">
|
||||
Once the crew completes the task requiring human input, you'll receive a webhook notification containing:
|
||||
- Execution ID
|
||||
- Task ID
|
||||
- Task output
|
||||
</Step>
|
||||
|
||||
<Step title="Review Task Output">
|
||||
The system will pause in the `Pending Human Input` state. Review the task output carefully.
|
||||
</Step>
|
||||
|
||||
<Step title="Submit Human Feedback">
|
||||
Call the resume endpoint of your crew with the following information:
|
||||
<Frame>
|
||||
<img src="/images/enterprise/crew-resume-endpoint.png" alt="Crew Resume Endpoint" />
|
||||
</Frame>
|
||||
<Warning>
|
||||
**Feedback Impact on Task Execution**:
|
||||
It's crucial to exercise care when providing feedback, as the entire feedback content will be incorporated as additional context for further task executions.
|
||||
</Warning>
|
||||
This means:
|
||||
- All information in your feedback becomes part of the task's context.
|
||||
- Irrelevant details may negatively influence it.
|
||||
- Concise, relevant feedback helps maintain task focus and efficiency.
|
||||
- Always review your feedback carefully before submission to ensure it contains only pertinent information that will positively guide the task's execution.
|
||||
</Step>
|
||||
<Step title="Handle Negative Feedback">
|
||||
If you provide negative feedback:
|
||||
- The crew will retry the task with added context from your feedback.
|
||||
- You'll receive another webhook notification for further review.
|
||||
- Repeat steps 4-6 until satisfied.
|
||||
</Step>
|
||||
|
||||
<Step title="Execution Continuation">
|
||||
When you submit positive feedback, the execution will proceed to the next steps.
|
||||
</Step>
|
||||
</Steps>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How to configure Salesforce with CrewAI Enterprise">
|
||||
**Salesforce Demo**
|
||||
|
||||
Salesforce is a leading customer relationship management (CRM) platform that helps businesses streamline their sales, service, and marketing operations.
|
||||
<Frame>
|
||||
<iframe width="100%" height="400" src="https://www.youtube.com/embed/oJunVqjjfu4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</Frame>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How can you control the maximum number of requests per minute that the entire crew can perform?">
|
||||
The `max_rpm` attribute sets the maximum number of requests per minute the crew can perform to avoid rate limits and will override individual agents' `max_rpm` settings if you set it.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
@@ -35,7 +35,8 @@ Let's get started building your first crew!
|
||||
Before starting, make sure you have:
|
||||
|
||||
1. Installed CrewAI following the [installation guide](/installation)
|
||||
2. Set up your OpenAI API key in your environment variables
|
||||
2. Set up your LLM API key in your environment, following the [LLM setup
|
||||
guide](/concepts/llms#setting-up-your-llm)
|
||||
3. Basic understanding of Python
|
||||
|
||||
## Step 1: Create a New CrewAI Project
|
||||
@@ -92,7 +93,8 @@ For our research crew, we'll create two agents:
|
||||
1. A **researcher** who excels at finding and organizing information
|
||||
2. An **analyst** who can interpret research findings and create insightful reports
|
||||
|
||||
Let's modify the `agents.yaml` file to define these specialized agents:
|
||||
Let's modify the `agents.yaml` file to define these specialized agents. Be sure
|
||||
to set `llm` to the provider you are using.
|
||||
|
||||
```yaml
|
||||
# src/research_crew/config/agents.yaml
|
||||
@@ -107,7 +109,7 @@ researcher:
|
||||
finding relevant information from various sources. You excel at
|
||||
organizing information in a clear and structured manner, making
|
||||
complex topics accessible to others.
|
||||
llm: openai/gpt-4o-mini
|
||||
llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude...
|
||||
|
||||
analyst:
|
||||
role: >
|
||||
@@ -120,7 +122,7 @@ analyst:
|
||||
and technical writing. You have a talent for identifying patterns
|
||||
and extracting meaningful insights from research data, then
|
||||
communicating those insights effectively through well-crafted reports.
|
||||
llm: openai/gpt-4o-mini
|
||||
llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude...
|
||||
```
|
||||
|
||||
Notice how each agent has a distinct role, goal, and backstory. These elements aren't just descriptive - they actively shape how the agent approaches its tasks. By crafting these carefully, you can create agents with specialized skills and perspectives that complement each other.
|
||||
@@ -282,12 +284,12 @@ This script prepares the environment, specifies our research topic, and kicks of
|
||||
|
||||
Create a `.env` file in your project root with your API keys:
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=your_openai_api_key
|
||||
```sh
|
||||
SERPER_API_KEY=your_serper_api_key
|
||||
# Add your provider's API key here too.
|
||||
```
|
||||
|
||||
You can get a Serper API key from [Serper.dev](https://serper.dev/).
|
||||
See the [LLM Setup guide](/concepts/llms#setting-up-your-llm) for details on configuring your provider of choice. You can get a Serper API key from [Serper.dev](https://serper.dev/).
|
||||
|
||||
## Step 8: Install Dependencies
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ Let's dive in and build your first flow!
|
||||
Before starting, make sure you have:
|
||||
|
||||
1. Installed CrewAI following the [installation guide](/installation)
|
||||
2. Set up your OpenAI API key in your environment variables
|
||||
2. Set up your LLM API key in your environment, following the [LLM setup
|
||||
guide](/concepts/llms#setting-up-your-llm)
|
||||
3. Basic understanding of Python
|
||||
|
||||
## Step 1: Create a New CrewAI Flow Project
|
||||
@@ -107,6 +108,8 @@ Now, let's modify the generated files for the content writer crew. We'll set up
|
||||
|
||||
1. First, update the agents configuration file to define our content creation team:
|
||||
|
||||
Remember to set `llm` to the provider you are using.
|
||||
|
||||
```yaml
|
||||
# src/guide_creator_flow/crews/content_crew/config/agents.yaml
|
||||
content_writer:
|
||||
@@ -119,7 +122,7 @@ content_writer:
|
||||
You are a talented educational writer with expertise in creating clear, engaging
|
||||
content. You have a gift for explaining complex concepts in accessible language
|
||||
and organizing information in a way that helps readers build their understanding.
|
||||
llm: openai/gpt-4o-mini
|
||||
llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude...
|
||||
|
||||
content_reviewer:
|
||||
role: >
|
||||
@@ -132,7 +135,7 @@ content_reviewer:
|
||||
content. You have an eye for detail, clarity, and coherence. You excel at
|
||||
improving content while maintaining the original author's voice and ensuring
|
||||
consistent quality across multiple sections.
|
||||
llm: openai/gpt-4o-mini
|
||||
llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude...
|
||||
```
|
||||
|
||||
These agent definitions establish the specialized roles and perspectives that will shape how our AI agents approach content creation. Notice how each agent has a distinct purpose and expertise.
|
||||
@@ -441,10 +444,15 @@ This is the power of flows - combining different types of processing (user inter
|
||||
|
||||
## Step 6: Set Up Your Environment Variables
|
||||
|
||||
Create a `.env` file in your project root with your API keys:
|
||||
Create a `.env` file in your project root with your API keys. See the [LLM setup
|
||||
guide](/concepts/llms#setting-up-your-llm) for details on configuring a provider.
|
||||
|
||||
```
|
||||
```sh .env
|
||||
OPENAI_API_KEY=your_openai_api_key
|
||||
# or
|
||||
GEMINI_API_KEY=your_gemini_api_key
|
||||
# or
|
||||
ANTHROPIC_API_KEY=your_anthropic_api_key
|
||||
```
|
||||
|
||||
## Step 7: Install Dependencies
|
||||
@@ -547,7 +555,10 @@ Let's break down the key components of flows to help you understand how to build
|
||||
Flows allow you to make direct calls to language models when you need simple, structured responses:
|
||||
|
||||
```python
|
||||
llm = LLM(model="openai/gpt-4o-mini", response_format=GuideOutline)
|
||||
llm = LLM(
|
||||
model="model-id-here", # gpt-4o, gemini-2.0-flash, anthropic/claude...
|
||||
response_format=GuideOutline
|
||||
)
|
||||
response = llm.call(messages=messages)
|
||||
```
|
||||
|
||||
|
||||
@@ -68,7 +68,13 @@ We'll create a CrewAI application where two agents collaborate to research and w
|
||||
```python
|
||||
from crewai import Agent, Crew, Process, Task
|
||||
from crewai_tools import SerperDevTool
|
||||
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
||||
from phoenix.otel import register
|
||||
|
||||
# setup monitoring for your crew
|
||||
tracer_provider = register(
|
||||
endpoint="http://localhost:6006/v1/traces")
|
||||
CrewAIInstrumentor().instrument(skip_dep_check=True, tracer_provider=tracer_provider)
|
||||
search_tool = SerperDevTool()
|
||||
|
||||
# Define your agents with roles and goals
|
||||
|
||||
BIN
docs/images/enterprise/activepieces-body.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
docs/images/enterprise/activepieces-email.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
docs/images/enterprise/activepieces-flow.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
docs/images/enterprise/activepieces-headers.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
docs/images/enterprise/activepieces-trigger.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
docs/images/enterprise/activepieces-webhook.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
docs/images/enterprise/azure-openai-studio.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/enterprise/crew-human-input.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
docs/images/enterprise/crew-resume-endpoint.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
docs/images/enterprise/crew-webhook-url.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
docs/images/enterprise/crewai-custom-gpt-1.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/images/enterprise/crewai-custom-gpt-2.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
docs/images/enterprise/crewai-enterprise-dashboard.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
docs/images/enterprise/customise-react-component-2.png
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
docs/images/enterprise/customise-react-component.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
docs/images/enterprise/dall-e-image.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
docs/images/enterprise/export-react-component.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
docs/images/enterprise/hubspot-workflow-1.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
docs/images/enterprise/hubspot-workflow-2.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
docs/images/enterprise/hubspot-workflow-3.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
docs/images/enterprise/kickoff-interface.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
docs/images/enterprise/kickoff-slack-crew-dropdown.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
docs/images/enterprise/kickoff-slack-crew-kickoff.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
docs/images/enterprise/kickoff-slack-crew-results.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
docs/images/enterprise/kickoff-slack-crew.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/images/enterprise/settings-page.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/images/enterprise/sfdcdemo-vini.mov
Normal file
BIN
docs/images/enterprise/slack-integration.png
Normal file
|
After Width: | Height: | Size: 212 KiB |
BIN
docs/images/enterprise/zapier-1.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
docs/images/enterprise/zapier-2.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/images/enterprise/zapier-3.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
docs/images/enterprise/zapier-4.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
docs/images/enterprise/zapier-5.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
docs/images/enterprise/zapier-6.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
docs/images/enterprise/zapier-7.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
docs/images/enterprise/zapier-7b.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
docs/images/enterprise/zapier-8.png
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
docs/images/enterprise/zapier-9.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
docs/images/releases/v01080.png
Normal file
|
After Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
BIN
docs/images/releases/v01170.png
Normal file
|
After Width: | Height: | Size: 2.7 MiB |
BIN
docs/images/releases/v01171.png
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
@@ -71,6 +71,10 @@ If you haven't installed `uv` yet, follow **step 1** to quickly get it set up on
|
||||
```
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
If you encounter the `chroma-hnswlib==0.7.6` build error (`fatal error C1083: Cannot open include file: 'float.h'`) on Windows, install (Visual Studio Build Tools)[https://visualstudio.microsoft.com/downloads/] with *Desktop development with C++*.
|
||||
</Warning>
|
||||
|
||||
- To verify that `crewai` is installed, run:
|
||||
```shell
|
||||
uv tool list
|
||||
|
||||
@@ -180,8 +180,9 @@ Follow the steps below to get Crewing! 🚣♂️
|
||||
</Step>
|
||||
<Step title="Set your environment variables">
|
||||
Before running your crew, make sure you have the following keys set as environment variables in your `.env` file:
|
||||
- An [OpenAI API key](https://platform.openai.com/account/api-keys) (or other LLM API key): `OPENAI_API_KEY=sk-...`
|
||||
- A [Serper.dev](https://serper.dev/) API key: `SERPER_API_KEY=YOUR_KEY_HERE`
|
||||
- The configuration for your choice of model, such as an API key. See the
|
||||
[LLM setup guide](/concepts/llms#setting-up-your-llm) to learn how to configure models from any provider.
|
||||
</Step>
|
||||
<Step title="Lock and install the dependencies">
|
||||
- Lock the dependencies and install them by using the CLI command:
|
||||
@@ -317,7 +318,7 @@ email_summarizer:
|
||||
Summarize emails into a concise and clear summary
|
||||
backstory: >
|
||||
You will create a 5 bullet point summary of the report
|
||||
llm: openai/gpt-4o
|
||||
llm: provider/model-id # Add your choice of model here
|
||||
```
|
||||
|
||||
<Tip>
|
||||
|
||||
@@ -22,7 +22,7 @@ streamlining the process of finding specific information within large document c
|
||||
Install the crewai_tools package by running the following command in your terminal:
|
||||
|
||||
```shell
|
||||
pip install 'crewai[tools]'
|
||||
uv pip install docx2txt 'crewai[tools]'
|
||||
```
|
||||
|
||||
## Example
|
||||
@@ -76,4 +76,4 @@ tool = DOCXSearchTool(
|
||||
),
|
||||
)
|
||||
)
|
||||
```
|
||||
```
|
||||
|
||||
@@ -8,10 +8,10 @@ icon: language
|
||||
|
||||
## Description
|
||||
|
||||
This tool is used to convert natural language to SQL queries. When passsed to the agent it will generate queries and then use them to interact with the database.
|
||||
This tool is used to convert natural language to SQL queries. When passed to the agent it will generate queries and then use them to interact with the database.
|
||||
|
||||
This enables multiple workflows like having an Agent to access the database fetch information based on the goal and then use the information to generate a response, report or any other output.
|
||||
Along with that proivdes the ability for the Agent to update the database based on its goal.
|
||||
Along with that provides the ability for the Agent to update the database based on its goal.
|
||||
|
||||
**Attention**: Make sure that the Agent has access to a Read-Replica or that is okay for the Agent to run insert/update queries on the database.
|
||||
|
||||
@@ -81,4 +81,4 @@ The Tool provides endless possibilities on the logic of the Agent and how it can
|
||||
|
||||
```md
|
||||
DB -> Agent -> ... -> Agent -> DB
|
||||
```
|
||||
```
|
||||
|
||||
@@ -143,12 +143,30 @@ config = {
|
||||
"config": {
|
||||
"model": "text-embedding-ada-002"
|
||||
}
|
||||
},
|
||||
"vectordb": {
|
||||
"provider": "elasticsearch",
|
||||
"config": {
|
||||
"collection_name": "my-collection",
|
||||
"cloud_id": "deployment-name:xxxx",
|
||||
"api_key": "your-key",
|
||||
"verify_certs": False
|
||||
}
|
||||
},
|
||||
"chunker": {
|
||||
"chunk_size": 400,
|
||||
"chunk_overlap": 100,
|
||||
"length_function": "len",
|
||||
"min_chunk_size": 0
|
||||
}
|
||||
}
|
||||
|
||||
rag_tool = RagTool(config=config, summarize=True)
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
The internal RAG tool utilizes the Embedchain adapter, allowing you to pass any configuration options that are supported by Embedchain.
|
||||
You can refer to the [Embedchain documentation](https://docs.embedchain.ai/components/introduction) for details.
|
||||
Make sure to review the configuration options available in the .yaml file.
|
||||
|
||||
## Conclusion
|
||||
The `RagTool` provides a powerful way to create and query knowledge bases from various data sources. By leveraging Retrieval-Augmented Generation, it enables agents to access and retrieve relevant information efficiently, enhancing their ability to provide accurate and contextually appropriate responses.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "crewai"
|
||||
version = "0.117.1"
|
||||
version = "0.119.0"
|
||||
description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10,<3.13"
|
||||
@@ -11,7 +11,7 @@ dependencies = [
|
||||
# Core Dependencies
|
||||
"pydantic>=2.4.2",
|
||||
"openai>=1.13.3",
|
||||
"litellm==1.67.2",
|
||||
"litellm==1.68.0",
|
||||
"instructor>=1.3.3",
|
||||
# Text Processing
|
||||
"pdfplumber>=0.11.4",
|
||||
@@ -45,7 +45,7 @@ Documentation = "https://docs.crewai.com"
|
||||
Repository = "https://github.com/crewAIInc/crewAI"
|
||||
|
||||
[project.optional-dependencies]
|
||||
tools = ["crewai-tools~=0.42.2"]
|
||||
tools = ["crewai-tools~=0.44.0"]
|
||||
embeddings = [
|
||||
"tiktoken~=0.7.0"
|
||||
]
|
||||
@@ -85,6 +85,8 @@ dev-dependencies = [
|
||||
"pytest-asyncio>=0.23.7",
|
||||
"pytest-subprocess>=1.5.2",
|
||||
"pytest-recording>=0.13.2",
|
||||
"pytest-randomly>=3.16.0",
|
||||
"pytest-timeout>=2.3.1",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -17,7 +17,7 @@ warnings.filterwarnings(
|
||||
category=UserWarning,
|
||||
module="pydantic.main",
|
||||
)
|
||||
__version__ = "0.117.1"
|
||||
__version__ = "0.119.0"
|
||||
__all__ = [
|
||||
"Agent",
|
||||
"Crew",
|
||||
|
||||
@@ -20,6 +20,7 @@ from crewai.tools.agent_tools.agent_tools import AgentTools
|
||||
from crewai.utilities import Converter, Prompts
|
||||
from crewai.utilities.agent_utils import (
|
||||
get_tool_names,
|
||||
load_agent_from_repository,
|
||||
parse_tools,
|
||||
render_text_description_and_args,
|
||||
)
|
||||
@@ -31,6 +32,14 @@ from crewai.utilities.events.agent_events import (
|
||||
AgentExecutionStartedEvent,
|
||||
)
|
||||
from crewai.utilities.events.crewai_event_bus import crewai_event_bus
|
||||
from crewai.utilities.events.knowledge_events import (
|
||||
KnowledgeQueryCompletedEvent,
|
||||
KnowledgeQueryFailedEvent,
|
||||
KnowledgeQueryStartedEvent,
|
||||
KnowledgeRetrievalCompletedEvent,
|
||||
KnowledgeRetrievalStartedEvent,
|
||||
KnowledgeSearchQueryFailedEvent,
|
||||
)
|
||||
from crewai.utilities.llm_utils import create_llm
|
||||
from crewai.utilities.token_counter_callback import TokenCalcHandler
|
||||
from crewai.utilities.training_handler import CrewTrainingHandler
|
||||
@@ -122,6 +131,20 @@ class Agent(BaseAgent):
|
||||
default=None,
|
||||
description="Knowledge context for the crew.",
|
||||
)
|
||||
knowledge_search_query: Optional[str] = Field(
|
||||
default=None,
|
||||
description="Knowledge search query for the agent dynamically generated by the agent.",
|
||||
)
|
||||
from_repository: Optional[str] = Field(
|
||||
default=None,
|
||||
description="The Agent's role to be used from your repository.",
|
||||
)
|
||||
|
||||
@model_validator(mode="before")
|
||||
def validate_from_repository(cls, v):
|
||||
if v is not None and (from_repository := v.get("from_repository")):
|
||||
return load_agent_from_repository(from_repository) | v
|
||||
return v
|
||||
|
||||
@model_validator(mode="after")
|
||||
def post_init_setup(self):
|
||||
@@ -185,7 +208,7 @@ class Agent(BaseAgent):
|
||||
self,
|
||||
task: Task,
|
||||
context: Optional[str] = None,
|
||||
tools: Optional[List[BaseTool]] = None
|
||||
tools: Optional[List[BaseTool]] = None,
|
||||
) -> str:
|
||||
"""Execute a task with the agent.
|
||||
|
||||
@@ -245,27 +268,65 @@ class Agent(BaseAgent):
|
||||
knowledge_config = (
|
||||
self.knowledge_config.model_dump() if self.knowledge_config else {}
|
||||
)
|
||||
if self.knowledge:
|
||||
agent_knowledge_snippets = self.knowledge.query(
|
||||
[task.prompt()], **knowledge_config
|
||||
)
|
||||
if agent_knowledge_snippets:
|
||||
self.agent_knowledge_context = extract_knowledge_context(
|
||||
agent_knowledge_snippets
|
||||
)
|
||||
if self.agent_knowledge_context:
|
||||
task_prompt += self.agent_knowledge_context
|
||||
|
||||
if self.crew:
|
||||
knowledge_snippets = self.crew.query_knowledge(
|
||||
[task.prompt()], **knowledge_config
|
||||
if self.knowledge:
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeRetrievalStartedEvent(
|
||||
agent=self,
|
||||
),
|
||||
)
|
||||
if knowledge_snippets:
|
||||
self.crew_knowledge_context = extract_knowledge_context(
|
||||
knowledge_snippets
|
||||
try:
|
||||
self.knowledge_search_query = self._get_knowledge_search_query(
|
||||
task_prompt
|
||||
)
|
||||
if self.knowledge_search_query:
|
||||
agent_knowledge_snippets = self.knowledge.query(
|
||||
[self.knowledge_search_query], **knowledge_config
|
||||
)
|
||||
if agent_knowledge_snippets:
|
||||
self.agent_knowledge_context = extract_knowledge_context(
|
||||
agent_knowledge_snippets
|
||||
)
|
||||
if self.agent_knowledge_context:
|
||||
task_prompt += self.agent_knowledge_context
|
||||
if self.crew:
|
||||
knowledge_snippets = self.crew.query_knowledge(
|
||||
[self.knowledge_search_query], **knowledge_config
|
||||
)
|
||||
if knowledge_snippets:
|
||||
self.crew_knowledge_context = extract_knowledge_context(
|
||||
knowledge_snippets
|
||||
)
|
||||
if self.crew_knowledge_context:
|
||||
task_prompt += self.crew_knowledge_context
|
||||
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeRetrievalCompletedEvent(
|
||||
query=self.knowledge_search_query,
|
||||
agent=self,
|
||||
retrieved_knowledge=(
|
||||
(self.agent_knowledge_context or "")
|
||||
+ (
|
||||
"\n"
|
||||
if self.agent_knowledge_context
|
||||
and self.crew_knowledge_context
|
||||
else ""
|
||||
)
|
||||
+ (self.crew_knowledge_context or "")
|
||||
),
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeSearchQueryFailedEvent(
|
||||
query=self.knowledge_search_query or "",
|
||||
agent=self,
|
||||
error=str(e),
|
||||
),
|
||||
)
|
||||
if self.crew_knowledge_context:
|
||||
task_prompt += self.crew_knowledge_context
|
||||
|
||||
tools = tools or self.tools or []
|
||||
self.create_agent_executor(tools=tools, task=task)
|
||||
@@ -288,12 +349,19 @@ class Agent(BaseAgent):
|
||||
|
||||
# Determine execution method based on timeout setting
|
||||
if self.max_execution_time is not None:
|
||||
if not isinstance(self.max_execution_time, int) or self.max_execution_time <= 0:
|
||||
raise ValueError("Max Execution time must be a positive integer greater than zero")
|
||||
result = self._execute_with_timeout(task_prompt, task, self.max_execution_time)
|
||||
if (
|
||||
not isinstance(self.max_execution_time, int)
|
||||
or self.max_execution_time <= 0
|
||||
):
|
||||
raise ValueError(
|
||||
"Max Execution time must be a positive integer greater than zero"
|
||||
)
|
||||
result = self._execute_with_timeout(
|
||||
task_prompt, task, self.max_execution_time
|
||||
)
|
||||
else:
|
||||
result = self._execute_without_timeout(task_prompt, task)
|
||||
|
||||
|
||||
except TimeoutError as e:
|
||||
# Propagate TimeoutError without retry
|
||||
crewai_event_bus.emit(
|
||||
@@ -345,54 +413,46 @@ class Agent(BaseAgent):
|
||||
)
|
||||
return result
|
||||
|
||||
def _execute_with_timeout(
|
||||
self,
|
||||
task_prompt: str,
|
||||
task: Task,
|
||||
timeout: int
|
||||
) -> str:
|
||||
def _execute_with_timeout(self, task_prompt: str, task: Task, timeout: int) -> str:
|
||||
"""Execute a task with a timeout.
|
||||
|
||||
|
||||
Args:
|
||||
task_prompt: The prompt to send to the agent.
|
||||
task: The task being executed.
|
||||
timeout: Maximum execution time in seconds.
|
||||
|
||||
|
||||
Returns:
|
||||
The output of the agent.
|
||||
|
||||
|
||||
Raises:
|
||||
TimeoutError: If execution exceeds the timeout.
|
||||
RuntimeError: If execution fails for other reasons.
|
||||
"""
|
||||
import concurrent.futures
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
future = executor.submit(
|
||||
self._execute_without_timeout,
|
||||
task_prompt=task_prompt,
|
||||
task=task
|
||||
self._execute_without_timeout, task_prompt=task_prompt, task=task
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
return future.result(timeout=timeout)
|
||||
except concurrent.futures.TimeoutError:
|
||||
future.cancel()
|
||||
raise TimeoutError(f"Task '{task.description}' execution timed out after {timeout} seconds. Consider increasing max_execution_time or optimizing the task.")
|
||||
raise TimeoutError(
|
||||
f"Task '{task.description}' execution timed out after {timeout} seconds. Consider increasing max_execution_time or optimizing the task."
|
||||
)
|
||||
except Exception as e:
|
||||
future.cancel()
|
||||
raise RuntimeError(f"Task execution failed: {str(e)}")
|
||||
|
||||
def _execute_without_timeout(
|
||||
self,
|
||||
task_prompt: str,
|
||||
task: Task
|
||||
) -> str:
|
||||
def _execute_without_timeout(self, task_prompt: str, task: Task) -> str:
|
||||
"""Execute a task without a timeout.
|
||||
|
||||
|
||||
Args:
|
||||
task_prompt: The prompt to send to the agent.
|
||||
task: The task being executed.
|
||||
|
||||
|
||||
Returns:
|
||||
The output of the agent.
|
||||
"""
|
||||
@@ -560,6 +620,61 @@ class Agent(BaseAgent):
|
||||
def set_fingerprint(self, fingerprint: Fingerprint):
|
||||
self.security_config.fingerprint = fingerprint
|
||||
|
||||
def _get_knowledge_search_query(self, task_prompt: str) -> str | None:
|
||||
"""Generate a search query for the knowledge base based on the task description."""
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeQueryStartedEvent(
|
||||
task_prompt=task_prompt,
|
||||
agent=self,
|
||||
),
|
||||
)
|
||||
query = self.i18n.slice("knowledge_search_query").format(
|
||||
task_prompt=task_prompt
|
||||
)
|
||||
rewriter_prompt = self.i18n.slice("knowledge_search_query_system_prompt")
|
||||
if not isinstance(self.llm, BaseLLM):
|
||||
self._logger.log(
|
||||
"warning",
|
||||
f"Knowledge search query failed: LLM for agent '{self.role}' is not an instance of BaseLLM",
|
||||
)
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeQueryFailedEvent(
|
||||
agent=self,
|
||||
error="LLM is not compatible with knowledge search queries",
|
||||
),
|
||||
)
|
||||
return None
|
||||
|
||||
try:
|
||||
rewritten_query = self.llm.call(
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
"content": rewriter_prompt,
|
||||
},
|
||||
{"role": "user", "content": query},
|
||||
]
|
||||
)
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeQueryCompletedEvent(
|
||||
query=query,
|
||||
agent=self,
|
||||
),
|
||||
)
|
||||
return rewritten_query
|
||||
except Exception as e:
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeQueryFailedEvent(
|
||||
agent=self,
|
||||
error=str(e),
|
||||
),
|
||||
)
|
||||
return None
|
||||
|
||||
def kickoff(
|
||||
self,
|
||||
messages: Union[str, List[Dict[str, str]]],
|
||||
|
||||
1
src/crewai/agents/agent_adapters/langgraph/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""LangGraph adapter for crewAI."""
|
||||
@@ -0,0 +1 @@
|
||||
"""OpenAI agent adapters for crewAI."""
|
||||
@@ -5,5 +5,5 @@ def get_auth_token() -> str:
|
||||
"""Get the authentication token."""
|
||||
access_token = TokenManager().get_token()
|
||||
if not access_token:
|
||||
raise Exception()
|
||||
raise Exception("No token found, make sure you are logged in")
|
||||
return access_token
|
||||
|
||||
@@ -13,7 +13,7 @@ ENV_VARS = {
|
||||
],
|
||||
"gemini": [
|
||||
{
|
||||
"prompt": "Enter your GEMINI API key (press Enter to skip)",
|
||||
"prompt": "Enter your GEMINI API key from https://ai.dev/apikey (press Enter to skip)",
|
||||
"key_name": "GEMINI_API_KEY",
|
||||
}
|
||||
],
|
||||
|
||||
@@ -4,7 +4,7 @@ import click
|
||||
|
||||
|
||||
# Be mindful about changing this.
|
||||
# on some enviorments we don't use this command but instead uv sync directly
|
||||
# on some environments we don't use this command but instead uv sync directly
|
||||
# so if you expect this to support more things you will need to replicate it there
|
||||
# ask @joaomdmoura if you are unsure
|
||||
def install_crew(proxy_options: list[str]) -> None:
|
||||
|
||||
@@ -14,6 +14,7 @@ class PlusAPI:
|
||||
|
||||
TOOLS_RESOURCE = "/crewai_plus/api/v1/tools"
|
||||
CREWS_RESOURCE = "/crewai_plus/api/v1/crews"
|
||||
AGENTS_RESOURCE = "/crewai_plus/api/v1/agents"
|
||||
|
||||
def __init__(self, api_key: str) -> None:
|
||||
self.api_key = api_key
|
||||
@@ -37,6 +38,9 @@ class PlusAPI:
|
||||
def get_tool(self, handle: str):
|
||||
return self._make_request("GET", f"{self.TOOLS_RESOURCE}/{handle}")
|
||||
|
||||
def get_agent(self, handle: str):
|
||||
return self._make_request("GET", f"{self.AGENTS_RESOURCE}/{handle}")
|
||||
|
||||
def publish_tool(
|
||||
self,
|
||||
handle: str,
|
||||
|
||||
@@ -2,7 +2,7 @@ import subprocess
|
||||
|
||||
import click
|
||||
|
||||
from crewai.cli.utils import get_crew
|
||||
from crewai.cli.utils import get_crews
|
||||
|
||||
|
||||
def reset_memories_command(
|
||||
@@ -26,35 +26,47 @@ def reset_memories_command(
|
||||
"""
|
||||
|
||||
try:
|
||||
crew = get_crew()
|
||||
if not crew:
|
||||
raise ValueError("No crew found.")
|
||||
if all:
|
||||
crew.reset_memories(command_type="all")
|
||||
click.echo("All memories have been reset.")
|
||||
return
|
||||
|
||||
if not any([long, short, entity, kickoff_outputs, knowledge]):
|
||||
if not any([long, short, entity, kickoff_outputs, knowledge, all]):
|
||||
click.echo(
|
||||
"No memory type specified. Please specify at least one type to reset."
|
||||
)
|
||||
return
|
||||
|
||||
if long:
|
||||
crew.reset_memories(command_type="long")
|
||||
click.echo("Long term memory has been reset.")
|
||||
if short:
|
||||
crew.reset_memories(command_type="short")
|
||||
click.echo("Short term memory has been reset.")
|
||||
if entity:
|
||||
crew.reset_memories(command_type="entity")
|
||||
click.echo("Entity memory has been reset.")
|
||||
if kickoff_outputs:
|
||||
crew.reset_memories(command_type="kickoff_outputs")
|
||||
click.echo("Latest Kickoff outputs stored has been reset.")
|
||||
if knowledge:
|
||||
crew.reset_memories(command_type="knowledge")
|
||||
click.echo("Knowledge has been reset.")
|
||||
crews = get_crews()
|
||||
if not crews:
|
||||
raise ValueError("No crew found.")
|
||||
for crew in crews:
|
||||
if all:
|
||||
crew.reset_memories(command_type="all")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Reset memories command has been completed."
|
||||
)
|
||||
continue
|
||||
if long:
|
||||
crew.reset_memories(command_type="long")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Long term memory has been reset."
|
||||
)
|
||||
if short:
|
||||
crew.reset_memories(command_type="short")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Short term memory has been reset."
|
||||
)
|
||||
if entity:
|
||||
crew.reset_memories(command_type="entity")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Entity memory has been reset."
|
||||
)
|
||||
if kickoff_outputs:
|
||||
crew.reset_memories(command_type="kickoff_outputs")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Latest Kickoff outputs stored has been reset."
|
||||
)
|
||||
if knowledge:
|
||||
crew.reset_memories(command_type="knowledge")
|
||||
click.echo(
|
||||
f"[Crew ({crew.name if crew.name else crew.id})] Knowledge has been reset."
|
||||
)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
click.echo(f"An error occurred while resetting the memories: {e}", err=True)
|
||||
|
||||
@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
|
||||
authors = [{ name = "Your Name", email = "you@example.com" }]
|
||||
requires-python = ">=3.10,<3.13"
|
||||
dependencies = [
|
||||
"crewai[tools]>=0.117.1,<1.0.0"
|
||||
"crewai[tools]>=0.119.0,<1.0.0"
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Poem crew template."""
|
||||
@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
|
||||
authors = [{ name = "Your Name", email = "you@example.com" }]
|
||||
requires-python = ">=3.10,<3.13"
|
||||
dependencies = [
|
||||
"crewai[tools]>=0.117.1,<1.0.0",
|
||||
"crewai[tools]>=0.119.0,<1.0.0",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -5,7 +5,7 @@ description = "Power up your crews with {{folder_name}}"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10,<3.13"
|
||||
dependencies = [
|
||||
"crewai[tools]>=0.117.1"
|
||||
"crewai[tools]>=0.119.0"
|
||||
]
|
||||
|
||||
[tool.crewai]
|
||||
|
||||
@@ -2,7 +2,8 @@ import os
|
||||
import shutil
|
||||
import sys
|
||||
from functools import reduce
|
||||
from typing import Any, Dict, List
|
||||
from inspect import isfunction, ismethod
|
||||
from typing import Any, Dict, List, get_type_hints
|
||||
|
||||
import click
|
||||
import tomli
|
||||
@@ -10,6 +11,7 @@ from rich.console import Console
|
||||
|
||||
from crewai.cli.constants import ENV_VARS
|
||||
from crewai.crew import Crew
|
||||
from crewai.flow import Flow
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
import tomllib
|
||||
@@ -250,11 +252,11 @@ def write_env_file(folder_path, env_vars):
|
||||
file.write(f"{key}={value}\n")
|
||||
|
||||
|
||||
def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None:
|
||||
"""Get the crew instance from the crew.py file."""
|
||||
def get_crews(crew_path: str = "crew.py", require: bool = False) -> list[Crew]:
|
||||
"""Get the crew instances from the a file."""
|
||||
crew_instances = []
|
||||
try:
|
||||
import importlib.util
|
||||
import os
|
||||
|
||||
for root, _, files in os.walk("."):
|
||||
if crew_path in files:
|
||||
@@ -271,12 +273,10 @@ def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None:
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
for attr_name in dir(module):
|
||||
attr = getattr(module, attr_name)
|
||||
try:
|
||||
if callable(attr) and hasattr(attr, "crew"):
|
||||
crew_instance = attr().crew()
|
||||
return crew_instance
|
||||
module_attr = getattr(module, attr_name)
|
||||
|
||||
try:
|
||||
crew_instances.extend(fetch_crews(module_attr))
|
||||
except Exception as e:
|
||||
print(f"Error processing attribute {attr_name}: {e}")
|
||||
continue
|
||||
@@ -286,7 +286,6 @@ def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None:
|
||||
import traceback
|
||||
|
||||
print(f"Traceback: {traceback.format_exc()}")
|
||||
|
||||
except (ImportError, AttributeError) as e:
|
||||
if require:
|
||||
console.print(
|
||||
@@ -300,7 +299,6 @@ def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None:
|
||||
if require:
|
||||
console.print("No valid Crew instance found in crew.py", style="bold red")
|
||||
raise SystemExit
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
if require:
|
||||
@@ -308,4 +306,36 @@ def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None:
|
||||
f"Unexpected error while loading crew: {str(e)}", style="bold red"
|
||||
)
|
||||
raise SystemExit
|
||||
return crew_instances
|
||||
|
||||
|
||||
def get_crew_instance(module_attr) -> Crew | None:
|
||||
if (
|
||||
callable(module_attr)
|
||||
and hasattr(module_attr, "is_crew_class")
|
||||
and module_attr.is_crew_class
|
||||
):
|
||||
return module_attr().crew()
|
||||
if (ismethod(module_attr) or isfunction(module_attr)) and get_type_hints(
|
||||
module_attr
|
||||
).get("return") is Crew:
|
||||
return module_attr()
|
||||
elif isinstance(module_attr, Crew):
|
||||
return module_attr
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def fetch_crews(module_attr) -> list[Crew]:
|
||||
crew_instances: list[Crew] = []
|
||||
|
||||
if crew_instance := get_crew_instance(module_attr):
|
||||
crew_instances.append(crew_instance)
|
||||
|
||||
if isinstance(module_attr, type) and issubclass(module_attr, Flow):
|
||||
instance = module_attr()
|
||||
for attr_name in dir(instance):
|
||||
attr = getattr(instance, attr_name)
|
||||
if crew_instance := get_crew_instance(attr):
|
||||
crew_instances.append(crew_instance)
|
||||
return crew_instances
|
||||
|
||||
@@ -6,7 +6,17 @@ import warnings
|
||||
from concurrent.futures import Future
|
||||
from copy import copy as shallow_copy
|
||||
from hashlib import md5
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, cast
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
Tuple,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
|
||||
from pydantic import (
|
||||
UUID4,
|
||||
@@ -24,6 +34,7 @@ from crewai.agent import Agent
|
||||
from crewai.agents.agent_builder.base_agent import BaseAgent
|
||||
from crewai.agents.cache import CacheHandler
|
||||
from crewai.crews.crew_output import CrewOutput
|
||||
from crewai.flow.flow_trackable import FlowTrackable
|
||||
from crewai.knowledge.knowledge import Knowledge
|
||||
from crewai.knowledge.source.base_knowledge_source import BaseKnowledgeSource
|
||||
from crewai.llm import LLM, BaseLLM
|
||||
@@ -41,7 +52,7 @@ from crewai.tools.agent_tools.agent_tools import AgentTools
|
||||
from crewai.tools.base_tool import BaseTool, Tool
|
||||
from crewai.types.usage_metrics import UsageMetrics
|
||||
from crewai.utilities import I18N, FileHandler, Logger, RPMController
|
||||
from crewai.utilities.constants import TRAINING_DATA_FILE
|
||||
from crewai.utilities.constants import NOT_SPECIFIED, TRAINING_DATA_FILE
|
||||
from crewai.utilities.evaluators.crew_evaluator_handler import CrewEvaluator
|
||||
from crewai.utilities.evaluators.task_evaluator import TaskEvaluator
|
||||
from crewai.utilities.events.crew_events import (
|
||||
@@ -69,7 +80,7 @@ from crewai.utilities.training_handler import CrewTrainingHandler
|
||||
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")
|
||||
|
||||
|
||||
class Crew(BaseModel):
|
||||
class Crew(FlowTrackable, BaseModel):
|
||||
"""
|
||||
Represents a group of agents, defining how they should collaborate and the tasks they should perform.
|
||||
|
||||
@@ -304,7 +315,9 @@ class Crew(BaseModel):
|
||||
"""Initialize private memory attributes."""
|
||||
self._external_memory = (
|
||||
# External memory doesn’t support a default value since it was designed to be managed entirely externally
|
||||
self.external_memory.set_crew(self) if self.external_memory else None
|
||||
self.external_memory.set_crew(self)
|
||||
if self.external_memory
|
||||
else None
|
||||
)
|
||||
|
||||
self._long_term_memory = self.long_term_memory
|
||||
@@ -333,6 +346,7 @@ class Crew(BaseModel):
|
||||
embedder=self.embedder,
|
||||
collection_name="crew",
|
||||
)
|
||||
self.knowledge.add_sources()
|
||||
|
||||
except Exception as e:
|
||||
self._logger.log(
|
||||
@@ -464,7 +478,7 @@ class Crew(BaseModel):
|
||||
separated by a synchronous task.
|
||||
"""
|
||||
for i, task in enumerate(self.tasks):
|
||||
if task.async_execution and task.context:
|
||||
if task.async_execution and isinstance(task.context, list):
|
||||
for context_task in task.context:
|
||||
if context_task.async_execution:
|
||||
for j in range(i - 1, -1, -1):
|
||||
@@ -482,7 +496,7 @@ class Crew(BaseModel):
|
||||
task_indices = {id(task): i for i, task in enumerate(self.tasks)}
|
||||
|
||||
for task in self.tasks:
|
||||
if task.context:
|
||||
if isinstance(task.context, list):
|
||||
for context_task in task.context:
|
||||
if id(context_task) not in task_indices:
|
||||
continue # Skip context tasks not in the main tasks list
|
||||
@@ -1020,11 +1034,14 @@ class Crew(BaseModel):
|
||||
)
|
||||
return cast(List[BaseTool], tools)
|
||||
|
||||
def _get_context(self, task: Task, task_outputs: List[TaskOutput]):
|
||||
def _get_context(self, task: Task, task_outputs: List[TaskOutput]) -> str:
|
||||
if not task.context:
|
||||
return ""
|
||||
|
||||
context = (
|
||||
aggregate_raw_outputs_from_tasks(task.context)
|
||||
if task.context
|
||||
else aggregate_raw_outputs_from_task_outputs(task_outputs)
|
||||
aggregate_raw_outputs_from_task_outputs(task_outputs)
|
||||
if task.context is NOT_SPECIFIED
|
||||
else aggregate_raw_outputs_from_tasks(task.context)
|
||||
)
|
||||
return context
|
||||
|
||||
@@ -1212,7 +1229,7 @@ class Crew(BaseModel):
|
||||
task_mapping[task.key] = cloned_task
|
||||
|
||||
for cloned_task, original_task in zip(cloned_tasks, self.tasks):
|
||||
if original_task.context:
|
||||
if isinstance(original_task.context, list):
|
||||
cloned_context = [
|
||||
task_mapping[context_task.key]
|
||||
for context_task in original_task.context
|
||||
@@ -1369,8 +1386,6 @@ class Crew(BaseModel):
|
||||
else:
|
||||
self._reset_specific_memory(command_type)
|
||||
|
||||
self._logger.log("info", f"{command_type} memory has been reset")
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"Failed to reset {command_type} memory: {str(e)}"
|
||||
self._logger.log("error", error_msg)
|
||||
@@ -1391,8 +1406,14 @@ class Crew(BaseModel):
|
||||
if system is not None:
|
||||
try:
|
||||
system.reset()
|
||||
self._logger.log(
|
||||
"info",
|
||||
f"[Crew ({self.name if self.name else self.id})] {name} memory has been reset",
|
||||
)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to reset {name} memory") from e
|
||||
raise RuntimeError(
|
||||
f"[Crew ({self.name if self.name else self.id})] Failed to reset {name} memory: {str(e)}"
|
||||
) from e
|
||||
|
||||
def _reset_specific_memory(self, memory_type: str) -> None:
|
||||
"""Reset a specific memory system.
|
||||
@@ -1421,5 +1442,11 @@ class Crew(BaseModel):
|
||||
|
||||
try:
|
||||
memory_system.reset()
|
||||
self._logger.log(
|
||||
"info",
|
||||
f"[Crew ({self.name if self.name else self.id})] {name} memory has been reset",
|
||||
)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to reset {name} memory") from e
|
||||
raise RuntimeError(
|
||||
f"[Crew ({self.name if self.name else self.id})] Failed to reset {name} memory: {str(e)}"
|
||||
) from e
|
||||
|
||||
44
src/crewai/flow/flow_trackable.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import inspect
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field, InstanceOf, model_validator
|
||||
|
||||
from crewai.flow import Flow
|
||||
|
||||
|
||||
class FlowTrackable(BaseModel):
|
||||
"""Mixin that tracks the Flow instance that instantiated the object, e.g. a
|
||||
Flow instance that created a Crew or Agent.
|
||||
|
||||
Automatically finds and stores a reference to the parent Flow instance by
|
||||
inspecting the call stack.
|
||||
"""
|
||||
|
||||
parent_flow: Optional[InstanceOf[Flow]] = Field(
|
||||
default=None,
|
||||
description="The parent flow of the instance, if it was created inside a flow.",
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _set_parent_flow(self, max_depth: int = 5) -> "FlowTrackable":
|
||||
frame = inspect.currentframe()
|
||||
|
||||
try:
|
||||
if frame is None:
|
||||
return self
|
||||
|
||||
frame = frame.f_back
|
||||
for _ in range(max_depth):
|
||||
if frame is None:
|
||||
break
|
||||
|
||||
candidate = frame.f_locals.get("self")
|
||||
if isinstance(candidate, Flow):
|
||||
self.parent_flow = candidate
|
||||
break
|
||||
|
||||
frame = frame.f_back
|
||||
finally:
|
||||
del frame
|
||||
|
||||
return self
|
||||
@@ -41,7 +41,6 @@ class Knowledge(BaseModel):
|
||||
)
|
||||
self.sources = sources
|
||||
self.storage.initialize_knowledge_storage()
|
||||
self._add_sources()
|
||||
|
||||
def query(
|
||||
self, query: List[str], results_limit: int = 3, score_threshold: float = 0.35
|
||||
@@ -63,7 +62,7 @@ class Knowledge(BaseModel):
|
||||
)
|
||||
return results
|
||||
|
||||
def _add_sources(self):
|
||||
def add_sources(self):
|
||||
try:
|
||||
for source in self.sources:
|
||||
source.storage = self.storage
|
||||
|
||||
1
src/crewai/knowledge/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Knowledge utilities for crewAI."""
|
||||
@@ -13,6 +13,7 @@ from crewai.agents.parser import (
|
||||
AgentFinish,
|
||||
OutputParserException,
|
||||
)
|
||||
from crewai.flow.flow_trackable import FlowTrackable
|
||||
from crewai.llm import LLM
|
||||
from crewai.tools.base_tool import BaseTool
|
||||
from crewai.tools.structured_tool import CrewStructuredTool
|
||||
@@ -80,7 +81,7 @@ class LiteAgentOutput(BaseModel):
|
||||
return self.raw
|
||||
|
||||
|
||||
class LiteAgent(BaseModel):
|
||||
class LiteAgent(FlowTrackable, BaseModel):
|
||||
"""
|
||||
A lightweight agent that can process messages and use tools.
|
||||
|
||||
@@ -162,7 +163,7 @@ class LiteAgent(BaseModel):
|
||||
_messages: List[Dict[str, str]] = PrivateAttr(default_factory=list)
|
||||
_iterations: int = PrivateAttr(default=0)
|
||||
_printer: Printer = PrivateAttr(default_factory=Printer)
|
||||
|
||||
|
||||
@model_validator(mode="after")
|
||||
def setup_llm(self):
|
||||
"""Set up the LLM and other components after initialization."""
|
||||
|
||||
@@ -5,8 +5,7 @@ import sys
|
||||
import threading
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager
|
||||
from types import SimpleNamespace
|
||||
from contextlib import contextmanager, redirect_stderr, redirect_stdout
|
||||
from typing import (
|
||||
Any,
|
||||
DefaultDict,
|
||||
@@ -31,7 +30,6 @@ from crewai.utilities.events.llm_events import (
|
||||
LLMCallType,
|
||||
LLMStreamChunkEvent,
|
||||
)
|
||||
from crewai.utilities.events.tool_usage_events import ToolExecutionErrorEvent
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", UserWarning)
|
||||
@@ -45,6 +43,9 @@ with warnings.catch_warnings():
|
||||
from litellm.utils import supports_response_schema
|
||||
|
||||
|
||||
import io
|
||||
from typing import TextIO
|
||||
|
||||
from crewai.llms.base_llm import BaseLLM
|
||||
from crewai.utilities.events import crewai_event_bus
|
||||
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
||||
@@ -54,12 +55,17 @@ from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class FilteredStream:
|
||||
def __init__(self, original_stream):
|
||||
class FilteredStream(io.TextIOBase):
|
||||
_lock = None
|
||||
|
||||
def __init__(self, original_stream: TextIO):
|
||||
self._original_stream = original_stream
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def write(self, s) -> int:
|
||||
def write(self, s: str) -> int:
|
||||
if not self._lock:
|
||||
self._lock = threading.Lock()
|
||||
|
||||
with self._lock:
|
||||
# Filter out extraneous messages from LiteLLM
|
||||
if (
|
||||
@@ -214,15 +220,11 @@ def suppress_warnings():
|
||||
)
|
||||
|
||||
# Redirect stdout and stderr
|
||||
old_stdout = sys.stdout
|
||||
old_stderr = sys.stderr
|
||||
sys.stdout = FilteredStream(old_stdout)
|
||||
sys.stderr = FilteredStream(old_stderr)
|
||||
try:
|
||||
with (
|
||||
redirect_stdout(FilteredStream(sys.stdout)),
|
||||
redirect_stderr(FilteredStream(sys.stderr)),
|
||||
):
|
||||
yield
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
sys.stderr = old_stderr
|
||||
|
||||
|
||||
class Delta(TypedDict):
|
||||
@@ -483,6 +485,7 @@ class LLM(BaseLLM):
|
||||
full_response += chunk_content
|
||||
|
||||
# Emit the chunk event
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMStreamChunkEvent(chunk=chunk_content),
|
||||
@@ -611,6 +614,7 @@ class LLM(BaseLLM):
|
||||
return full_response
|
||||
|
||||
# Emit failed event and re-raise the exception
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMCallFailedEvent(error=str(e)),
|
||||
@@ -633,7 +637,7 @@ class LLM(BaseLLM):
|
||||
current_tool_accumulator.function.arguments += (
|
||||
tool_call.function.arguments
|
||||
)
|
||||
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMStreamChunkEvent(
|
||||
@@ -806,6 +810,7 @@ class LLM(BaseLLM):
|
||||
function_name, lambda: None
|
||||
) # Ensure fn is always a callable
|
||||
logging.error(f"Error executing function '{function_name}': {e}")
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMCallFailedEvent(error=f"Tool execution error: {str(e)}"),
|
||||
@@ -843,6 +848,7 @@ class LLM(BaseLLM):
|
||||
LLMContextLengthExceededException: If input exceeds model's context limit
|
||||
"""
|
||||
# --- 1) Emit call started event
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMCallStartedEvent(
|
||||
@@ -891,6 +897,7 @@ class LLM(BaseLLM):
|
||||
# whether to summarize the content or abort based on the respect_context_window flag
|
||||
raise
|
||||
except Exception as e:
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMCallFailedEvent(error=str(e)),
|
||||
@@ -905,6 +912,7 @@ class LLM(BaseLLM):
|
||||
response (str): The response from the LLM call.
|
||||
call_type (str): The type of call, either "tool_call" or "llm_call".
|
||||
"""
|
||||
assert hasattr(crewai_event_bus, "emit")
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=LLMCallCompletedEvent(response=response, call_type=call_type),
|
||||
|
||||
1
src/crewai/llms/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""LLM implementations for crewAI."""
|
||||
1
src/crewai/llms/third_party/__init__.py
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"""Third-party LLM implementations for crewAI."""
|
||||
1
src/crewai/memory/storage/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Memory storage implementations for crewAI."""
|
||||
@@ -8,8 +8,6 @@ from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
|
||||
T = TypeVar("T", bound=type)
|
||||
|
||||
"""Base decorator for creating crew classes with configuration and function management."""
|
||||
@@ -248,6 +246,9 @@ def CrewBase(cls: T) -> T:
|
||||
callback_functions[callback]() for callback in callbacks
|
||||
]
|
||||
|
||||
if guardrail := task_info.get("guardrail"):
|
||||
self.tasks_config[task_name]["guardrail"] = guardrail
|
||||
|
||||
# Include base class (qual)name in the wrapper class (qual)name.
|
||||
WrappedClass.__name__ = CrewBase.__name__ + "(" + cls.__name__ + ")"
|
||||
WrappedClass.__qualname__ = CrewBase.__qualname__ + "(" + cls.__name__ + ")"
|
||||
|
||||
@@ -2,7 +2,6 @@ import datetime
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import threading
|
||||
import uuid
|
||||
from concurrent.futures import Future
|
||||
@@ -41,6 +40,7 @@ from crewai.tasks.output_format import OutputFormat
|
||||
from crewai.tasks.task_output import TaskOutput
|
||||
from crewai.tools.base_tool import BaseTool
|
||||
from crewai.utilities.config import process_config
|
||||
from crewai.utilities.constants import NOT_SPECIFIED
|
||||
from crewai.utilities.converter import Converter, convert_to_model
|
||||
from crewai.utilities.events import (
|
||||
TaskCompletedEvent,
|
||||
@@ -97,7 +97,7 @@ class Task(BaseModel):
|
||||
)
|
||||
context: Optional[List["Task"]] = Field(
|
||||
description="Other tasks that will have their output used as context for this task.",
|
||||
default=None,
|
||||
default=NOT_SPECIFIED,
|
||||
)
|
||||
async_execution: Optional[bool] = Field(
|
||||
description="Whether the task should be executed asynchronously or not.",
|
||||
@@ -140,9 +140,9 @@ class Task(BaseModel):
|
||||
default=None,
|
||||
)
|
||||
processed_by_agents: Set[str] = Field(default_factory=set)
|
||||
guardrail: Optional[Callable[[TaskOutput], Tuple[bool, Any]]] = Field(
|
||||
guardrail: Optional[Union[Callable[[TaskOutput], Tuple[bool, Any]], str]] = Field(
|
||||
default=None,
|
||||
description="Function to validate task output before proceeding to next task",
|
||||
description="Function or string description of a guardrail to validate task output before proceeding to next task",
|
||||
)
|
||||
max_retries: int = Field(
|
||||
default=3, description="Maximum number of retries when guardrail fails"
|
||||
@@ -157,8 +157,12 @@ class Task(BaseModel):
|
||||
|
||||
@field_validator("guardrail")
|
||||
@classmethod
|
||||
def validate_guardrail_function(cls, v: Optional[Callable]) -> Optional[Callable]:
|
||||
"""Validate that the guardrail function has the correct signature and behavior.
|
||||
def validate_guardrail_function(
|
||||
cls, v: Optional[str | Callable]
|
||||
) -> Optional[str | Callable]:
|
||||
"""
|
||||
If v is a callable, validate that the guardrail function has the correct signature and behavior.
|
||||
If v is a string, return it as is.
|
||||
|
||||
While type hints provide static checking, this validator ensures runtime safety by:
|
||||
1. Verifying the function accepts exactly one parameter (the TaskOutput)
|
||||
@@ -171,16 +175,16 @@ class Task(BaseModel):
|
||||
- Clear error messages help users debug guardrail implementation issues
|
||||
|
||||
Args:
|
||||
v: The guardrail function to validate
|
||||
v: The guardrail function to validate or a string describing the guardrail task
|
||||
|
||||
Returns:
|
||||
The validated guardrail function
|
||||
The validated guardrail function or a string describing the guardrail task
|
||||
|
||||
Raises:
|
||||
ValueError: If the function signature is invalid or return annotation
|
||||
doesn't match Tuple[bool, Any]
|
||||
"""
|
||||
if v is not None:
|
||||
if v is not None and callable(v):
|
||||
sig = inspect.signature(v)
|
||||
positional_args = [
|
||||
param
|
||||
@@ -211,6 +215,7 @@ class Task(BaseModel):
|
||||
)
|
||||
return v
|
||||
|
||||
_guardrail: Optional[Callable] = PrivateAttr(default=None)
|
||||
_original_description: Optional[str] = PrivateAttr(default=None)
|
||||
_original_expected_output: Optional[str] = PrivateAttr(default=None)
|
||||
_original_output_file: Optional[str] = PrivateAttr(default=None)
|
||||
@@ -231,6 +236,20 @@ class Task(BaseModel):
|
||||
)
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def ensure_guardrail_is_callable(self) -> "Task":
|
||||
if callable(self.guardrail):
|
||||
self._guardrail = self.guardrail
|
||||
elif isinstance(self.guardrail, str):
|
||||
from crewai.tasks.llm_guardrail import LLMGuardrail
|
||||
|
||||
assert self.agent is not None
|
||||
self._guardrail = LLMGuardrail(
|
||||
description=self.guardrail, llm=self.agent.llm
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
@field_validator("id", mode="before")
|
||||
@classmethod
|
||||
def _deny_user_set_id(cls, v: Optional[UUID4]) -> None:
|
||||
@@ -407,10 +426,8 @@ class Task(BaseModel):
|
||||
output_format=self._get_output_format(),
|
||||
)
|
||||
|
||||
if self.guardrail:
|
||||
guardrail_result = GuardrailResult.from_tuple(
|
||||
self.guardrail(task_output)
|
||||
)
|
||||
if self._guardrail:
|
||||
guardrail_result = self._process_guardrail(task_output)
|
||||
if not guardrail_result.success:
|
||||
if self.retry_count >= self.max_retries:
|
||||
raise Exception(
|
||||
@@ -464,13 +481,46 @@ class Task(BaseModel):
|
||||
)
|
||||
)
|
||||
self._save_file(content)
|
||||
crewai_event_bus.emit(self, TaskCompletedEvent(output=task_output, task=self))
|
||||
crewai_event_bus.emit(
|
||||
self, TaskCompletedEvent(output=task_output, task=self)
|
||||
)
|
||||
return task_output
|
||||
except Exception as e:
|
||||
self.end_time = datetime.datetime.now()
|
||||
crewai_event_bus.emit(self, TaskFailedEvent(error=str(e), task=self))
|
||||
raise e # Re-raise the exception after emitting the event
|
||||
|
||||
def _process_guardrail(self, task_output: TaskOutput) -> GuardrailResult:
|
||||
assert self._guardrail is not None
|
||||
|
||||
from crewai.utilities.events import (
|
||||
LLMGuardrailCompletedEvent,
|
||||
LLMGuardrailStartedEvent,
|
||||
)
|
||||
from crewai.utilities.events.crewai_event_bus import crewai_event_bus
|
||||
|
||||
result = self._guardrail(task_output)
|
||||
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
LLMGuardrailStartedEvent(
|
||||
guardrail=self._guardrail, retry_count=self.retry_count
|
||||
),
|
||||
)
|
||||
|
||||
guardrail_result = GuardrailResult.from_tuple(result)
|
||||
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
LLMGuardrailCompletedEvent(
|
||||
success=guardrail_result.success,
|
||||
result=guardrail_result.result,
|
||||
error=guardrail_result.error,
|
||||
retry_count=self.retry_count,
|
||||
),
|
||||
)
|
||||
return guardrail_result
|
||||
|
||||
def prompt(self) -> str:
|
||||
"""Prompt the task.
|
||||
|
||||
@@ -593,7 +643,7 @@ class Task(BaseModel):
|
||||
|
||||
cloned_context = (
|
||||
[task_mapping[context_task.key] for context_task in self.context]
|
||||
if self.context
|
||||
if isinstance(self.context, list)
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
92
src/crewai/tasks/llm_guardrail.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from crewai.agent import Agent, LiteAgentOutput
|
||||
from crewai.llm import LLM
|
||||
from crewai.task import Task
|
||||
from crewai.tasks.task_output import TaskOutput
|
||||
|
||||
|
||||
class LLMGuardrailResult(BaseModel):
|
||||
valid: bool = Field(
|
||||
description="Whether the task output complies with the guardrail"
|
||||
)
|
||||
feedback: str | None = Field(
|
||||
description="A feedback about the task output if it is not valid",
|
||||
default=None,
|
||||
)
|
||||
|
||||
|
||||
class LLMGuardrail:
|
||||
"""It validates the output of another task using an LLM.
|
||||
|
||||
This class is used to validate the output from a Task based on specified criteria.
|
||||
It uses an LLM to validate the output and provides a feedback if the output is not valid.
|
||||
|
||||
Args:
|
||||
description (str): The description of the validation criteria.
|
||||
llm (LLM, optional): The language model to use for code generation.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
description: str,
|
||||
llm: LLM,
|
||||
):
|
||||
self.description = description
|
||||
|
||||
self.llm: LLM = llm
|
||||
|
||||
def _validate_output(self, task_output: TaskOutput) -> LiteAgentOutput:
|
||||
agent = Agent(
|
||||
role="Guardrail Agent",
|
||||
goal="Validate the output of the task",
|
||||
backstory="You are a expert at validating the output of a task. By providing effective feedback if the output is not valid.",
|
||||
llm=self.llm,
|
||||
)
|
||||
|
||||
query = f"""
|
||||
Ensure the following task result complies with the given guardrail.
|
||||
|
||||
Task result:
|
||||
{task_output.raw}
|
||||
|
||||
Guardrail:
|
||||
{self.description}
|
||||
|
||||
Your task:
|
||||
- Confirm if the Task result complies with the guardrail.
|
||||
- If not, provide clear feedback explaining what is wrong (e.g., by how much it violates the rule, or what specific part fails).
|
||||
- Focus only on identifying issues — do not propose corrections.
|
||||
- If the Task result complies with the guardrail, saying that is valid
|
||||
"""
|
||||
|
||||
result = agent.kickoff(query, response_format=LLMGuardrailResult)
|
||||
|
||||
return result
|
||||
|
||||
def __call__(self, task_output: TaskOutput) -> Tuple[bool, Any]:
|
||||
"""Validates the output of a task based on specified criteria.
|
||||
|
||||
Args:
|
||||
task_output (TaskOutput): The output to be validated.
|
||||
|
||||
Returns:
|
||||
Tuple[bool, Any]: A tuple containing:
|
||||
- bool: True if validation passed, False otherwise
|
||||
- Any: The validation result or error message
|
||||
"""
|
||||
|
||||
try:
|
||||
result = self._validate_output(task_output)
|
||||
assert isinstance(
|
||||
result.pydantic, LLMGuardrailResult
|
||||
), "The guardrail result is not a valid pydantic model"
|
||||
|
||||
if result.pydantic.valid:
|
||||
return True, task_output.raw
|
||||
else:
|
||||
return False, result.pydantic.feedback
|
||||
except Exception as e:
|
||||
return False, f"Error while validating the task output: {str(e)}"
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import warnings
|
||||
@@ -9,11 +10,25 @@ from contextlib import contextmanager
|
||||
from importlib.metadata import version
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||
OTLPSpanExporter,
|
||||
)
|
||||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
||||
from opentelemetry.sdk.trace import TracerProvider
|
||||
from opentelemetry.sdk.trace.export import (
|
||||
BatchSpanProcessor,
|
||||
SpanExportResult,
|
||||
)
|
||||
from opentelemetry.trace import Span, Status, StatusCode
|
||||
|
||||
from crewai.telemetry.constants import (
|
||||
CREWAI_TELEMETRY_BASE_URL,
|
||||
CREWAI_TELEMETRY_SERVICE_NAME,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress_warnings():
|
||||
@@ -22,20 +37,20 @@ def suppress_warnings():
|
||||
yield
|
||||
|
||||
|
||||
from opentelemetry import trace # noqa: E402
|
||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||
OTLPSpanExporter, # noqa: E402
|
||||
)
|
||||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource # noqa: E402
|
||||
from opentelemetry.sdk.trace import TracerProvider # noqa: E402
|
||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor # noqa: E402
|
||||
from opentelemetry.trace import Span, Status, StatusCode # noqa: E402
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from crewai.crew import Crew
|
||||
from crewai.task import Task
|
||||
|
||||
|
||||
class SafeOTLPSpanExporter(OTLPSpanExporter):
|
||||
def export(self, spans) -> SpanExportResult:
|
||||
try:
|
||||
return super().export(spans)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return SpanExportResult.FAILURE
|
||||
|
||||
|
||||
class Telemetry:
|
||||
"""A class to handle anonymous telemetry for the crewai package.
|
||||
|
||||
@@ -64,7 +79,7 @@ class Telemetry:
|
||||
self.provider = TracerProvider(resource=self.resource)
|
||||
|
||||
processor = BatchSpanProcessor(
|
||||
OTLPSpanExporter(
|
||||
SafeOTLPSpanExporter(
|
||||
endpoint=f"{CREWAI_TELEMETRY_BASE_URL}/v1/traces",
|
||||
timeout=30,
|
||||
)
|
||||
@@ -217,7 +232,7 @@ class Telemetry:
|
||||
"agent_key": task.agent.key if task.agent else None,
|
||||
"context": (
|
||||
[task.description for task in task.context]
|
||||
if task.context
|
||||
if isinstance(task.context, list)
|
||||
else None
|
||||
),
|
||||
"tools_names": [
|
||||
@@ -733,7 +748,7 @@ class Telemetry:
|
||||
"agent_key": task.agent.key if task.agent else None,
|
||||
"context": (
|
||||
[task.description for task in task.context]
|
||||
if task.context
|
||||
if isinstance(task.context, list)
|
||||
else None
|
||||
),
|
||||
"tools_names": [
|
||||
|
||||
1
src/crewai/tools/agent_tools/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Agent tools for crewAI."""
|
||||
@@ -27,7 +27,9 @@
|
||||
"feedback_instructions": "User feedback: {feedback}\nInstructions: Use this feedback to enhance the next output iteration.\nNote: Do not respond or add commentary.",
|
||||
"lite_agent_system_prompt_with_tools": "You are {role}. {backstory}\nYour personal goal is: {goal}\n\nYou ONLY have access to the following tools, and should NEVER make up tools that are not listed here:\n\n{tools}\n\nIMPORTANT: Use the following format in your response:\n\n```\nThought: you should always think about what to do\nAction: the action to take, only one name of [{tool_names}], just the name, exactly as it's written.\nAction Input: the input to the action, just a simple JSON object, enclosed in curly braces, using \" to wrap keys and values.\nObservation: the result of the action\n```\n\nOnce all necessary information is gathered, return the following format:\n\n```\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n```",
|
||||
"lite_agent_system_prompt_without_tools": "You are {role}. {backstory}\nYour personal goal is: {goal}\n\nTo give my best complete final answer to the task respond using the exact following format:\n\nThought: I now can give a great answer\nFinal Answer: Your final answer must be the great and the most complete as possible, it must be outcome described.\n\nI MUST use these formats, my job depends on it!",
|
||||
"lite_agent_response_format": "\nIMPORTANT: Your final answer MUST contain all the information requested in the following format: {response_format}\n\nIMPORTANT: Ensure the final output does not include any code block markers like ```json or ```python."
|
||||
"lite_agent_response_format": "\nIMPORTANT: Your final answer MUST contain all the information requested in the following format: {response_format}\n\nIMPORTANT: Ensure the final output does not include any code block markers like ```json or ```python.",
|
||||
"knowledge_search_query": "The original query is: {task_prompt}.",
|
||||
"knowledge_search_query_system_prompt": "Your goal is to rewrite the user query so that it is optimized for retrieval from a vector database. Consider how the query will be used to find relevant documents, and aim to make it more specific and context-aware. \n\n Do not include any other text than the rewritten query, especially any preamble or postamble and only add expected output format if its relevant to the rewritten query. \n\n Focus on the key words of the intended task and to retrieve the most relevant information. \n\n There will be some extra context provided that might need to be removed such as expected_output formats structured_outputs and other instructions."
|
||||
},
|
||||
"errors": {
|
||||
"force_final_answer_error": "You can't keep going, here is the best final answer you generated:\n\n {formatted_answer}",
|
||||
|
||||
@@ -16,6 +16,7 @@ from crewai.tools.base_tool import BaseTool
|
||||
from crewai.tools.structured_tool import CrewStructuredTool
|
||||
from crewai.tools.tool_types import ToolResult
|
||||
from crewai.utilities import I18N, Printer
|
||||
from crewai.utilities.errors import AgentRepositoryError
|
||||
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
||||
LLMContextLengthExceededException,
|
||||
)
|
||||
@@ -428,3 +429,36 @@ def show_agent_logs(
|
||||
printer.print(
|
||||
content=f"\033[95m## Final Answer:\033[00m \033[92m\n{formatted_answer.output}\033[00m\n\n"
|
||||
)
|
||||
|
||||
|
||||
def load_agent_from_repository(from_repository: str) -> Dict[str, Any]:
|
||||
attributes: Dict[str, Any] = {}
|
||||
if from_repository:
|
||||
import importlib
|
||||
|
||||
from crewai.cli.authentication.token import get_auth_token
|
||||
from crewai.cli.plus_api import PlusAPI
|
||||
|
||||
client = PlusAPI(api_key=get_auth_token())
|
||||
response = client.get_agent(from_repository)
|
||||
if response.status_code != 200:
|
||||
raise AgentRepositoryError(
|
||||
f"Agent {from_repository} could not be loaded: {response.text}"
|
||||
)
|
||||
|
||||
agent = response.json()
|
||||
for key, value in agent.items():
|
||||
if key == "tools":
|
||||
attributes[key] = []
|
||||
for tool_name in value:
|
||||
try:
|
||||
module = importlib.import_module("crewai_tools")
|
||||
tool_class = getattr(module, tool_name)
|
||||
attributes[key].append(tool_class())
|
||||
except Exception as e:
|
||||
raise AgentRepositoryError(
|
||||
f"Tool {tool_name} could not be loaded: {e}"
|
||||
) from e
|
||||
else:
|
||||
attributes[key] = value
|
||||
return attributes
|
||||
|
||||
@@ -5,3 +5,14 @@ KNOWLEDGE_DIRECTORY = "knowledge"
|
||||
MAX_LLM_RETRY = 3
|
||||
MAX_FILE_NAME_LENGTH = 255
|
||||
EMITTER_COLOR = "bold_blue"
|
||||
|
||||
|
||||
class _NotSpecified:
|
||||
def __repr__(self):
|
||||
return "NOT_SPECIFIED"
|
||||
|
||||
|
||||
# Sentinel value used to detect when no value has been explicitly provided.
|
||||
# Unlike `None`, which might be a valid value from the user, `NOT_SPECIFIED` allows
|
||||
# us to distinguish between "not passed at all" and "explicitly passed None" or "[]".
|
||||
NOT_SPECIFIED = _NotSpecified()
|
||||
|
||||