协调模式下,团队负责人将任务分配给团队成员,并将他们的产出整合为一份连贯的响应。

协调模式如何运作

在“协调”模式下:

  1. 团队接收用户查询
  2. 团队负责人分析查询并决定如何将其分解为子任务
  3. 团队负责人将具体任务分配给合适的团队成员
  4. 团队成员完成分配的任务并返回结果
  5. 团队负责人将所有产出整合为最终的、连贯的响应

此模式非常适合需要多种专业技能、协调和不同输出来进行综合的复杂任务。

1

创建一个协调模式团队

创建一个文件 content_team.py

content_team.py

searcher = Agent(
    name="Searcher",
    role="Searches the top URLs for a topic",
    instructions=[
        "Given a topic, first generate a list of 3 search terms related to that topic.",
        "For each search term, search the web and analyze the results.Return the 10 most relevant URLs to the topic.",
        "You are writing for the New York Times, so the quality of the sources is important.",
    ],
    tools=[DuckDuckGoTools()],
    add_datetime_to_instructions=True,
)
writer = Agent(
    name="Writer",
    role="Writes a high-quality article",
    description=(
        "You are a senior writer for the New York Times. Given a topic and a list of URLs, "
        "your goal is to write a high-quality NYT-worthy article on the topic."
    ),
    instructions=[
        "First read all urls using `read_article`."
        "Then write a high-quality NYT-worthy article on the topic."
        "The article should be well-structured, informative, engaging and catchy.",
        "Ensure the length is at least as long as a NYT cover story -- at a minimum, 15 paragraphs.",
        "Ensure you provide a nuanced and balanced opinion, quoting facts where possible.",
        "Focus on clarity, coherence, and overall quality.",
        "Never make up facts or plagiarize. Always provide proper attribution.",
        "Remember: you are writing for the New York Times, so the quality of the article is important.",
    ],
    tools=[Newspaper4kTools()],
    add_datetime_to_instructions=True,
)

editor = Team(
    name="Editor",
    mode="coordinate",
    model=OpenAIChat("gpt-4o"),
    members=[searcher, writer],
    description="You are a senior NYT editor. Given a topic, your goal is to write a NYT worthy article.",
    instructions=[
        "First ask the search journalist to search for the most relevant URLs for that topic.",
        "Then ask the writer to get an engaging draft of the article.",
        "Edit, proofread, and refine the article to ensure it meets the high standards of the New York Times.",
        "The article should be extremely articulate and well written. "
        "Focus on clarity, coherence, and overall quality.",
        "Remember: you are the final gatekeeper before the article is published, so make sure the article is perfect.",
    ],
    add_datetime_to_instructions=True,
    add_member_tools_to_system_message=False,  # This can be tried to make the agent more consistently get the transfer tool call correct
    enable_agentic_context=True,  # Allow the agent to maintain a shared context and send that to members.
    share_member_interactions=True,  # Share all member responses with subsequent member requests.
    show_members_responses=True,
    markdown=True,
)
editor.print_response("Write an article about latest developments in AI.")
2

运行团队

安装库

pip install openai duckduckgo-search newspaper4k lxml_html_clean

运行团队

python content_team.py

定义成功标准

您可以通过为团队指定成功标准来指导协调员:

strategy_team = Team(
    members=[market_analyst, competitive_analyst, strategic_planner],
    mode="coordinate",
    name="Strategy Team",
    description="A team that develops strategic recommendations",
    success_criteria="Produce actionable strategic recommendations supported by market and competitive analysis",
)

response = strategy_team.run(
    "Develop a market entry strategy for our new AI-powered healthcare product"
)