在CrewAI中设置特定代理为经理

CrewAI 允许用户将特定代理设置为团队的经理,从而提供对任务管理和协调的更多控制。 此功能使管理角色的定制能够更好地适应您项目的需求。

使用 manager_agent 属性

自定义管理代理

manager_agent 属性允许您定义一个自定义代理来管理团队。该代理将监督整个过程,确保任务高效完成并达到最高标准。

示例

Code
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()

自定义管理代理的好处

  • 增强控制: 根据项目的具体需求定制管理方法。
  • 改进的协调:由经验丰富的代理确保高效的任务协调和管理。
  • 可定制的管理: 定义与项目目标一致的管理角色和职责。

设置管理器LLM

如果您正在使用分层过程并且不想设置自定义管理器代理,您可以指定管理器的语言模型:

Code
from langchain_openai import ChatOpenAI

manager_llm = ChatOpenAI(model_name="gpt-4")

crew = Crew(
    agents=[researcher, writer],
    tasks=[task],
    process=Process.hierarchical,
    manager_llm=manager_llm
)

在使用分层过程时,必须设置manager_agentmanager_llm

这个页面有帮助吗?