Skip to content

Commit 3712e93

Browse files
committed
📝 docs(v2): align docs content with Nexa v2.0/v2.1 — no visual changes
Content-only update across 14 files: - index.md/.en.md: add v2.0 Harness 6-tuple + v2.1 Agent properties overview - preface.md: add Harness Native design philosophy - part1_basic.md: add v2.1 agent properties + v2.0 autoloop/try_agent/@tool - part2_advanced.md: add v2.0/v2.1 to feature summary table - part3_extensions.md: add @tool/catch_correction/output_format - part4_ecosystem_and_stdlib.md: extend namespace table - part4_future.md: restructure as milestones + roadmap - part5_architecture_evolution.md: mark achieved items - part5_compiler.md: add HarnessValidator - part5_enterprise.md: extend features table - part6_best_practices.md: add Harness Native best practices - cli_reference.md: add harness-check command - reference.md: add v2.0/v2.1 keywords + Harness EBNF grammar Zero visual files touched (no extra.css/fonts.css/main.html changes).
1 parent 4139de1 commit 3712e93

14 files changed

Lines changed: 282 additions & 31 deletions

docs/cli_reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Nexa CLI 是 Nexa 语言的命令行接口,提供编译、运行、测试、
1616

1717
| 命令 | 说明 | 版本 |
1818
|------|------|------|
19-
| `nexa build` | 编译 .nx 文件为 .py | v0.9.7+ |
20-
| `nexa run` | 编译并执行 .nx 文件 | v0.9.7+ |
19+
| `nexa build` | 编译 .nx .py (支持 `--harness`) | v0.9.7+ |
20+
| `nexa run` | 编译并执行 (支持 `--harness`) | v0.9.7+ |
2121
| `nexa test` | 编译并运行测试 | v0.9.7+ |
22+
| `nexa harness-check` | Harness 六元组编译期验证 | v2.0 |
2223
| `nexa inspect` | 结构分析 (Agent-Native Tooling) | v1.3.0 |
2324
| `nexa validate` | 语义验证 | v1.3.0 |
2425
| `nexa lint` | 类型系统 Lint (渐进式类型系统) | v1.3.1 |

docs/index.en.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,39 @@ branch2 = agent.branch()
197197

198198
---
199199

200-
## 🎯 More Core Features
200+
## 🔥 v2.1: Production Hardening — Agent-Level Property Primitives
201+
202+
Nexa v2.1 adds **Agent-level language primitives**:
203+
204+
```nexa
205+
agent Coder {
206+
stream: true, max_tool_calls: 10,
207+
tool_call_strategy: "auto"
208+
}
209+
agent Planner {
210+
output_format: "json",
211+
output_schema: { steps: [{title: "string"}], estimated_time: "string" }
212+
}
213+
```
214+
215+
## 🔥 v2.0: Harness Native Runtime — Six-Tuple H=(E,T,C,S,L,V)
216+
217+
| Dimension | Syntax | Runtime | Tests |
218+
|-----------|--------|---------|-------|
219+
| **E** | `autoloop` / `try_agent` | ExecutionEngine | 52 |
220+
| **T** | `@tool` annotation | ToolRegistry | 53 |
221+
| **C** | `with_context` | ContextManager | 52 |
222+
| **S** | `snapshot` / `fork` / `merge` | StateStore | 45 |
223+
| **L** | `before_step` / `reflect` | LifecycleHookManager | 53 |
224+
| **V** | `verify ... satisfies` | EvaluationInterface | 59 |
225+
| **Actor** | `spawn` / `pass` / `await` | ActorSystem | 18 |
226+
| **WASM** | sandbox | WASM Sandbox | 15 |
227+
228+
Fully backward compatible. See [examples/v2.0/](https://github.com/ouyangyipeng/Nexa/tree/main/examples/v2.0).
229+
230+
---
231+
232+
## 🎯 More Core Features (v1.x)
201233

202234
Beyond code simplicity, Nexa provides these powerful language-level features:
203235

docs/index.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,44 @@ branch2 = agent.branch()
197197

198198
---
199199

200-
## 🎯 更多核心特性
200+
## 🔥 v2.1: Production Hardening — Agent 级属性原语
201+
202+
Nexa v2.1 为 Nexa Code 新增了 **Agent 级语言原语**
203+
204+
```nexa
205+
agent Coder {
206+
stream: true, // 流式输出
207+
max_tool_calls: 10, // 单次请求最多 10 轮工具调用
208+
tool_call_strategy: "auto" // auto | required | none
209+
}
210+
211+
agent Planner {
212+
output_format: "json", // 强制 JSON 模式
213+
output_schema: { // 编译器自动生成 Pydantic 模型
214+
steps: [{title: "string", description: "string"}],
215+
estimated_time: "string"
216+
}
217+
}
218+
```
219+
220+
## 🔥 v2.0: Harness Native Runtime — 六元组 H=(E,T,C,S,L,V)
221+
222+
| 维度 | 语法原语 | 运行时组件 | 测试数 |
223+
|------|---------|-----------|--------|
224+
| **E** | `autoloop` / `try_agent` | ExecutionEngine | 52 |
225+
| **T** | `@tool` 注解 | ToolRegistry | 53 |
226+
| **C** | `with_context` | ContextManager | 52 |
227+
| **S** | `snapshot` / `fork` / `merge` | StateStore | 45 |
228+
| **L** | `before_step` / `reflect` | LifecycleHookManager | 53 |
229+
| **V** | `verify ... satisfies` | EvaluationInterface | 59 |
230+
| **Actor** | `spawn` / `pass` / `await` | ActorSystem | 18 |
231+
| **WASM** | sandbox | WASM Sandbox | 15 |
232+
233+
完整示例参见 [examples/v2.0/](https://github.com/ouyangyipeng/Nexa/tree/main/examples/v2.0)[examples/v2.1/](https://github.com/ouyangyipeng/Nexa/tree/main/examples/v2.1)。向后兼容:v1.x 代码无需修改。
234+
235+
---
236+
237+
## 🎯 更多核心特性 (v1.x)
201238

202239
除了代码简洁性,Nexa 还提供以下强大的语言级特性:
203240

docs/part1_basic.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ agent FriendlyBot {
3535
| `prompt` | string | **** | - | v0.5+ | Agent 的核心任务指令 |
3636
| `model` | string || 默认模型 | v0.5+ | 指定使用的 LLM 模型 |
3737
| `memory` | string || - | v0.5+ | 记忆模式:`persistent`(持久化)等 |
38-
| `stream` | boolean || false | v0.5+ | 是否启用流式输出 |
38+
| `stream` | boolean || false | v2.1+ | 是否启用流式输出 |
3939
| `cache` | boolean || false | v0.5+ | 是否启用智能缓存 |
4040
| `experience` | string || - | v0.5+ | 长期记忆文件路径 |
4141
| `fallback` | string/list || - | v0.5+ | 备用模型配置 |
@@ -45,6 +45,10 @@ agent FriendlyBot {
4545
| `retry` | int || 3 | v0.5+ | 失败重试次数 |
4646
| `requires` | clause || - | v1.2+ | 前置条件契约条款 |
4747
| `ensures` | clause || - | v1.2+ | 后置条件契约条款 |
48+
| `output_format` | string || - | v2.1+ | 输出格式约束,支持 `"json"` |
49+
| `output_schema` | dict || - | v2.1+ | JSON Schema → 编译器自动生成 Pydantic |
50+
| `max_tool_calls` | int || - | v2.1+ | 最大工具调用轮数 |
51+
| `tool_call_strategy` | string || `"auto"` | v2.1+ | `"auto"`/`"required"`/`"none"` |
4852

4953
### 属性详细说明
5054

@@ -228,6 +232,59 @@ agent HighAvailabilityBot {
228232
}
229233
```
230234

235+
#### `output_format` / `output_schema` — 结构化输出 (v2.1+)
236+
237+
```nexa
238+
agent Planner {
239+
output_format: "json",
240+
output_schema: {
241+
steps: [{title: "string", description: "string"}],
242+
estimated_time: "string"
243+
}
244+
}
245+
```
246+
247+
#### `max_tool_calls` / `tool_call_strategy` — 工具调用控制 (v2.1+)
248+
249+
```nexa
250+
agent Coder {
251+
max_tool_calls: 10,
252+
tool_call_strategy: "auto"
253+
}
254+
```
255+
256+
| 策略值 | 含义 |
257+
|--------|------|
258+
| `"auto"` | 模型自行判断(默认) |
259+
| `"required"` | 强制调用至少一个工具 |
260+
| `"none"` | 禁用所有工具调用 |
261+
262+
---
263+
264+
## 🔄 v2.0 基础执行原语
265+
266+
### `autoloop` (E维度)
267+
```nexa
268+
autoloop max_steps: 10, exit_when: "任务完成", timeout: 300 {
269+
result = Agent.run(input)
270+
}
271+
```
272+
273+
### `try_agent` / `catch_correction` (E+L维度)
274+
```nexa
275+
try_agent {
276+
result = Agent.run(input)
277+
} catch_correction(e: ToolError) {
278+
reflect "工具执行失败,请调整参数重试"
279+
}
280+
```
281+
282+
### `@tool` 注解 (T维度)
283+
```nexa
284+
@tool("搜索网页内容")
285+
fn web_search(query: string): string { ... }
286+
```
287+
231288
---
232289

233290
## 🎯 Agent 修饰器(Decorators)

docs/part2_advanced.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,16 @@ formatted = p.format(); // 调用 Printable trait 的 format 方法
952952
| 延迟执行 | `defer` | v1.3.x | 资源清理 |
953953
| 模式匹配 | `match` | v1.3.x | 数据解构 |
954954
| 代数数据类型 | `struct/enum/trait` | v1.3.x | 类型安全建模 |
955+
| **自主循环** | `autoloop` | v2.0 | ReAct 自主执行 |
956+
| **容错自纠** | `try_agent/catch_correction` | v2.0 | 错误反射纠错 |
957+
| **上下文管理** | `with_context` | v2.0 | Token 预算控制 |
958+
| **状态快照** | `snapshot/fork/merge` | v2.0 | COW 分支探索 |
959+
| **输出验证** | `verify ... satisfies` | v2.0 | 四层输出验证 |
960+
| **生命周期** | `before/after_step/reflect` | v2.0 | 步骤级钩子注入 |
961+
| **Actor 并发** | `spawn/pass/await` | v2.0 | 多智能体消息传递 |
962+
| **并行分发** | `|>> spawn` | v2.1 | DAG 并行分发 |
955963

956-
这些特性让 Nexa 能够优雅地处理最复杂的智能体编排场景从简单的流水线到复杂的 DAG 拓扑,从确定性的分支到语义级别的条件判断,再到类型安全的数据建模
964+
这些特性让 Nexa 能够优雅地处理最复杂的智能体编排场景——从简单的流水线到复杂的 DAG 拓扑,从类型安全的数据建模到**语言原生的安全运行时**
957965

958966
---
959967

@@ -963,3 +971,4 @@ formatted = p.format(); // 调用 Printable trait 的 format 方法
963971
- [语法扩展](part3_extensions.md) - 学习 Protocol 与契约高级用法
964972
- [语言参考手册](reference.md) - 查看完整语法规范
965973
- [最佳实践](part6_best_practices.md) - 企业级开发经验
974+
- [Harness Agent 设计文档](https://github.com/ouyangyipeng/Nexa/blob/main/docs/others/Harness_Agent.md) - Harness 六元组详解

docs/part3_extensions.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,11 @@ flow main {
880880
| Design by Contract | v1.2.0+ | requires/ensures/invariant | 输入输出契约验证 |
881881
| Gradual Type System | v1.3.1+ | strict/warn/forgiving | 渐进式类型安全 |
882882
| Error Propagation | v1.3.2+ | `?``otherwise` | 优雅错误处理 |
883+
| **`@tool` 注解** | v2.0 | 声明式工具绑定 | 编译器自动生成 ToolSchema |
884+
| **`try_agent/catch_correction`** | v2.0 | 容错自纠执行 | 工具错误触发反思注入 |
885+
| **`output_format/schema`** | v2.1 | Agent 结构化输出 | 编译器自动生成 Pydantic 模型 |
883886

884-
通过将 `protocol` 的刚性契约与动态 `fallback` 流转网络相结合,再配合 v1.2.0 的契约式编程、v1.3.1 的渐进式类型系统和 v1.3.2 的错误传播机制,Nexa 在赋予高度"思考灵活性"的同时,从未抛弃几十年来传统软件工程所积累的"鲁棒性与边界确定性"基因。这也是 Agent 开发向正规化轨道迈出的决定性一步
887+
通过将 `protocol` 的刚性契约与 `fallback` 流转网络相结合,再配合 v1.2.0 的契约式编程、v1.3.1 的渐进式类型系统、v1.3.2 的错误传播、v2.0 的 Harness 六元组运行时验证和 v2.1 的 Agent 级结构化输出,Nexa 在赋予高度"思考灵活性"的同时,从未抛弃传统软件工程的"鲁棒性与边界确定性"基因。
885888

886889
---
887890

docs/part4_ecosystem_and_stdlib.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,16 @@ agent.run("使用 API key: sk-xxx"); // 危险!
803803
| `std.trait` | v1.3.x | 特质 | 多态行为 |
804804
| `secret()` | v0.5+ | 密钥管理 | API 认证、数据库连接 |
805805
| `img()` | v0.8+ | 多模态 | 图像分析、视觉任务 |
806-
807-
Nexa 对于物理世界模块的封装,永远是以降低开发者的心智门槛、坚守系统沙盒安全性为最高原则。从 v0.5 的基础 10 个命名空间到 v1.3.x 的 25 个命名空间,这些功能为你搭建自动化王国奠定了最扎实的水电煤基建。
806+
| **Harness Kernel** | v2.0 | 六元组运行时内核 | autoloop/with_context 执行 |
807+
| **ExecutionEngine** | v2.0 | ReAct 循环引擎 | E维度 |
808+
| **ContextManager** | v2.0 | 三层上下文压缩 | C维度 |
809+
| **StateStore** | v2.0 | COW 状态存储 | S维度 |
810+
| **LifecycleHookManager** | v2.0 | 生命周期钩子 | L维度 |
811+
| **EvaluationInterface** | v2.0 | 四层验证接口 | V维度 |
812+
| **ActorSystem** | v2.0 | 多智能体并发 | spawn/pass/await |
813+
| **WASM Sandbox** | v2.0 | 工具安全沙盒 | wasmtime + 四级权限 |
814+
815+
Nexa 从 v0.5 的基础 10 个命名空间到 v1.3.x 的 25 个命名空间,再到 v2.0 的 Harness Native 运行时组件,为你搭建自动化王国奠定了最扎实的基础。
808816

809817
---
810818

docs/part4_future.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,29 @@
22
comments: true
33
---
44

5-
# 5. 未来展望:进军完全认知架构与资源控制 (Cognitive Architecture)
6-
7-
智能体架构的发展日新月异,今天我们探讨的 Pipeline 管道、Intent 路由和 Join 汇聚,实际上仅仅是 Nexa 宏大图景的冰山一角。在我们从“自动化工具”走向“全自治企业级数字雇员”的征途中,不可避免地要解决关于成本、安全、人机协同等深水区难题。
8-
9-
在 Nexa 项目核心维护团队(Genesis Team)的案头与架构蓝图中,有一批即将融合入语言底层的革命性原语。本章将为您揭晓 Nexa 在下一个大版本中将带来的前瞻性特性。
5+
# 5. 未来展望与已实现里程碑
6+
7+
## ✅ 已实现里程碑
8+
9+
| 蓝图 | 状态 | 版本 |
10+
|------|------|------|
11+
| Rust AVM 底座 || v1.0-alpha (0 errors, 0 warnings) |
12+
| WASM 安全沙盒 || v1.0-alpha (wasmtime v21) |
13+
| 智能调度器 || v1.0-alpha |
14+
| 向量虚存分页 || v1.0-alpha |
15+
| HITL: wait_for_human() || v0.9.7 |
16+
| reason() 原语 || v0.9.7 |
17+
| RBAC 权限控制 || v0.9.6-rc |
18+
| 传统控制流 || v1.0.1-beta |
19+
| IDD 意图驱动开发 || v1.1.0 (104 tests) |
20+
| Design by Contract || v1.2.0 (47 tests) |
21+
| 16 项 v1.3.x 特性 || v1.3.0-v1.3.7 |
22+
| Harness Native Runtime || v2.0 (296 tests) |
23+
| Agent 级属性原语 || v2.1 |
24+
25+
## 🔮 未来展望
26+
27+
在 Nexa 核心团队(Genesis Team)的架构蓝图中,下一阶段的重点方向:
1028

1129
---
1230

docs/part5_architecture_evolution.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,29 @@ impl ContextPager {
468468

469469
---
470470

471+
## 6. 当前进展 (截至 v2.1.0)
472+
473+
### ✅ 已完成
474+
475+
| 阶段 | 状态 | 说明 |
476+
|------|------|------|
477+
| Rust AVM 底座 | ✅ 已完成 | v1.0-alpha: cargo check 0 errors 0 warnings |
478+
| WASM 安全沙盒 | ✅ 已完成 | v1.0-alpha: wasmtime v21 + 四级权限 |
479+
| 智能调度器 | ✅ 基础实现 | v1.0-alpha: DAG 拓扑排序 |
480+
| 向量虚存分页 | ✅ 基础实现 | v1.0-alpha: LRU/LFU/Hybrid |
481+
| Harness Native Runtime | ✅ 已完成 | v2.0: 六元组 296 测试 |
482+
| ActorSystem | ✅ 已完成 | v2.0: 18 测试 |
483+
| HarnessValidator | ✅ 已完成 | v2.0: --harness=warn/strict/off |
484+
| Agent 性能属性 | ✅ 已完成 | v2.1: stream/output_format/schema 等 |
485+
486+
### 🔮 未来路线图
487+
488+
| 阶段 | 状态 |
489+
|------|------|
490+
| 可视化 DAG 编辑器 | 🔮 架构规划已完成 |
491+
| 包管理器 (nxm) | 🔮 规划中 |
492+
| AVM 生产就绪 | 🔮 规划中 |
493+
494+
---
495+
471496
*此文档将随项目进展持续更新*

docs/part5_compiler.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,13 @@ nexa run script.nx --profile
618618

619619
## 📝 本章小结
620620

621-
在本章中,我们深入了解了:
622-
623-
1. **编译管道**:从词法分析到代码生成的完整流程
624-
2. **AVM 架构**:Rust 编写的高性能执行引擎
625-
3. **WASM 沙盒**:四级权限模型和资源限制
621+
1. **编译管道**:从词法分析到代码生成(含 v2.0 HarnessValidator)
622+
2. **AVM 架构**:Rust 高性能执行引擎(cargo check clean)
623+
3. **WASM 沙盒**:四级权限模型(wasmtime v21)
626624
4. **智能调度器**:优先级队列和负载均衡
627-
5. **向量虚存**:LRU/LFU 淘汰策略
628-
6. **Runtime 组件**:memory、orchestrator、evaluator、rbac
625+
5. **向量虚存**:LRU/LFU/Hybrid 淘汰策略
626+
6. **HarnessValidator**:v2.0 编译期六维约束验证(`--harness=strict/warn/off`
627+
7. **Runtime 组件**:execution_engine、context_manager、state_store 等
629628

630629
---
631630

0 commit comments

Comments
 (0)