Leanpub Header

Skip to main content

从零构建 AI Agent

16 步从 Hello World 到 Skill 插件系统——基于真实项目的实战笔记,附完整教学代码

从零构建 AI Agent

16 章手写一个 CLI Agent。从 Hello World 到 Skill 插件系统,只用 Python 标准库 + OpenAI SDK。每章附真实项目踩坑笔记——来自 git 提交历史的 bug、设计失误和凌晨调试的教训。读完你会理解 Agent 的底层运作方式,而非只是会用某个框架。

Minimum price

$7.99

$14.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

这不是一本讲 LangChain 的书,也不是一本 prompt 模板合集。

这是一本带你从零写 AI Agent 的书。

我写了一个叫 Nimo 的 CLI Agent——用自然语言对话来完成 TAPD 项目管理、SVN版本控制等日常操作。然后用这个项目的实战经验,提炼出一套通用的 Agent 开发方法,写成了这本书。

全书用一个叫 MiniAgent 的教学项目贯穿始终:从 40 行代码的 Hello World 开始,每章解决一个真实问题——工具注册、多轮循环、记忆管理、执行引擎、Skill 插件系统、流式响应、安全加固——16 章下来,你会得到一个架构完整的 Agent。

只用 Python 标准库 + OpenAI SDK。没有框架,没有魔法。

每章末尾的"实战笔记"是本书最有价值的部分——来自 Nimo 项目真实 git 提交历史的bug、设计失误、凌晨调试的教训,以及"如果重来一次我会换种写法"的反思。附录中的 10个踩坑清单,每个都经历了"发现→定位→修复→复盘"的完整过程。

读完这本书,你不会成为"XX 框架专家",但你会真正理解 Agent 的底层运作方式。以后再用任何框架,你能一眼看穿它的设计意图和局限。

适合谁:会写 Python 异步代码、用过 LLM API、想真正理解 Agent 原理而非只会调框架的开发者。

全书目录

第 1 章:为什么写 Nimo
第 2 章:Hello World Agent
第 3 章:工具注册系统
第 4 章:Agent 核心循环
第 5 章:对话记忆管理
第 6 章:配置与用户画像
第 7 章:执行引擎
第 8 章:意图工具设计
第 9 章:Skill 插件系统
第 10 章:定时任务系统
第 11 章:动态代码执行
第 12 章:CLI 体验打磨
第 13 章:流式响应
第 14 章:Agent 测试策略
第 15 章:错误韧性设计
第 16 章:安全与加固
附录:DeepSeek API 速查 · 项目结构参考 · 10 个真实踩坑清单 · 教学代码索引

Author

About the Author

傅政

傅政,13 年软件研发老兵,通信工程出身,现任某视讯科技公司终端研发负责人,带领全平台客户端团队做视频会议产品。

日常工作重度依赖 TAPD 和 SVN——查需求、翻任务、填工时、看提交日志。这些操作重复且琐碎,于是写了 Nimo 这个 CLI Agent,用自然语言一句搞定原本需要几次手动操作的事。

这本书来自 Nimo 的真实开发过程。不是翻译的框架文档,不是拼凑的 prompt 模板——是从 40 行代码的 Hello World 到完整的 Skill 插件系统,每一步都有 git 提交历史为证。

联系作者:fuzheng@icloud.com

Contents

Table of Contents

  • 第 1 章:为什么写 Nimo
  • 第 2 章:Hello World Agent
  • 第 3 章:工具注册系统
  • 第 4 章:Agent 核心循环
  • 第 5 章:对话记忆管理
  • 第 6 章:配置与用户画像
  • 第 7 章:执行引擎
  • 第 8 章:意图工具设计
  • 第 9 章:Skill 插件系统
  • 第 10 章:定时任务系统
  • 第 11 章:动态代码执行
  • 第 12 章:CLI 体验打磨
  • 第 13 章:流式响应
  • 第 14 章:Agent 测试策略
  • 第 15 章:错误韧性设计
  • 第 16 章:安全与加固
  • 附录:API 速查 · 项目结构 · 踩坑清单 · 教学代码索引
第 1 章:为什么写 Nimo
  • 1.1 Nimo 能做什么
  • 1.2 Nimo 的架构全景
  • 1.3 Agent 的三要素
  • 1.4 Function Calling:让 LLM 能“动手“
  • 1.5 为什么不用框架
  • 1.6 主线项目:MiniAgent
  • 1.7 每章的“Nimo 实战笔记“
  • 1.8 这本书不做什么
  • 1.9 你需要准备什么

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub