跳转到内容

自定义管理者代理

在 CrewAI 中将特定 agent 设为管理者

Section titled “在 CrewAI 中将特定 agent 设为管理者”

CrewAI 允许用户将某个特定 agent 设置为 crew 的管理者,从而更好地控制任务 管理与协调。这个功能可以根据项目需求定制管理角色。

manager_agent 属性允许你定义一个自定义 agent 来管理 crew。这个 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()
  • 更强控制力:根据项目的具体需求调整管理方式。
  • 更好的协调:通过经验丰富的 agent 确保任务协调与管理高效进行。
  • 可定制的管理方式:定义与项目目标一致的管理角色和职责。

如果你使用分层流程,但不想设置自定义管理者 agent,也可以为管理者指定语言模型:

from crewai import LLM
manager_llm = LLM(model="gpt-4o")
crew = Crew(
agents=[researcher, writer],
tasks=[task],
process=Process.hierarchical,
manager_llm=manager_llm
)