使用多智能体系统和 CrewAI 简化书籍创作。
微信搜索关注《AI科技论谈》
多智能体系统(MAS)作为人工智能的重要应用,正在成为热门趋势。它通过将任务分配给多个专门单元,有效简化了复杂工作流程。例如在写作中,多智能体系统可完成构思、搭建框架、撰写章节和校对。
本文聚焦CrewAI,介绍其如何简化书籍创作流程。
1 多智能体系统(MAS)
多智能体系统(MAS)指的是多个自主智能体协同合作,以实现共同目标的一种框架。其中,每个智能体聚焦于特定角色,并且会和其他智能体相互协作。
在需要多元视角、多阶段推进的任务中,MAS 的效能极为凸显,例如书籍创作。
在 CrewAI 中,智能体被赋予了独特的角色与目标,以此来模拟人类团队的专业分工,让书籍创作从规划、写作到编辑、出版的全流程组织管理更为高效。
2 书籍创作流程拆解
为简化流程,可将书籍创作划分为五个主要阶段,并为每个阶段分配特定智能体:
-
规划:构思创意、拟定大纲,设计角色与场景。
-
写作:依据规划起草各章节内容。
-
编辑:完善草稿,确保内容连贯、风格优化。
-
事实核查:核实内容的准确性。
-
出版:对书稿排版,为出版做准备。
提示: 根据具体需求,你可以调整智能体的数量和职责。例如,使用ChatGPT对这些步骤进行头脑风暴,并规划智能体的分工。如果你希望在Crew AI中实现类似的多智能体系统,可以参考以下提示词:
“我想在Crew AI中构建一个用于写书的多智能体系统,让多个智能体并行工作完成创作。请拆解整个书籍创作过程,并明确每个阶段所需的智能体数量。”
3 各智能体的作用
-
规划智能体:流程战略核心,构思主题、大纲,确定角色、场景等关键元素。
-
职责:定主题体裁、创大纲、设计角色与世界观。
-
-
写作智能体(核心):将规划化为文字,起草章节,保证故事连贯、元素融合。
-
职责:按大纲写章(演示每章 1000 字,可按需提示),融入叙事结构。
-
-
编辑智能体:润色书稿,确保文本清晰、连贯、风格一致。
-
职责:查语法、优化语气风格。
-
-
事实核查智能体:保障非虚构或技术类内容事实准确。
-
职责:核实事实文献、验证数据一致性。
-
-
出版智能体:确定书稿数字或印刷版最终格式。
-
职责:按标准排版、完成文档整理。
-
4 实现多智能体系统的代码示例
CrewAI 提供了定义智能体、分配任务和管理工作流的框架。以下是用于书籍创作的多智能体系统的实现代码:
代码示例:
!pip3 install crewai
import os
from crewai import Agent, Task, Crew, Process
# 定义智能体
# 设置OpenAI API的环境变量
os.environ["OPENAI_API_KEY"] = "Paste your key here"
os.environ["OPENAI_MODEL_NAME"] = "gpt-4o"
planning_agent = Agent(
role="Planning Agent",
goal="Develop the book's concept, outline, characters, and world.",
backstory="An experienced author specializing in planning and structuring novels.",
verbose=True
)
# 定义写作智能体
writing_agent = Agent(
role="Writing Agent",
goal="Write detailed chapters based on the provided outline and character details.",
backstory="A creative writer adept at bringing stories to life.",
verbose=True
)
# 定义编辑智能体
editing_agent = Agent(
role="Editing Agent",
goal="Edit the written chapters for clarity, coherence, and grammatical accuracy.",
backstory="A meticulous editor with an eye for detail.",
verbose=True
)
# 定义事实核查智能体
fact_checking_agent = Agent(
role="Fact-Checking Agent",
goal="Verify the accuracy of all factual information presented in the book.",
backstory="A diligent researcher ensuring all facts are correct.",
verbose=True
)
# 定义出版智能体
publishing_agent = Agent(
role="Publishing Agent",
goal="Format the manuscript and prepare it for publication.",
backstory="An expert in publishing standards and formatting.",
verbose=True
)
# 为每个智能体定义任务
tasks = [
Task(
description="Develop the book's concept, outline, characters, and world.",
expected_output="A comprehensive plan including theme, genre, outline, character profiles, and world details.",
agent=planning_agent
),
Task(
description="Write detailed chapters based on the provided outline and character details.Each chapter should be 1000 words atleast",
expected_output="Drafts of all chapters in the book.",
agent=writing_agent
),
Task(
description="Edit the written chapters for clarity, coherence, and grammatical accuracy.",
expected_output="Edited versions of all chapters.",
agent=editing_agent
),
Task(
description="Verify the accuracy of all factual information presented in the book.",
expected_output="A report confirming the accuracy of all facts or detailing necessary corrections.",
agent=fact_checking_agent
),
Task(
description="Format the manuscript and prepare it for publication.",
expected_output="A finalized manuscript ready for publication.",
agent=publishing_agent
)
]
# 组合所有智能体
book_writing_crew = Crew(
agents=[planning_agent, writing_agent, editing_agent, fact_checking_agent, publishing_agent],
tasks=tasks,
process=Process.sequential,
verbose=True
)
# 执行工作流程
if __name__ == "__main__":
result = book_writing_crew.kickoff()
print("Final Manuscript:", result)
输出:
我们会得到书籍的最终书稿,还能看到不同AI智能体的输出结果。以下是一些截图:


5 关键要点
-
专业化智能体:每个智能体专注于特定任务,确保高质量的输出。
-
工作流程管理:任务按顺序或并行组织,以实现最高效率。
-
可定制性:CrewAI允许你根据各种内容类型调整系统。
-
可扩展性:随着项目的发展,可以添加更多智能体或任务。
6 结语
在书籍创作中运用多智能体系统,充分展现了人工智能优化创意工作流程的强大能力。借助 CrewAI,我们能够在确保创作质量与连贯性的同时,实现复杂流程的自动化操作。无论你是专注于人工智能开发,还是投身内容创作领域,这种方法都为应对大型项目提供了一种高效且具备可扩展性的途径。
推荐书单
《一本书读懂AI Agent:技术、应用与商业 智能体》
这是一部从技术原理、行业应用、商业价值、投资创业、发展趋势5个维度讲解AI Agent的著作,具有科普书和商业书的双重属性。
本书首先详细介绍了AI Agent的技术路径及其在11大领域的应用,丰富的应用案例可以帮助读者深度理解AI Agent产品形态与服务方式;然后深入探讨了AI Agent的商业价值与商业生态,并对AI Agent的企业级应用和投资创业做了很多思考与总结,能够带给读者应用与创业方面的启发。本书将技术、应用及商业理念融会贯通,理论性与实用性兼具,是一本适合业内外人士快速了解AI Agent、提升行业认知的综合指南,得到了很多行业人士、专家及创业者的一致好评。
5折购买链接:https://item.jd.com/14306237.html
精彩回顾
DeepSeek R1横空出世,超越OpenAI o1,教你用Ollama跑起来
AI编程助手Cline发布3.1版本,剑指取代Cursor和Windsurf