流程
Process 实现
Section titled “Process 实现”- Sequential:按顺序执行任务,确保任务按有序的推进完成。
- Hierarchical:以管理层级组织任务,任务会根据结构化的指挥链进行委派和执行。要启用 hierarchical process,crew 中必须指定 manager language model(
manager_llm)或自定义 manager agent(manager_agent),以支持 manager 创建和管理任务。
Processes 在团队协作中的作用
Section titled “Processes 在团队协作中的作用”Processes 让单个 agents 作为一个整体高效运作,帮助它们更顺畅地协同完成共同目标。
将 Process 分配给 Crew
Section titled “将 Process 分配给 Crew”要给 crew 分配 process,请在创建 crew 时指定 process 类型,以设定执行策略。对于 hierarchical process,请务必定义 manager_llm 或 manager_agent 作为 manager agent。
from crewai import Crew, Process
# 示例:创建一个使用 sequential process 的 crewcrew = Crew( agents=my_agents, tasks=my_tasks, process=Process.sequential)
# 示例:创建一个使用 hierarchical process 的 crew# 请确保提供 manager_llm 或 manager_agentcrew = Crew( agents=my_agents, tasks=my_tasks, process=Process.hierarchical, manager_llm="gpt-4o" # 或 # manager_agent=my_manager_agent)注意: 请确保在创建 Crew 对象之前已经定义好 my_agents 和 my_tasks,并且对于 hierarchical process,还必须提供 manager_llm 或 manager_agent。
这种方式模拟动态团队工作流,以周到且系统化的方式推进任务。任务执行会按任务列表中的预定义顺序进行,前一个任务的输出会作为下一个任务的上下文。
要自定义任务上下文,请在 Task 类中使用 context 参数,指定哪些输出应作为后续任务的上下文。
它模拟企业层级结构,CrewAI 允许指定自定义 manager agent,或者自动创建一个 manager,但这需要指定 manager language model(manager_llm)。这个 agent 负责监督任务执行,包括规划、委派和验证。任务不会预先分配;manager 会根据 agents 的能力分配任务、审核输出并评估任务是否完成。
Process 类:详细概览
Section titled “Process 类:详细概览”Process 类以枚举(Enum)形式实现,确保类型安全,并将 process 值限制为已定义的类型(sequential、hierarchical)。
通过 processes 实现的结构化协作,是 CrewAI 让 agents 以系统化方式协同工作的关键。 本文档已经更新,以反映最新的功能和增强内容,确保用户能够获得最及时、最完整的信息。