You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/concepts/knowledge.mdx
+11-7
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,21 @@
1
1
---
2
2
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.
4
4
icon: book
5
5
---
6
6
7
7
# Using Knowledge in CrewAI
8
8
9
9
## Introduction
10
10
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
+
11
13
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
+
12
19
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.
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
+
classMyCrew:
19
+
@before_kickoff
20
+
defprepare_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
+
classMyCrew:
41
+
@after_kickoff
42
+
deflog_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.
Copy file name to clipboardexpand all lines: docs/quickstart.mdx
+37-11
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ icon: rocket
8
8
9
9
Let's create a simple crew that will help us `research` and `report` on the `latest AI developments` for a given topic or subject.
10
10
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.
12
12
If you haven't installed them yet, you can do so by following the [installation guide](/installation).
13
13
14
14
Follow the steps below to get crewing! 🚣♂️
@@ -23,7 +23,7 @@ Follow the steps below to get crewing! 🚣♂️
23
23
```
24
24
</CodeGroup>
25
25
</Step>
26
-
<Steptitle="Modify your `agents.yaml` file">
26
+
<Steptitle="Modify your `agents.yaml` file">
27
27
<Tip>
28
28
You can also modify the agents as needed to fit your use case or copy and paste as is to your project.
29
29
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! 🚣♂️
39
39
You're a seasoned researcher with a knack for uncovering the latest
40
40
developments in {topic}. Known for your ability to find the most relevant
41
41
information and present it in a clear and concise manner.
42
-
42
+
43
43
reporting_analyst:
44
44
role: >
45
45
{topic} Reporting Analyst
@@ -51,7 +51,7 @@ Follow the steps below to get crewing! 🚣♂️
51
51
it easy for others to understand and act on the information you provide.
52
52
```
53
53
</Step>
54
-
<Step title="Modify your `tasks.yaml` file">
54
+
<Step title="Modify your `tasks.yaml` file">
55
55
```yaml tasks.yaml
56
56
# src/latest_ai_development/config/tasks.yaml
57
57
research_task:
@@ -73,8 +73,8 @@ Follow the steps below to get crewing! 🚣♂️
73
73
agent: reporting_analyst
74
74
output_file: report.md
75
75
```
76
-
</Step>
77
-
<Step title="Modify your `crew.py` file">
76
+
</Step>
77
+
<Step title="Modify your `crew.py` file">
78
78
```python crew.py
79
79
# src/latest_ai_development/crew.py
80
80
from crewai import Agent, Crew, Process, Task
@@ -121,10 +121,34 @@ Follow the steps below to get crewing! 🚣♂️
121
121
tasks=self.tasks, # Automatically created by the @task decorator
122
122
process=Process.sequential,
123
123
verbose=True,
124
-
)
124
+
)
125
125
```
126
126
</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
+
<Steptitle="Feel free to pass custom inputs to your crew">
128
152
For example, you can pass the `topic` input to your crew to customize the research and reporting.
129
153
```python main.py
130
154
#!/usr/bin/env python
@@ -237,14 +261,14 @@ Follow the steps below to get crewing! 🚣♂️
237
261
### Note on Consistency in Naming
238
262
239
263
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.
241
265
This naming consistency allows CrewAI to automatically link your configurations with your code; otherwise, your task won't recognize the reference properly.
242
266
243
267
#### Example References
244
268
245
269
<Tip>
246
270
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>
248
272
249
273
```yaml agents.yaml
250
274
email_summarizer:
@@ -281,6 +305,8 @@ Use the annotations to properly reference the agent and task in the `crew.py` fi
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.
308
334
You can learn more about the core concepts [here](/concepts).
Copy file name to clipboardexpand all lines: pyproject.toml
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
[project]
2
2
name = "crewai"
3
-
version = "0.80.0"
3
+
version = "0.83.0"
4
4
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."
0 commit comments