文档索引
获取完整文档索引: https://docs.crewai.com.cn/llms.txt
在深入了解之前,请使用此文件来浏览所有可用页面。
在 CrewAI 中设置特定代理作为管理者
CrewAI 允许用户指定一个特定代理作为团队(Crew)的管理者,从而对任务的管理和协调提供更强的控制力。此功能支持自定义管理角色,以更好地契合您的项目需求。
使用 manager_agent 属性
自定义管理器智能体
manager_agent 属性允许您定义一个自定义代理来管理团队。该代理将监督整个流程,确保任务能够高效且高标准地完成。
import os
from crewai import Agent, Task, Crew, Process
# Define your agents
researcher = Agent(
role="Researcher",
goal="Conduct thorough research and analysis on AI and AI agents",
backstory="You're an expert researcher, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently researching for a new client.",
allow_delegation=False,
)
writer = Agent(
role="Senior Writer",
goal="Create compelling content about AI and AI agents",
backstory="You're a senior writer, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently writing content for a new client.",
allow_delegation=False,
)
# Define your task
task = Task(
description="Generate a list of 5 interesting ideas for an article, then write one captivating paragraph for each idea that showcases the potential of a full article on this topic. Return the list of ideas with their paragraphs and your notes.",
expected_output="5 bullet points, each with a paragraph and accompanying notes.",
)
# Define the manager agent
manager = Agent(
role="Project Manager",
goal="Efficiently manage the crew and ensure high-quality task completion",
backstory="You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
allow_delegation=True,
)
# Instantiate your crew with a custom manager
crew = Crew(
agents=[researcher, writer],
tasks=[task],
manager_agent=manager,
process=Process.hierarchical,
)
# Start the crew's work
result = crew.kickoff()
自定义管理代理的优势
- 增强的控制力:根据项目的具体需求量身定制管理方式。
- 改进的协调性:由经验丰富的代理确保高效的任务协调与管理。
- 可自定义的管理:定义与项目目标保持一致的管理角色和职责。
设置管理者大语言模型 (Manager LLM)
如果您正在使用分层流程(Hierarchical Process),且不想设置自定义管理代理,您可以直接为管理者指定大语言模型。
from crewai import LLM
manager_llm = LLM(model="gpt-4o")
crew = Crew(
agents=[researcher, writer],
tasks=[task],
process=Process.hierarchical,
manager_llm=manager_llm
)
使用分层流程时,必须设置 manager_agent 或 manager_llm 其中之一。