Skip to content

Commit f85b6ff

Browse files
committed
教程编写
1 parent 0938259 commit f85b6ff

12 files changed

Lines changed: 3379 additions & 27 deletions

File tree

.github/workflows/deploy-mdbook.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
with:
2525
mdbook-version: 'latest'
2626

27+
# 安装二进制安装器并下载 mdbook-mermaid
28+
- name: Install mdbook-mermaid
29+
run: |
30+
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
31+
cargo binstall -y mdbook-mermaid
32+
2733
- name: Build mdBook
2834
run: mdbook build book/ # 假设 book.toml 位于 book/ 目录
2935

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ __pycache__/
1111
.vscode/
1212
.idea/
1313
.trae/
14+
.obsidian/
1415

1516
# tmp
1617
tmp/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
Tiny Agent 遵循**由浅入深、循序渐进**的设计理念,不依赖复杂框架,从一次最简单的大模型调用开始,逐步构建出一个具备知识、工具、推理、记忆和协作能力的智能体。适合已掌握 Python 基础、想掌握AI Agent底层原理的开发者。
66

7+
![](./book/src/images/snapshot-v0.2.gif)
8+
79
## 项目特点
810

911
* 🚀 极简轻量化实现:剔除冗余封装,代码注释完整,单文件模块易阅读、逐行可拆解学习

book/book.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22
title = "极简智能体:AI Agent 渐进式开发实战"
33
authors = ["leon"]
44
language = "cn"
5+
6+
[preprocessor]
7+
8+
[preprocessor.mermaid]
9+
command = "mdbook-mermaid"
10+
11+
[output]
12+
13+
[output.html]
14+
additional-js = ["mermaid.min.js", "mermaid-init.js"]

book/mermaid-init.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
(() => {
6+
const darkThemes = ['ayu', 'navy', 'coal'];
7+
const lightThemes = ['light', 'rust'];
8+
9+
const classList = document.getElementsByTagName('html')[0].classList;
10+
11+
let lastThemeWasLight = true;
12+
for (const cssClass of classList) {
13+
if (darkThemes.includes(cssClass)) {
14+
lastThemeWasLight = false;
15+
break;
16+
}
17+
}
18+
19+
const theme = lastThemeWasLight ? 'default' : 'dark';
20+
mermaid.initialize({ startOnLoad: true, theme });
21+
22+
// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
23+
24+
for (const darkTheme of darkThemes) {
25+
document.getElementById(darkTheme).addEventListener('click', () => {
26+
if (lastThemeWasLight) {
27+
window.location.reload();
28+
}
29+
});
30+
}
31+
32+
for (const lightTheme of lightThemes) {
33+
document.getElementById(lightTheme).addEventListener('click', () => {
34+
if (!lastThemeWasLight) {
35+
window.location.reload();
36+
}
37+
});
38+
}
39+
})();

book/mermaid.min.js

Lines changed: 2609 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# 第一部分:模型基础与全栈通信(基础篇)
77

88
- [第一章:Hello LLM(你好,大模型)](./chapter_01.md)
9-
- [第二章:Streaming Web(流式 Web 输出](./chapter_02.md)
9+
- [第二章:Streaming Web(Web 流式输出](./chapter_02.md)
1010

1111

1212
# 附录

book/src/chapter_01.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 第一章:Hello LLM(你好,大模型)
22

3-
> **导语**:本章是 Tiny Agent 的起点,不用前端、不做多轮历史,只先跑通“用户输入一句话,大模型回复一句话”的最小闭环。
3+
> **导语**:本章是 Tiny Agent 的起点,不用前端、不做多轮历史,只先跑通“用户输入一句话,大模型回复一句话”的最小闭环。完成本章后,你将掌握大模型的 API 调用方式,为 Agent 开发奠定基础。
44
>
55
> **源码版本**[v0.1](https://github.com/leonlucc/tiny-agent/tree/v0.1)
66
@@ -42,7 +42,7 @@ AI: 你好,我是一个可以理解和生成文本的 AI 助手。
4242
3. 把用户输入包装成一条 `user` 消息,调用 `client.chat.completions.create()`
4343
4. 从响应中取出 `response.choices[0].message.content` 并打印到终端。
4444

45-
本版本没有 Web UI、没有多轮对话,它只解决一个问题**确认代码能够真正访问 LLM,并拿到一次回复**
45+
这个版本没有 Web UI、没有多轮对话,它只做一件事**验证代码能成功调用LLM并获取回复**
4646
```mermaid
4747
flowchart LR
4848
User[CLI 终端<br/>用户输入/输出] -->|输入| App[Python 应用<br/>simple_call.py]
@@ -168,10 +168,13 @@ LLM_API_KEY=your_api_key_here
168168
LLM_BASE_URL=https://api.deepseek.com
169169
LLM_MODEL=deepseek-v4-flash
170170
```
171-
安全提醒:`.env` 文件包含 API Key 等敏感信息,切记将其加入 .gitignore,避免意外提交到版本控制系统。
171+
> **💡 小贴士:安全提醒**
172+
>
173+
> `.env` 文件包含 API Key 等敏感信息,切记将其加入 .gitignore,避免意外提交到版本控制系统。
172174
173-
💡 小贴士:如何快速获取 API Key?
174-
>本项目兼容标准的 OpenAI 协议,国内外的诸多主流平台都可以无缝接入。推荐注册并使用国内极速且高性价比的平台,例如 [DeepSeek](https://platform.deepseek.com/)[硅基流动](https://siliconflow.cn/) 等 API 聚合服务。注册获取 `sk-...` 格式的密钥后,直接填入 .env 即可无缝运行。
175+
> **💡 小贴士:如何快速获取 API Key?**
176+
>
177+
> 本项目兼容标准的 OpenAI 协议,国内外的诸多主流平台都可以无缝接入。推荐注册并使用国内极速且高性价比的平台,例如 [DeepSeek](https://platform.deepseek.com/)[硅基流动](https://siliconflow.cn/) 等 API 聚合服务。注册获取 `sk-...` 格式的密钥后,直接填入 .env 即可无缝运行。
175178
176179

177180
### 4.4 运行入口
@@ -310,7 +313,7 @@ def main() -> None:
310313

311314
## 5. Git Diff 导读
312315

313-
本版本相对于空工程,核心变化是新增 `backend` 目录,上文已经详细讲解,完整代码已提交至 GitHub 仓库,你可以切换到 `v0.0.1` Tag查看或直接运行 `git checkout v0.0.1`查看。
316+
本版本相对于空工程,核心变化是新增 `backend` 目录,上文已经详细讲解,完整代码已提交至 GitHub 仓库,你可以切换到 `v0.1` Tag查看或直接运行 `git checkout v0.1`查看。
314317

315318
---
316319

@@ -365,7 +368,7 @@ messages=[{"role": "user", "content": message}]
365368

366369
### 6.7 为什么错误处理非常简单?
367370

368-
v0.0.1 的目标是跑通闭环,不是建立完整的错误分类体系。
371+
本章的目标是跑通闭环,不是建立完整的错误分类体系。
369372

370373
因此代码只做两类处理:
371374

@@ -390,6 +393,6 @@ v0.0.1 的目标是跑通闭环,不是建立完整的错误分类体系。
390393

391394
---
392395

393-
下一章,我们会在这个基础上引入 Chat History,让 Tiny Agent 从“一问一答”走向“连续对话”
396+
下一章,我们会在这个基础上引入 Web 流式输出,让 Tiny Agent 从一问一答的命令行,走向逐字呈现的浏览器
394397

395-
[→ 进入第二章:Chat(基础对话](./chapter_02.md)
398+
[→ 进入第二章:Streaming Web(Web 流式输出](./chapter_02.md)

0 commit comments

Comments
 (0)