AutoGen框架进行多智能体协作—反思与提升博客文章质量(三)

1. 实践场景

在这里插入图片描述

两个代理之间通过互相反思以提升博客质量。其中一个代理作为修改意见提出者,另一个代理为写作者。写作者依据要求进行内容创作,评论员则提出修改要求,作者再根据要求对内容进行重新调整。

2. 代码实践

本节学习内容:传送门

2.1 准备环境

llm_config = {"model": "gpt-3.5-turbo"}

2.2 明确任务

task = '''
        Write a concise but engaging blogpost about
       DeepLearning.AI. Make sure the blogpost is
       within 100 words.
       '''

2.3 创建一个writer代理

import autogen

writer = autogen.AssistantAgent(
    name="Writer",
    system_message="You are a writer. You write engaging and concise " 
        "blogpost (with title) on given topics. You must polish your "
        "writing based on the feedback you receive and give a refined "
        "version. Only return your final work without additional comments.",
    llm_config=llm_config,
)

reply = writer.generate_reply(messages=[{"content": task, "role": "user"}])
print(reply)

输出如下:

Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.

2.4 创建一个critic代理

critic = autogen.AssistantAgent(
    name="Critic",
    is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
    llm_config=llm_config,
    system_message="You are a critic. You review the work of "
                "the writer and provide constructive "
                "feedback to help improve the quality of the content.",
)
res = critic.initiate_chat(
    recipient=writer,
    message=task,
    max_turns=2,
    summary_method="last_msg"
)

输出如下:

Critic (to Writer):


        Write a concise but engaging blogpost about
       DeepLearning.AI. Make sure the blogpost is
       within 100 words.
       

--------------------------------------------------------------------------------
Writer (to Critic):

Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.

--------------------------------------------------------------------------------
Critic (to Writer):

This blogpost effectively conveys the key features of DeepLearning.AI in a concise and engaging manner. The title is attention-grabbing and sets the tone for the content. The content provides a brief overview of the platform, mentioning the founder, courses offered, interactive learning experience, and community aspect. To enhance the blogpost, you could consider adding specific examples of the courses available or success stories from learners who have benefited from DeepLearning.AI. This would make the content more relatable and compelling to readers. Additionally, including a call to action at the end encouraging readers to explore the platform further would help drive engagement. Great job overall!

--------------------------------------------------------------------------------
Writer (to Critic):

Title: Unleash Your Potential with DeepLearning.AI

Embark on an AI journey with DeepLearning.AI, founded by AI expert Andrew Ng. Master computer vision, NLP, and more through interactive courses and projects. Join a global community of learners and professionals to enhance your skills. From beginners to experts, DeepLearning.AI offers a path to excel in AI. Explore courses like "Neural Networks and Deep Learning" or dive into "Sequence Models." Hear success stories and take your AI skills to the next level today. Don't miss out—join DeepLearning.AI and pave the way to a successful AI career.

--------------------------------------------------------------------------------

可以看到经过两轮拉扯,critic给writer明确了任务,writer根据任务要求给critic返回了初稿,critic根据初稿内容提出了修改意见,writer最后根据意见生成了修改结果。

2.5 对其他细节进行堆叠

如图,我们对自己生成的内容可能要进行验证,如确保对检索内容的重要性核对、对生成内容的合法性审查、对生成内容的道德审查以及最终要进行汇总的Reviewer,这几个阶段分别是critic提出意见时候可以参考的,因此我们需要对工作流程进行细化和堆叠。
在这里插入图片描述

2.5.1 嵌套聊天

创建SEO审查Agent

SEO_reviewer = autogen.AssistantAgent(
    name="SEO Reviewer",
    llm_config=llm_config,
    system_message="You are an SEO reviewer, known for "
        "your ability to optimize content for search engines, "
        "ensuring that it ranks well and attracts organic traffic. " 
        "Make sure your suggestion is concise (within 3 bullet points), "
        "concrete and to the point. "
        "Begin the review by stating your role.",
)

创建内容合法性审查Agent

legal_reviewer = autogen.AssistantAgent(
    name="Legal Reviewer",
    llm_config=llm_config,
    system_message="You are a legal reviewer, known for "
        "your ability to ensure that content is legally compliant "
        "and free from any potential legal issues. "
        "Make sure your suggestion is concise (within 3 bullet points), "
        "concrete and to the point. "
        "Begin the review by stating your role.",
)

创建道德伦理审查Agent

ethics_reviewer = autogen.AssistantAgent(
    name="Ethics Reviewer",
    llm_config=llm_config,
    system_message="You are an ethics reviewer, known for "
        "your ability to ensure that content is ethically sound "
        "and free from any potential ethical issues. " 
        "Make sure your suggestion is concise (within 3 bullet points), "
        "concrete and to the point. "
        "Begin the review by stating your role. ",
)

创建meta reviewer整合建议Agent

meta_reviewer = autogen.AssistantAgent(
    name="Meta Reviewer",
    llm_config=llm_config,
    system_message="You are a meta reviewer, you aggragate and review "
    "the work of other reviewers and give a final suggestion on the content.",
)

2.5.2 协调嵌套对话以解决任务

def reflection_message(recipient, messages, sender, config):
    return f'''Review the following content. 
            \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}'''

review_chats = [
    {
     "recipient": SEO_reviewer, 
     "message": reflection_message, 
     "summary_method": "reflection_with_llm",
     "summary_args": {"summary_prompt" : 
        "Return review into as JSON object only:"
        "{'Reviewer': '', 'Review': ''}. Here Reviewer should be your role",},
     "max_turns": 1},
    {
    "recipient": legal_reviewer, "message": reflection_message, 
     "summary_method": "reflection_with_llm",
     "summary_args": {"summary_prompt" : 
        "Return review into as JSON object only:"
        "{'Reviewer': '', 'Review': ''}.",},
     "max_turns": 1},
    {"recipient": ethics_reviewer, "message": reflection_message, 
     "summary_method": "reflection_with_llm",
     "summary_args": {"summary_prompt" : 
        "Return review into as JSON object only:"
        "{'reviewer': '', 'review': ''}",},
     "max_turns": 1},
     {"recipient": meta_reviewer, 
      "message": "Aggregrate feedback from all reviewers and give final suggestions on the writing.", 
     "max_turns": 1},
]

2.5.3 将子任务整合并设置初始对话

critic.register_nested_chats(
    review_chats,
    trigger=writer,
)
res = critic.initiate_chat(
    recipient=writer,
    message=task,
    max_turns=2,
    summary_method="last_msg"
)

输出如下:

Critic (to Writer):


        Write a concise but engaging blogpost about
       DeepLearning.AI. Make sure the blogpost is
       within 100 words.
       

--------------------------------------------------------------------------------
Writer (to Critic):

Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
Critic (to SEO Reviewer):

Review the following content. 
            

 Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.

--------------------------------------------------------------------------------
SEO Reviewer (to Critic):

As an SEO reviewer:

- Include target keywords like "DeepLearning.AI courses," "Andrew Ng AI courses," "deep learning online classes" to improve search engine visibility.
- Add structured data markup for course details, instructor information, and reviews to enhance search results appearance with rich snippets.
- Encourage users to engage by adding a clear call-to-action like "Enroll now" or "Start learning today" to improve user interaction and potentially increase click-through rates.

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
Critic (to Legal Reviewer):

Review the following content. 
            

 Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.
Context: 
{'Reviewer': 'SEO Specialist', 'Review': '- Include target keywords like "DeepLearning.AI courses," "Andrew Ng AI courses," "deep learning online classes" to improve search engine visibility. - Add structured data markup for course details, instructor information, and reviews to enhance search results appearance with rich snippets. - Encourage users to engage by adding a clear call-to-action like "Enroll now" or "Start learning today" to improve user interaction and potentially increase click-through rates.'}

--------------------------------------------------------------------------------
Legal Reviewer (to Critic):

As a Legal Reviewer:

- Ensure compliance with intellectual property rights by verifying that all content related to courses, instructors, and platform details does not infringe on any trademarks or copyrights.
- Confirm that any testimonials or reviews included are authentic and not fabricated to avoid potential false advertising claims.
- Review the disclaimer regarding the outcomes of the courses to prevent any misleading claims about guaranteed career advancements.

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
Critic (to Ethics Reviewer):

Review the following content. 
            

 Title: Unveiling the Power of DeepLearning.AI

Step into the world of artificial intelligence with DeepLearning.AI. Founded by renowned AI expert Andrew Ng, this platform offers top-notch courses to master deep learning. From computer vision to natural language processing, DeepLearning.AI covers it all. Gain valuable skills through interactive lessons and hands-on projects, and join a thriving community of learners worldwide. Whether you're a beginner or seasoned professional, DeepLearning.AI equips you with the knowledge to excel in the AI field. Elevate your career and unleash the potential of AI with DeepLearning.AI today.
Context: 
{'Reviewer': 'SEO Specialist', 'Review': '- Include target keywords like "DeepLearning.AI courses," "Andrew Ng AI courses," "deep learning online classes" to improve search engine visibility. - Add structured data markup for course details, instructor information, and reviews to enhance search results appearance with rich snippets. - Encourage users to engage by adding a clear call-to-action like "Enroll now" or "Start learning today" to improve user interaction and potentially increase click-through rates.'}
{'Reviewer': 'Legal Reviewer', 'Review': '- Ensure compliance with intellectual property rights by verifying that all content related to courses, instructors, and platform details does not infringe on any trademarks or copyrights. - Confirm that any testimonials or reviews included are authentic and not fabricated to avoid potential false advertising claims. - Review the disclaimer regarding the outcomes of the courses to prevent any misleading claims about guaranteed career advancements.'}

--------------------------------------------------------------------------------
Ethics Reviewer (to Critic):

**Ethics Reviewer**

- Ensure that any claims made about the effectiveness of DeepLearning.AI courses are evidence-based and avoid exaggeration to prevent misleading learners.
- Verify that the platform accurately represents the qualifications and expertise of the instructors to maintain transparency and trust with the learners.
- Review the data privacy and security measures in place to protect the personal information of users and ensure compliance with data protection regulations.

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
Critic (to Meta Reviewer):

Aggregrate feedback from all reviewers and give final suggestions on the writing.
Context: 
{'Reviewer': 'SEO Specialist', 'Review': '- Include target keywords like "DeepLearning.AI courses," "Andrew Ng AI courses," "deep learning online classes" to improve search engine visibility. - Add structured data markup for course details, instructor information, and reviews to enhance search results appearance with rich snippets. - Encourage users to engage by adding a clear call-to-action like "Enroll now" or "Start learning today" to improve user interaction and potentially increase click-through rates.'}
{'Reviewer': 'Legal Reviewer', 'Review': '- Ensure compliance with intellectual property rights by verifying that all content related to courses, instructors, and platform details does not infringe on any trademarks or copyrights. - Confirm that any testimonials or reviews included are authentic and not fabricated to avoid potential false advertising claims. - Review the disclaimer regarding the outcomes of the courses to prevent any misleading claims about guaranteed career advancements.'}
{'reviewer': 'Ethics Reviewer', 'review': '- Ensure that any claims made about the effectiveness of DeepLearning.AI courses are evidence-based and avoid exaggeration to prevent misleading learners. - Verify that the platform accurately represents the qualifications and expertise of the instructors to maintain transparency and trust with the learners. - Review the data privacy and security measures in place to protect the personal information of users and ensure compliance with data protection regulations.'}

--------------------------------------------------------------------------------
Meta Reviewer (to Critic):

After aggregating the feedback from the SEO Specialist, Legal Reviewer, and Ethics Reviewer, here are the key points to consider:

1. SEO: Incorporate target keywords and structured data markup to enhance search engine visibility and user engagement. Include clear call-to-action phrases to improve interaction and click-through rates.

2. Legal: Ensure compliance with intellectual property rights, authenticity of testimonials, and avoid misleading claims in the disclaimer regarding course outcomes to prevent legal issues related to false advertising.

3. Ethics: Base claims about course effectiveness on evidence, accurately represent instructor qualifications, and prioritize data privacy and security to maintain transparency and trust with learners.

Final Suggestions:
- Implement SEO recommendations to boost visibility and engagement.
- Double-check all content for intellectual property compliance and authenticity.
- Focus on evidence-based claims and transparent representation of instructors.
- Prioritize data privacy and security measures.

Overall, the writing should prioritize transparency, accuracy, and user trust. By addressing the suggestions of all reviewers, the content can be enhanced to meet both regulatory requirements and user expectations.

--------------------------------------------------------------------------------
Critic (to Writer):

After aggregating the feedback from the SEO Specialist, Legal Reviewer, and Ethics Reviewer, here are the key points to consider:

1. SEO: Incorporate target keywords and structured data markup to enhance search engine visibility and user engagement. Include clear call-to-action phrases to improve interaction and click-through rates.

2. Legal: Ensure compliance with intellectual property rights, authenticity of testimonials, and avoid misleading claims in the disclaimer regarding course outcomes to prevent legal issues related to false advertising.

3. Ethics: Base claims about course effectiveness on evidence, accurately represent instructor qualifications, and prioritize data privacy and security to maintain transparency and trust with learners.

Final Suggestions:
- Implement SEO recommendations to boost visibility and engagement.
- Double-check all content for intellectual property compliance and authenticity.
- Focus on evidence-based claims and transparent representation of instructors.
- Prioritize data privacy and security measures.

Overall, the writing should prioritize transparency, accuracy, and user trust. By addressing the suggestions of all reviewers, the content can be enhanced to meet both regulatory requirements and user expectations.

--------------------------------------------------------------------------------
Writer (to Critic):

Title: Unleashing the Potential of DeepLearning.AI Responsibly

Dive into the realm of AI education with DeepLearning.AI, led by AI pioneer Andrew Ng. Master cutting-edge deep learning skills in computer vision, NLP, and more through interactive courses and projects. Join a global community of learners and propel your AI career forward. Incorporating expert feedback, we ensure compliance with legal and ethical standards. Discover the power of AI responsibly – with clear CTAs, evidence-based claims, and a commitment to data privacy. Elevate your skills with confidence and transparency, and let DeepLearning.AI be your gateway to success in the world of AI.

--------------------------------------------------------------------------------

2.6 获取摘要

print(res.summary)

输出如下:

Title: Unleashing the Potential of DeepLearning.AI Responsibly

Dive into the realm of AI education with DeepLearning.AI, led by AI pioneer Andrew Ng. Master cutting-edge deep learning skills in computer vision, NLP, and more through interactive courses and projects. Join a global community of learners and propel your AI career forward. Incorporating expert feedback, we ensure compliance with legal and ethical standards. Discover the power of AI responsibly – with clear CTAs, evidence-based claims, and a commitment to data privacy. Elevate your skills with confidence and transparency, and let DeepLearning.AI be your gateway to success in the world of AI.

3. 总结

多轮对话是多代理的重点核心内容,需要注意的是,多代理之间的对话轮次和约束条件是内容管理的重中之重,因此对于对话质量和效率的把控,很大程度取决于base模型,其次是子任务规划,如何让任务合理合规非常重要。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

l8947943

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值