官方网站 | https://www.crewai.com/ |
---|---|
GIT地址 | https://github.com/crewAIInc/crewAI |
GIT Star数 | 25493 |
开发语言 | Python |
话题 | agents, ai, ai-agents, llms |
GIT信息最后更新日期 | 2025/01/28 02:25 |
许可 | MIT |
简介 | 最先进的框架,用于编排角色扮演的自主人工智能代理。通过培养协作智能,CrewAI使代理能够无缝合作,解决复杂任务。 |
To get started with CrewAI, follow these simple steps:
Ensure you have Python >=3.10 <3.13 installed on your system. CrewAI uses UV for dependency management and package handling, offering a seamless setup and execution experience.
First, install CrewAI:
pip install crewai
If you want to install the 'crewai' package along with its optional features that include additional tools for agents, you can do so by using the following command:
pip install 'crewai[tools]'
The command above installs the basic package and also adds extra components which require more dependencies to function.
To create a new CrewAI project, run the following CLI (Command Line Interface) command:
crewai create crew <project_name>
This command creates a new project folder with the following structure:
my_project/├── .gitignore├── pyproject.toml├── README.md├── .env└── src/ └── my_project/ ├── __init__.py ├── main.py ├── crew.py ├── tools/ │ ├── custom_tool.py │ └── __init__.py └── config/ ├── agents.yaml └── tasks.yaml
You can now start developing your crew by editing the files in the src/my_project
folder. The main.py
file is the entry point of the project, the crew.py
file is where you define your crew, the agents.yaml
file is where you define your agents, and the tasks.yaml
file is where you define your tasks.
src/my_project/config/agents.yaml
to define your agents.src/my_project/config/tasks.yaml
to define your tasks.src/my_project/crew.py
to add your own logic, tools, and specific arguments.src/my_project/main.py
to add custom inputs for your agents and tasks..env
file.Instantiate your crew:
crewai create crew latest-ai-development
Modify the files as needed to fit your use case:
agents.yaml
# src/my_project/config/agents.yamlresearcher: role: > {topic} Senior Data Researcher goal: > Uncover cutting-edge developments in {topic} backstory: > You're a seasoned researcher with a knack for uncovering the latest developments in {topic}. Known for your ability to find the most relevant information and present it in a clear and concise manner.reporting_analyst: role: > {topic} Reporting Analyst goal: > Create detailed reports based on {topic} data analysis and research findings backstory: > You're a meticulous analyst with a keen eye for detail. You're known for your ability to turn complex data into clear and concise reports, making it easy for others to understand and act on the information you provide.
tasks.yaml
# src/my_project/config/tasks.yamlresearch_task: description: > Conduct a thorough research about {topic} Make sure you find any interesting and relevant information given the current year is 2024. expected_output: > A list with 10 bullet points of the most relevant information about {topic} agent: researcherreporting_task: description: > Review the context you got and expand each topic into a full section for a report. Make sure the report is detailed and contains any and all relevant information. expected_output: > A fully fledge reports with the mains topics, each with a full section of information. Formatted as markdown without '```' agent: reporting_analyst output_file: report.md
crew.py
# src/my_project/crew.pyfrom crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, taskfrom crewai_tools import SerperDevTool@CrewBaseclass LatestAiDevelopmentCrew():"""LatestAiDevelopment crew"""@agentdef researcher(self) -> Agent:return Agent(config=self.agents_config['researcher'],verbose=True,tools=[SerperDevTool()])@agentdef reporting_analyst(self) -> Agent:return Agent(config=self.agents_config['reporting_analyst'],verbose=True)@taskdef research_task(self) -> Task:return Task(config=self.tasks_config['research_task'],)@taskdef reporting_task(self) -> Task:return Task(config=self.tasks_config['reporting_task'],output_file='report.md')@crewdef crew(self) -> Crew:"""Creates the LatestAiDevelopment crew"""return Crew(agents=self.agents, # Automatically created by the @agent decoratortasks=self.tasks, # Automatically created by the @task decoratorprocess=Process.sequential,verbose=True,)
main.py
#!/usr/bin/env python# src/my_project/main.pyimport sysfrom latest_ai_development.crew import LatestAiDevelopmentCrewdef run(): """ Run the crew. """ inputs = { 'topic': 'AI Agents' } LatestAiDevelopmentCrew().crew().kickoff(inputs=inputs)
Before running your crew, make sure you have the following keys set as environment variables in your .env
file:
OPENAI_API_KEY=sk-...
SERPER_API_KEY=YOUR_KEY_HERE
Lock the dependencies and install them by using the CLI command but first, navigate to your project directory:
cd my_projectcrewai install (Optional)
To run your crew, execute the following command in the root of your project:
crewai run
or
python src/my_project/main.py
If an error happens due to the usage of poetry, please run the following command to update your crewai package:
crewai update
You should see the output in the console and the report.md
file should be created in the root of your project with the full final report.
In addition to the sequential process, you can use the hierarchical process, which automatically assigns a manager to the defined crew to properly coordinate the planning and execution of tasks through delegation and validation of results. See more about the processes here.