Appearance
Building an Information Gathering System
This is an example of using CrewAI with a single agent to build an information gathering system.
If you want to run this example, you can find the code in this GitHub repository:
https://github.com/pverhaert/crewai_basic_demo
Introduction
In this demo, we'll explore a practical example of using CrewAI to create an information gathering system. This system is designed to provide comprehensive information on any given topic in a specified language. The agency in this example has only one agent that has one task. The agent uses only its own knowledge to answer questions, without internet access.
Understanding the Crew
The crew in this example consists of a single agent and a single task. Let's break down what the crew does:
- It takes user input for a
topic
and alanguage
. - It uses an Information Agent to gather detailed information about the topic.
- It presents the information in a structured format, including a summary, detailed explanation, and key points.
- The output is provided in the specified language, with titles translated accordingly.
- Finally, it saves the output to a markdown file.
Agent and Task Relationship
The Information Agent
python
researcher = Agent(
role="Information Agent",
goal="Provide comprehensive and accurate information about {topic}",
backstory="""
You are an advanced information agent with access to vast databases and resources.
Your primary objective is to deliver detailed, factual, and well-organized information on any given topic.
You must avoid giving personal opinions or making unsupported assumptions.
""",
verbose=True,
)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
This agent is designed to be a knowledgeable and reliable source of information. Its goal is to provide comprehensive and accurate information about the given topic.
The Task
python
get_info_task = Task(
description="Gather and present detailed information about {topic} in {language}",
agent=researcher,
expected_output="""
Provide an extensive summary of {topic} in {language}, followed by a thorough explanation and 5 key points about {topic}.
Also translate the titles in the output to {language}.
Format the result in markdown.
Output format:
# {topic}
## Summary
A comprehensive summary in paragraph format.
## Detailed Explanation
An in-depth explanation covering various aspects of {topic}.
## 5 Key Points about {topic}
- **1**: Detailed explanation of point 1.
- **2**: Detailed explanation of point 2.
- **3**: Detailed explanation of point 3.
- **4**: Detailed explanation of point 4.
- **5**: Detailed explanation of point 5.
""",
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
The task is assigned to the Information Agent. It specifies what the agent should do (gather and present information) and how the output should be structured.
Running the Crew
To start the crew, we follow these steps:
- Create the crew object:
python
crew = Crew(
agents=[researcher],
tasks=[get_info_task],
full_output=True,
verbose=True,
)
1
2
3
4
5
6
2
3
4
5
6
- Get user input:
python
user_topic = input("\nEnter the topic you want information about: \n")
language = input("\nEnter the language you want the information in:").strip() or "English"
inputs = {
'topic': user_topic,
'language': language,
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- Kickoff the crew:
python
result = crew.kickoff(inputs=inputs)
1
- Print and save the result:
python
print(result)
output_filename = f"demo1/{inputs['topic'].replace(' ', '_')}.md"
with open(output_filename, 'w', encoding='utf-8') as file:
file.write(str(result))
1
2
3
4
5
2
3
4
5
Example: "The Birds by Alfred Hitchcock"
Let's walk through an example using "The Birds by Alfred Hitchcock" as the input topic and "English" as the language.
User input:
- Topic: The Birds by Alfred Hitchcock
- Language: English
The Information Agent will gather comprehensive information about the film.
The task will structure the information according to the specified format.
The crew will kickoff and generate the result.
The output will be saved as
demo1/The_Birds_by_Alfred_Hitchcock.md
and might look something like this:\
markdown
# The Birds by Alfred Hitchcock
## Summary
The Birds is a 1963 horror film directed by Alfred Hitchcock, based on the 1951 short story "The Birds" by Daphne du
Maurier. The film tells the story of a series of sudden and unexplained bird attacks on the people of Bodega Bay, a
small town in Northern California. The film follows Melanie Daniels, a young socialite who meets Matthew Condon, a
lawyer, and his mother, at a San Francisco bird shop. Melanie, who has never been to the area before, decides to follow
Matthew home, where she meets his mother, Mrs. Condon, and his younger sister, Cathy. As the story unfolds, the family
and the town are attacked by birds, including seagulls, sparrows, and even hawks, resulting in chaos and terror.
## Detailed Explanation
The Birds is a seminal work by Alfred Hitchcock, one of the most influential filmmakers of all time. The film is a
masterclass in suspense, with Hitchcock expertly building tension through a combination of atmospheric settings, sound
design, and the unsettling presence of birds. The film's use of birds as a source of terror is both fascinating and
terrifying, and it has become one of the most iconic and enduring images in horror cinema.
The film's story is relatively simple, but it is the execution that makes it so effective. Hitchcock's use of long
takes, point-of-view shots, and careful editing creates a sense of unease and uncertainty, making the viewer feel like
they are part of the action. The film's cast, including Tippi Hedren, Rod Taylor, and Jessica Tandy, deliver strong
performances that add to the film's tension.
One of the most interesting aspects of The Birds is its use of symbolism. The birds can be seen as a symbol for the
unpredictability of nature, and the way that they attack without warning serves as a reminder of the power of the
natural world. The film also explores themes of family, love, and the complexities of human relationships.
## 5 Key Points about The Birds by Alfred Hitchcock
- **1**: **The Film's Use of Real Birds**: Hitchcock used a combination of real birds and special effects to create the
film's terrifying bird attacks. The film's crew spent months training birds to perform specific actions, and the
results are both impressive and unsettling.
- **2**: **The Role of Sound**: The Birds is a film that is just as much about sound as it is about image. Hitchcock's
use of sound design, including the sound of birds chirping and flapping, creates a sense of unease and tension that is
impossible to ignore.
- **3**: **The Influence of Daphne du Maurier**: The Birds is based on a short story by Daphne du Maurier, a British
author known for her dark and atmospheric stories. Du Maurier's work was a major influence on Hitchcock, and The Birds
is one of several films that he made based on her stories.
- **4**: **The Performance of Tippi Hedren**: Tippi Hedren, who played the role of Melanie Daniels, was a relatively
unknown actress when she was cast in The Birds. Her performance in the film was widely praised, and it helped to
establish her as a major star.
- **5**: **The Legacy of The Birds**: The Birds is a film that has had a lasting impact on the horror genre. It has been
named as one of the greatest horror films of all time, and its influence can be seen in countless other films,
including The Shining and The Exorcist.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Example Output
And example output file can be found here: The Birds by Alfred Hitchcock