Skip to content

Commit b2655f5

Browse files
committed
docs: Update ecosystem integrations and refine grammar docs based on Nexa v0.8 releases
1 parent cab8ed0 commit b2655f5

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

docs/part1_basic.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ agent FriendlyBot {
2828
- **`role`** (角色语义场):定义该代理的系统角色(System Persona)。这不仅仅是一个标签,在底层编译为 Python 运行时时,它会作为系统提示词的极高权重顶层注入点,赋能模型的上下文边界。
2929
- **`model`** (动态智脑映射):**(极具破坏性优势的特性)**原生的模型硬线链接。这使得我们可以在不同的代理之间按需无缝切换背后的引擎(从 `gpt-4` 到轻量的开源大模型)。在其它框架中,更改模型往往意味着大改 `LLMConfig`,但在 Nexa 中只需改动这一行字符串。
3030
- **`prompt`** (任务执行描述):这是驱动模型行动的核心指令区,支持多行纯文本字面量表达。在这里,你不需要处理转义甚至复杂的 Token 拼接,一切都自然发生。
31+
- **`memory`** (记忆持久化):代理的记忆模式,如 `persistent` 等。允许你的 agent 自动管理多轮对话状态,不再需要手动拼接 `messages` 历史,像原生认知一样记录上下文。
32+
- **`stream`** (流式推写开关):将其设置为 `"true"` 可以直接启用大模型的 Token 级流式响应。让 Agent 边思考边输出,实现对终端用户无卡顿的实时反馈。
33+
- **`fallback`** (模型灾备降级):由于 API RateLimit 或意外宕机导致请求失败时,通过设定 `fallback` 模型作为容灾选项,在运行时无缝切换。
3134

3235
---
3336

docs/part4_ecosystem_and_stdlib.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
comments: true
3+
---
4+
5+
# 5. 生态集成与标准库:通向物理世界的大门
6+
7+
智能体的强大不仅仅来源于内部的逻辑流与思考,更取决于其触及外部物理世界广度与深度。在最近的版本迭代中,Nexa 引入了极为强大的模块化和原生设备穿透能力(Vision/标准库模块)。本章将详细介绍这些通向“大千世界”的接口。
8+
9+
---
10+
11+
## 📦 标准库扩展 (Standard Library)
12+
在传统的胶水框架中,实现一个爬取网页并保存的 Agent,你需要自行安装 requests,手写 beautifulsoup 解析器,再打包成冗长的 Tool 供大模型调用。Nexa 中内置了原生的 `std` 标准库。
13+
你可以通过 `uses` 关键字直接声明代理权限,Nexa 将自动处理沙盒环境的隔离和调用上下文。
14+
15+
目前原生的标准库命名空间大幅扩充,包括:
16+
- `std.fs`:文件系统操作(读、写、列出目录属性),支持相对路径和安全拦截。
17+
- `std.http`:原生的网络请求钩子,不仅能发出请求,内置解析器会自动将庞大的 HTML / 噪音清洗为干净可读的 Markdown 塞回给模型的上下文。
18+
- `std.time`:赋予被困在静态权重里的模型“真实的时间感”。
19+
- `std.shell`:系统级终端下沉,执行底层操作。
20+
- `std.ask_human`:原生提供的人在回路(Human-in-the-loop, HITL)询问跳出机制。
21+
22+
**实战:新闻资讯抓取聚合流**
23+
```nexa
24+
// Nexa Agent 直接通过 uses 集成多维度环境
25+
agent Researcher uses std.time, std.http, std.fs {
26+
prompt: "You are an intelligent news researcher. Your job is to fetch the current date, then fetch top news from a given URL, summarize the top 3 items, and save the result into a local file with the date included in the summary.",
27+
model: "minimax-m2.5"
28+
}
29+
30+
flow main {
31+
msg = "Please fetch the current time, then fetch news from https://lite.cnn.com. Extract top 3 headlines and save them to `examples/today_news.md` using the file system tool.";
32+
Researcher.run(msg);
33+
}
34+
```
35+
36+
---
37+
38+
## 🔐 `secret`:敏感密钥的沙箱隔离
39+
在处理云端 API 和数据库对接时,绝对不能将 `API_KEY` 明文写在代码和 Prompt 里!Nexa 设计了原生的安全池 `.nxs` (Nexa Secure) 机制和 `secret()` 函数。
40+
41+
开发者可以在同目录的 `secrets.nxs` 中写入真实密钥,而在 `.nx` 代码中,你所流通的仅仅是一个受运行时保护的内存引用:
42+
```nexa
43+
flow main {
44+
// 仅仅是通过命名获取了加密指针,永远不会被打印或写入普通日志
45+
my_key = secret("MY_TEST_KEY");
46+
47+
// Agent 在底层通过安全的 RPC 调用附带该密钥连接外部,保障了整个工作流的数据安全
48+
CloudDeployAgent.run("Deploy using the API credentials: ", my_key);
49+
}
50+
```
51+
52+
---
53+
54+
## 🧩 模块化革命:`include .nxlib` 与 SKILLS.md
55+
要实现大型企业级 AI 系统的大规模协作,就必须允许代码进行微服务级的拆分!Nexa 最新的模块化方案允许你实现优雅复用:
56+
1. **`.nxlib` 文件引用**
57+
你可以将大量常用的基础 Agent 或通信协议打包成专门的 `.nxlib` 库,主文件只需一行 `include`
58+
```nexa
59+
include "utils.nxlib";
60+
61+
flow main {
62+
// LibAgent 来自于已经导入的 utils.nxlib,你可以像原生存放在此一样直接调用
63+
LibAgent.run("Echo this: module included successfully.");
64+
}
65+
```
66+
67+
2. **跨语言 Markdown 技能挂载 (`uses "SKILLS.md"`)**
68+
对于极度复杂且需要人工微调的 Tool (比如某个特定业务领域的算法)。Nexa 突破性地支持直接解析外部的 `.md` 技能定义本,只需要在 `uses` 声明对应的文档路径即可,底层 Runtime 会自动读取、解析并挂载那些大段的规则:
69+
```nexa
70+
// SKILLS.md 中存放了冗长的环境指导方针与外部函数
71+
agent StreamBot uses "examples/SKILLS.md" {
72+
model: "minimax-m2.5",
73+
prompt: "I am a helpful assistant. Apply the skills strictly to solve this issue."
74+
}
75+
```
76+
77+
---
78+
79+
## 👁️ 多模态先锋:全局内置的视觉原语 `img(...)`
80+
从 V0.8 架构开始,Nexa 正式进入了全多模态感知的阶段。你再也不用手写繁琐的 `Base64` 编码转换或者 `multipart/form-data` 解析装配,语言级别的 `img` 类型函数替你搞定一切:
81+
82+
```nexa
83+
agent ResilientVisionAgent {
84+
model: "minimax-m2.5",
85+
description: "I test fallback and vision capabilities."
86+
}
87+
88+
flow main {
89+
// 将指定路径下的静态图像直接转换为受引擎承认的内存多模态张量对象
90+
img_data = img("docs/img/logo.jpg");
91+
92+
// 就像传入普通字符串一样传给 Agent,底层会自适应匹配 VLM (Vision Language Model) 数据流!
93+
result = ResilientVisionAgent.run("Inspect this image", img_data);
94+
}
95+
```
96+
97+
Nexa 对于物理世界模块的封装,永远是以降低开发者的心智门槛、坚守系统沙盒安全性为最高原则。这些功能为你搭建自动化王国奠定了最扎实的水电煤基建。

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ nav:
8686
- 基础语法: part1_basic.md
8787
- 高级特性: part2_advanced.md
8888
- 语法扩展: part3_extensions.md
89+
- 生态与标准库: part4_ecosystem_and_stdlib.md
8990
- 深入设计:
9091
- 编译器设计: part5_compiler.md
9192
- 最佳实践: part6_best_practices.md

0 commit comments

Comments
 (0)