Skip to content

Commit 8cf1cd5

Browse files
committed
preparing new version
1 parent 93c0467 commit 8cf1cd5

File tree

12 files changed

+137
-31
lines changed

12 files changed

+137
-31
lines changed

docs/concepts/knowledge.mdx

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
---
22
title: Knowledge
3-
description: What is knowledge in CrewAI and how to use it.
3+
description: Understand what knowledge is in CrewAI and how to effectively use it.
44
icon: book
55
---
66

77
# Using Knowledge in CrewAI
88

99
## Introduction
1010

11+
Knowledge in CrewAI serves as a foundational component for enriching AI agents with contextual and relevant information. It enables agents to access and utilize structured data sources during their execution processes, making them more intelligent and responsive.
12+
1113
The Knowledge class in CrewAI provides a powerful way to manage and query knowledge sources for your AI agents. This guide will show you how to implement knowledge management in your CrewAI projects.
14+
15+
## What is Knowledge?
16+
17+
The `Knowledge` class in CrewAI manages various sources that store information, which can be queried and retrieved by AI agents. This modular approach allows you to integrate diverse data formats such as text, PDFs, spreadsheets, and more into your AI workflows.
18+
1219
Additionally, we have specific tools for generate knowledge sources for strings, text files, PDF's, and Spreadsheets. You can expand on any source type by extending the `KnowledgeSource` class.
1320

1421
## Basic Implementation
@@ -25,17 +32,14 @@ string_source = StringKnowledgeSource(
2532
content=content, metadata={"preference": "personal"}
2633
)
2734

28-
29-
llm = LLM(model="gpt-4o-mini", temperature=0)
30-
# Create an agent with the knowledge store
35+
# Create an agent with the knowledge store
3136
agent = Agent(
3237
role="About User",
3338
goal="You know everything about the user.",
3439
backstory="""You are a master at understanding people and their preferences.""",
35-
verbose=True,
36-
allow_delegation=False,
37-
llm=llm,
40+
verbose=True
3841
)
42+
3943
task = Task(
4044
description="Answer the following questions about the user: {question}",
4145
expected_output="An answer to the question.",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Before and After Kickoff Hooks
3+
description: Learn how to use before and after kickoff hooks in CrewAI
4+
---
5+
6+
CrewAI provides hooks that allow you to execute code before and after a crew's kickoff. These hooks are useful for preprocessing inputs or post-processing results.
7+
8+
## Before Kickoff Hook
9+
10+
The before kickoff hook is executed before the crew starts its tasks. It receives the input dictionary and can modify it before passing it to the crew. You can use this hook to set up your environment, load necessary data, or preprocess your inputs. This is useful in scenarios where the input data might need enrichment or validation before being processed by the crew.
11+
12+
Here's an example of defining a before kickoff function in your `crew.py`:
13+
14+
```python
15+
from crewai import CrewBase, before_kickoff
16+
17+
@CrewBase
18+
class MyCrew:
19+
@before_kickoff
20+
def prepare_data(self, inputs):
21+
# Preprocess or modify inputs
22+
inputs['processed'] = True
23+
return inputs
24+
25+
#...
26+
```
27+
28+
In this example, the prepare_data function modifies the inputs by adding a new key-value pair indicating that the inputs have been processed.
29+
30+
## After Kickoff Hook
31+
32+
The after kickoff hook is executed after the crew has completed its tasks. It receives the result object, which contains the outputs of the crew's execution. This hook is ideal for post-processing results, such as logging, data transformation, or further analysis.
33+
34+
Here's how you can define an after kickoff function in your `crew.py`:
35+
36+
```python
37+
from crewai import CrewBase, after_kickoff
38+
39+
@CrewBase
40+
class MyCrew:
41+
@after_kickoff
42+
def log_results(self, result):
43+
# Log or modify the results
44+
print("Crew execution completed with result:", result)
45+
return result
46+
47+
# ...
48+
```
49+
50+
51+
In the `log_results` function, the results of the crew execution are simply printed out. You can extend this to perform more complex operations such as sending notifications or integrating with other services.
52+
53+
## Utilizing Both Hooks
54+
55+
Both hooks can be used together to provide a comprehensive setup and teardown process for your crew's execution. They are particularly useful in maintaining clean code architecture by separating concerns and enhancing the modularity of your CrewAI implementations.
56+
57+
## Conclusion
58+
59+
Before and after kickoff hooks in CrewAI offer powerful ways to interact with the lifecycle of a crew's execution. By understanding and utilizing these hooks, you can greatly enhance the robustness and flexibility of your AI agents.

docs/quickstart.mdx

+37-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: rocket
88

99
Let's create a simple crew that will help us `research` and `report` on the `latest AI developments` for a given topic or subject.
1010

11-
Before we proceed, make sure you have `crewai` and `crewai-tools` installed.
11+
Before we proceed, make sure you have `crewai` and `crewai-tools` installed.
1212
If you haven't installed them yet, you can do so by following the [installation guide](/installation).
1313

1414
Follow the steps below to get crewing! 🚣‍♂️
@@ -23,7 +23,7 @@ Follow the steps below to get crewing! 🚣‍♂️
2323
```
2424
</CodeGroup>
2525
</Step>
26-
<Step title="Modify your `agents.yaml` file">
26+
<Step title="Modify your `agents.yaml` file">
2727
<Tip>
2828
You can also modify the agents as needed to fit your use case or copy and paste as is to your project.
2929
Any variable interpolated in your `agents.yaml` and `tasks.yaml` files like `{topic}` will be replaced by the value of the variable in the `main.py` file.
@@ -39,7 +39,7 @@ Follow the steps below to get crewing! 🚣‍♂️
3939
You're a seasoned researcher with a knack for uncovering the latest
4040
developments in {topic}. Known for your ability to find the most relevant
4141
information and present it in a clear and concise manner.
42-
42+
4343
reporting_analyst:
4444
role: >
4545
{topic} Reporting Analyst
@@ -51,7 +51,7 @@ Follow the steps below to get crewing! 🚣‍♂️
5151
it easy for others to understand and act on the information you provide.
5252
```
5353
</Step>
54-
<Step title="Modify your `tasks.yaml` file">
54+
<Step title="Modify your `tasks.yaml` file">
5555
```yaml tasks.yaml
5656
# src/latest_ai_development/config/tasks.yaml
5757
research_task:
@@ -73,8 +73,8 @@ Follow the steps below to get crewing! 🚣‍♂️
7373
agent: reporting_analyst
7474
output_file: report.md
7575
```
76-
</Step>
77-
<Step title="Modify your `crew.py` file">
76+
</Step>
77+
<Step title="Modify your `crew.py` file">
7878
```python crew.py
7979
# src/latest_ai_development/crew.py
8080
from crewai import Agent, Crew, Process, Task
@@ -121,10 +121,34 @@ Follow the steps below to get crewing! 🚣‍♂️
121121
tasks=self.tasks, # Automatically created by the @task decorator
122122
process=Process.sequential,
123123
verbose=True,
124-
)
124+
)
125125
```
126126
</Step>
127-
<Step title="Feel free to pass custom inputs to your crew">
127+
<Step title="[Optional] Add before and after crew functions">
128+
```python crew.py
129+
# src/latest_ai_development/crew.py
130+
from crewai import Agent, Crew, Process, Task
131+
from crewai.project import CrewBase, agent, crew, task, before_kickoff, after_kickoff
132+
from crewai_tools import SerperDevTool
133+
134+
@CrewBase
135+
class LatestAiDevelopmentCrew():
136+
"""LatestAiDevelopment crew"""
137+
138+
@before_kickoff
139+
def before_kickoff_function(self, inputs):
140+
print(f"Before kickoff function with inputs: {inputs}")
141+
return inputs # You can return the inputs or modify them as needed
142+
143+
@after_kickoff
144+
def after_kickoff_function(self, result):
145+
print(f"After kickoff function with result: {result}")
146+
return result # You can return the result or modify it as needed
147+
148+
# ... remaining code
149+
```
150+
</Step>
151+
<Step title="Feel free to pass custom inputs to your crew">
128152
For example, you can pass the `topic` input to your crew to customize the research and reporting.
129153
```python main.py
130154
#!/usr/bin/env python
@@ -237,14 +261,14 @@ Follow the steps below to get crewing! 🚣‍♂️
237261
### Note on Consistency in Naming
238262

239263
The names you use in your YAML files (`agents.yaml` and `tasks.yaml`) should match the method names in your Python code.
240-
For example, you can reference the agent for specific tasks from `tasks.yaml` file.
264+
For example, you can reference the agent for specific tasks from `tasks.yaml` file.
241265
This naming consistency allows CrewAI to automatically link your configurations with your code; otherwise, your task won't recognize the reference properly.
242266

243267
#### Example References
244268

245269
<Tip>
246270
Note how we use the same name for the agent in the `agents.yaml` (`email_summarizer`) file as the method name in the `crew.py` (`email_summarizer`) file.
247-
</Tip>
271+
</Tip>
248272

249273
```yaml agents.yaml
250274
email_summarizer:
@@ -281,6 +305,8 @@ Use the annotations to properly reference the agent and task in the `crew.py` fi
281305
* `@task`
282306
* `@crew`
283307
* `@tool`
308+
* `@before_kickoff`
309+
* `@after_kickoff`
284310
* `@callback`
285311
* `@output_json`
286312
* `@output_pydantic`
@@ -304,7 +330,7 @@ def email_summarizer_task(self) -> Task:
304330

305331
<Tip>
306332
In addition to the [sequential process](../how-to/sequential-process), you can use the [hierarchical process](../how-to/hierarchical-process),
307-
which automatically assigns a manager to the defined crew to properly coordinate the planning and execution of tasks through delegation and validation of results.
333+
which automatically assigns a manager to the defined crew to properly coordinate the planning and execution of tasks through delegation and validation of results.
308334
You can learn more about the core concepts [here](/concepts).
309335
</Tip>
310336

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "crewai"
3-
version = "0.80.0"
3+
version = "0.83.0"
44
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."
55
readme = "README.md"
66
requires-python = ">=3.10,<=3.13"
@@ -29,6 +29,8 @@ dependencies = [
2929
"tomli-w>=1.1.0",
3030
"tomli>=2.0.2",
3131
"chromadb>=0.5.18",
32+
"pdfplumber>=0.11.4",
33+
"openpyxl>=3.1.5",
3234
]
3335

3436
[project.urls]

src/crewai/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
category=UserWarning,
1717
module="pydantic.main",
1818
)
19-
__version__ = "0.80.0"
19+
__version__ = "0.83.0"
2020
__all__ = [
2121
"Agent",
2222
"Crew",

src/crewai/cli/templates/crew/crew.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from crewai import Agent, Crew, Process, Task
2-
from crewai.project import CrewBase, agent, crew, task
2+
from crewai.project import CrewBase, agent, crew, task, before_kickoff, after_kickoff
33

44
# Uncomment the following line to use an example of a custom tool
55
# from {{folder_name}}.tools.custom_tool import MyCustomTool
@@ -14,6 +14,18 @@ class {{crew_name}}():
1414
agents_config = 'config/agents.yaml'
1515
tasks_config = 'config/tasks.yaml'
1616

17+
@before_kickoff # Optional hook to be executed before the crew starts
18+
def pull_data_example(self, inputs):
19+
# Example of pulling data from an external API, dynamically changing the inputs
20+
inputs['extra_data'] = "This is extra data"
21+
return inputs
22+
23+
@after_kickoff # Optional hook to be executed after the crew has finished
24+
def log_results(self, output):
25+
# Example of logging results, dynamically changing the output
26+
print(f"Results: {output}")
27+
return output
28+
1729
@agent
1830
def researcher(self) -> Agent:
1931
return Agent(

src/crewai/cli/templates/crew/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
55
authors = [{ name = "Your Name", email = "you@example.com" }]
66
requires-python = ">=3.10,<=3.13"
77
dependencies = [
8-
"crewai[tools]>=0.80.0,<1.0.0"
8+
"crewai[tools]>=0.83.0,<1.0.0"
99
]
1010

1111
[project.scripts]

src/crewai/cli/templates/flow/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
55
authors = [{ name = "Your Name", email = "you@example.com" }]
66
requires-python = ">=3.10,<=3.13"
77
dependencies = [
8-
"crewai[tools]>=0.80.0,<1.0.0",
8+
"crewai[tools]>=0.83.0,<1.0.0",
99
]
1010

1111
[project.scripts]

src/crewai/cli/templates/pipeline/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Your Name <you@example.com>"]
66

77
[tool.poetry.dependencies]
88
python = ">=3.10,<=3.13"
9-
crewai = { extras = ["tools"], version = ">=0.80.0,<1.0.0" }
9+
crewai = { extras = ["tools"], version = ">=0.83.0,<1.0.0" }
1010
asyncio = "*"
1111

1212
[tool.poetry.scripts]

src/crewai/cli/templates/pipeline_router/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
55
authors = ["Your Name <you@example.com>"]
66
requires-python = ">=3.10,<=3.13"
77
dependencies = [
8-
"crewai[tools]>=0.80.0,<1.0.0"
8+
"crewai[tools]>=0.83.0,<1.0.0"
99
]
1010

1111
[project.scripts]

src/crewai/cli/templates/tool/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ description = "Power up your crews with {{folder_name}}"
55
readme = "README.md"
66
requires-python = ">=3.10,<=3.13"
77
dependencies = [
8-
"crewai[tools]>=0.80.0"
8+
"crewai[tools]>=0.83.0"
99
]
1010

uv.lock

+8-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)