CrewAI-readme-8.py
· 1.0 KiB · Python
Raw
# src/my_project/crew.py
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from crewai_tools import SerperDevTool
@CrewBase
class LatestAiDevelopmentCrew():
"""LatestAiDevelopment crew"""
@agent
def researcher(self) -> Agent:
return Agent(
config=self.agents_config['researcher'],
verbose=True,
tools=[SerperDevTool()]
)
@agent
def reporting_analyst(self) -> Agent:
return Agent(
config=self.agents_config['reporting_analyst'],
verbose=True
)
@task
def research_task(self) -> Task:
return Task(
config=self.tasks_config['research_task'],
)
@task
def reporting_task(self) -> Task:
return Task(
config=self.tasks_config['reporting_task'],
output_file='report.md'
)
@crew
def crew(self) -> Crew:
"""Creates the LatestAiDevelopment crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
)
1 | # src/my_project/crew.py |
2 | from crewai import Agent, Crew, Process, Task |
3 | from crewai.project import CrewBase, agent, crew, task |
4 | from crewai_tools import SerperDevTool |
5 | |
6 | @CrewBase |
7 | class LatestAiDevelopmentCrew(): |
8 | """LatestAiDevelopment crew""" |
9 | |
10 | @agent |
11 | def researcher(self) -> Agent: |
12 | return Agent( |
13 | config=self.agents_config['researcher'], |
14 | verbose=True, |
15 | tools=[SerperDevTool()] |
16 | ) |
17 | |
18 | @agent |
19 | def reporting_analyst(self) -> Agent: |
20 | return Agent( |
21 | config=self.agents_config['reporting_analyst'], |
22 | verbose=True |
23 | ) |
24 | |
25 | @task |
26 | def research_task(self) -> Task: |
27 | return Task( |
28 | config=self.tasks_config['research_task'], |
29 | ) |
30 | |
31 | @task |
32 | def reporting_task(self) -> Task: |
33 | return Task( |
34 | config=self.tasks_config['reporting_task'], |
35 | output_file='report.md' |
36 | ) |
37 | |
38 | @crew |
39 | def crew(self) -> Crew: |
40 | """Creates the LatestAiDevelopment crew""" |
41 | return Crew( |
42 | agents=self.agents, # Automatically created by the @agent decorator |
43 | tasks=self.tasks, # Automatically created by the @task decorator |
44 | process=Process.sequential, |
45 | verbose=True, |
46 | ) |