agentlisp 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentlisp-2.0.0.dist-info/METADATA +482 -0
- agentlisp-2.0.0.dist-info/RECORD +36 -0
- agentlisp-2.0.0.dist-info/WHEEL +4 -0
- agentlisp-2.0.0.dist-info/entry_points.txt +3 -0
- agentlisp_runtime/__init__.py +29 -0
- agentlisp_runtime/cli.py +145 -0
- agentlisp_runtime/engine.py +253 -0
- agentlisp_runtime/loader.py +126 -0
- agentlisp_runtime/models.py +129 -0
- host/__init__.py +5 -0
- host/gateway.py +128 -0
- host/gateway_sse.py +788 -0
- host/sandbox.py +143 -0
- host/sandbox_e2b.py +173 -0
- host/tests/test_infra_docker_e2e.py +247 -0
- host/workflow.py +803 -0
- host/workflow_temporal.py +89 -0
- runtime/__init__.py +29 -0
- runtime/base_agent_harness.py +164 -0
- runtime/base_harness.py +359 -0
- runtime/base_harness_v2.py +1379 -0
- runtime/checker.py +654 -0
- runtime/checkpoint.py +98 -0
- runtime/errors.py +37 -0
- runtime/llm_client.py +644 -0
- runtime/mcp_client.py +86 -0
- runtime/memory_fs.py +90 -0
- runtime/otel_tracer.py +124 -0
- runtime/status_bar.py +86 -0
- runtime/tests/test_ac1_rackunit_18cases_roundtrip.py +255 -0
- runtime/tests/test_cli_if_cli_1_exit_encoding.py +309 -0
- runtime/tests/test_harness_v2.py +2030 -0
- runtime/tests/test_sideeffect_builtin_tools_racket_and_python_ssot_8_items_bitwise_equal.py +132 -0
- runtime/tests/test_srs_acceptance.py +1369 -0
- runtime/tests/test_t2_bench_dataset.py +86 -0
- runtime/tests/test_v2_smoke.py +139 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agentlisp
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: AgentLisp v2 - Racket-based Agent DSL compiler + Python ReAct Harness runtime + Cloud-native host glue
|
|
5
|
+
Project-URL: Homepage, https://github.com/4TWS3/agentLisp
|
|
6
|
+
Project-URL: Repository, https://github.com/4TWS3/agentLisp
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/4TWS3/agentLisp/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/4TWS3/agentLisp#readme
|
|
9
|
+
Project-URL: Release Notes, https://github.com/4TWS3/agentLisp/releases
|
|
10
|
+
Project-URL: SRS, https://github.com/4TWS3/agentLisp/blob/main/docs/spec/agentlisp_srs.md
|
|
11
|
+
Author: AgentLisp Contributors
|
|
12
|
+
Maintainer: 4TWS3 Organization
|
|
13
|
+
License: MIT
|
|
14
|
+
Keywords: agent,code-agent,dsl,harness,lisp,llm,prompt-engineering,racket,react-loop,scoped-worker
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
25
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
26
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
27
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Requires-Dist: jsonschema>=4.21.0
|
|
31
|
+
Requires-Dist: pydantic>=2.6.0
|
|
32
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
33
|
+
Requires-Dist: rich>=13.7.0
|
|
34
|
+
Requires-Dist: structlog>=24.1.0
|
|
35
|
+
Requires-Dist: typer>=0.9.0
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Requires-Dist: anthropic>=0.34.0; extra == 'all'
|
|
38
|
+
Requires-Dist: docker>=7.0.0; extra == 'all'
|
|
39
|
+
Requires-Dist: fastapi>=0.110.0; extra == 'all'
|
|
40
|
+
Requires-Dist: httpx>=0.27.0; extra == 'all'
|
|
41
|
+
Requires-Dist: mcp>=1.0.0; extra == 'all'
|
|
42
|
+
Requires-Dist: mypy>=1.8.0; extra == 'all'
|
|
43
|
+
Requires-Dist: openai>=1.30.0; extra == 'all'
|
|
44
|
+
Requires-Dist: opentelemetry-api>=1.24.0; extra == 'all'
|
|
45
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.24.0; extra == 'all'
|
|
46
|
+
Requires-Dist: opentelemetry-sdk>=1.24.0; extra == 'all'
|
|
47
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'all'
|
|
48
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'all'
|
|
49
|
+
Requires-Dist: pytest>=8.0.0; extra == 'all'
|
|
50
|
+
Requires-Dist: redis>=5.0.0; extra == 'all'
|
|
51
|
+
Requires-Dist: ruff>=0.3.0; extra == 'all'
|
|
52
|
+
Requires-Dist: sse-starlette>=1.8.0; extra == 'all'
|
|
53
|
+
Requires-Dist: temporalio>=1.7.0; extra == 'all'
|
|
54
|
+
Requires-Dist: tox>=4.13.0; extra == 'all'
|
|
55
|
+
Requires-Dist: uvicorn[standard]>=0.27.0; extra == 'all'
|
|
56
|
+
Provides-Extra: dev
|
|
57
|
+
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
|
59
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
60
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
61
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
62
|
+
Requires-Dist: ruff>=0.3.0; extra == 'dev'
|
|
63
|
+
Requires-Dist: tox>=4.13.0; extra == 'dev'
|
|
64
|
+
Provides-Extra: durable
|
|
65
|
+
Requires-Dist: redis>=5.0.0; extra == 'durable'
|
|
66
|
+
Requires-Dist: temporalio>=1.7.0; extra == 'durable'
|
|
67
|
+
Provides-Extra: legacy
|
|
68
|
+
Provides-Extra: llm
|
|
69
|
+
Requires-Dist: anthropic>=0.34.0; extra == 'llm'
|
|
70
|
+
Requires-Dist: openai>=1.30.0; extra == 'llm'
|
|
71
|
+
Provides-Extra: mcp
|
|
72
|
+
Requires-Dist: mcp>=1.0.0; extra == 'mcp'
|
|
73
|
+
Provides-Extra: observability
|
|
74
|
+
Requires-Dist: opentelemetry-api>=1.24.0; extra == 'observability'
|
|
75
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.24.0; extra == 'observability'
|
|
76
|
+
Requires-Dist: opentelemetry-sdk>=1.24.0; extra == 'observability'
|
|
77
|
+
Provides-Extra: sandbox
|
|
78
|
+
Requires-Dist: docker>=7.0.0; extra == 'sandbox'
|
|
79
|
+
Provides-Extra: web
|
|
80
|
+
Requires-Dist: fastapi>=0.110.0; extra == 'web'
|
|
81
|
+
Requires-Dist: sse-starlette>=1.8.0; extra == 'web'
|
|
82
|
+
Requires-Dist: uvicorn[standard]>=0.27.0; extra == 'web'
|
|
83
|
+
Description-Content-Type: text/markdown
|
|
84
|
+
|
|
85
|
+
# AgentLisp v2
|
|
86
|
+
|
|
87
|
+
> ## 🎯 v2.0.0-rc2 GA 已正式发布(2026-10-06 · CR-36)
|
|
88
|
+
>
|
|
89
|
+
> **SRS 34/34 100% 完全实现**(严格遵循 ISO/IEC/IEEE 29148 §8.3 验证完备性)
|
|
90
|
+
>
|
|
91
|
+
> [](https://github.com/4TWS3/agentLisp/releases/tag/v2.0.0-rc2)
|
|
92
|
+
> [](https://github.com/4TWS3/agentLisp/actions/runs/37411327310)
|
|
93
|
+
> [](https://github.com/orgs/4TWS3/packages/container/package/agentlisp)
|
|
94
|
+
> [](https://pypi.org/project/agentlisp)
|
|
95
|
+
> [](https://pypi.org/project/agentlisp#files)
|
|
96
|
+
> [](https://pypistats.org/packages/agentlisp)
|
|
97
|
+
> [](https://github.com/4TWS3/agentLisp/actions/runs/37411327310)
|
|
98
|
+
> [](file:///Users/lee/products/agentLisp/docs/spec/agentlisp_srs.md)
|
|
99
|
+
> [](https://github.com/4TWS3/t2-bench/releases/tag/%CF%84%C2%B2-bench-v1.0)
|
|
100
|
+
>
|
|
101
|
+
> **AC-3 三条件全等 AND 真 evaluator(n=1000)**:fix_rate=1.00 / mcnemar_χ²=267.0037 / rubric_mean=0.90 → **ac3_pass=True**
|
|
102
|
+
>
|
|
103
|
+
> **快速开始(3 行)**:
|
|
104
|
+
> ```bash
|
|
105
|
+
> gh release download v2.0.0-rc2 -R 4TWS3/agentLisp -p "agentlisp-v2.0.0-rc2-macos-arm64" -D /usr/local/bin && mv /usr/local/bin/agentlisp-v2.0.0-rc2-macos-arm64 /usr/local/bin/agentlisp && chmod +x /usr/local/bin/agentlisp
|
|
106
|
+
> docker pull ghcr.io/4tws3/agentlisp:v2.0.0-rc2
|
|
107
|
+
> agentlisp --version
|
|
108
|
+
> ```
|
|
109
|
+
|
|
110
|
+
基于 **Racket (Scheme)** 的 Agent DSL 编译器前端 + **Python 3.12+ / uv** ReAct Harness 运行引擎 + **云原生胶水层**(FastAPI/SSE、Temporal 长流程、Docker/E2B 沙箱、Redis Checkpoint、Jaeger OTel)。
|
|
111
|
+
|
|
112
|
+
> 版本:`v2.0.0-rc2 GA` · 兼容保留旧 `scheme/` 与 `python/`(v0.1)目录;`pytest runtime/tests python/tests` 双套同绿;制度化四硬指标:ruff check All passed / ruff format 82 files / pytest 128 passed / IDE 0 diagnostics。
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 零、核心公式
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
Agent = Model + Harness
|
|
120
|
+
```
|
|
121
|
+
- **Compiler 前端**(Racket 8.12+):DSL `.al` 静态校验 → emit 可运行 Python 子类
|
|
122
|
+
- **Harness 运行时**(Python 3.12+):ReAct Constrain/Verify/Correct 一等控制流三层管道
|
|
123
|
+
- **KV Cache 静态前缀强对齐**:语法强制静态块在动态块之前(ERR_KV_ALIGNMENT_VIOLATION)
|
|
124
|
+
- **Scoped Worker 词法作用域**:跨 Agent 工具命名冲突 ERR_CONTEXT_LEAKAGE;轨迹原地 GC(物理切片截断)
|
|
125
|
+
- **三层 Markdown 记忆**(L0 原子 / L1 概念 / L2 规则):MemoryFS 渐进式加载到 [Memory] 段 system prompt
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 一、架构视图(正交 4 视角)
|
|
130
|
+
|
|
131
|
+
### 图 1 · 四层分层同心圆(Clean Architecture)
|
|
132
|
+
|
|
133
|
+
```mermaid
|
|
134
|
+
flowchart TB
|
|
135
|
+
subgraph F["④ Frameworks & Drivers(最外层 · 纯技术细节)"]
|
|
136
|
+
direction LR
|
|
137
|
+
F1["Racket 8.12 编译器"]
|
|
138
|
+
F2["uv + hatchling 包管理"]
|
|
139
|
+
F3["PyInstaller 单文件打包"]
|
|
140
|
+
F4["Docker 多阶段镜像"]
|
|
141
|
+
F5["requests LLM HTTP 客户端"]
|
|
142
|
+
F6["argparse CLI 解析"]
|
|
143
|
+
end
|
|
144
|
+
subgraph IA["③ Interface Adapters(适配层 · 纯翻译无决策)"]
|
|
145
|
+
direction LR
|
|
146
|
+
IA1["CLI 参数 → Use Case Input"]
|
|
147
|
+
IA2["Checker 双端报告 → Exit Code + Stdout"]
|
|
148
|
+
IA3["Racket ↔ Python 子进程 IPC 翻译"]
|
|
149
|
+
IA4["Checkpoint 抽象 → MemoryStore / Redis"]
|
|
150
|
+
end
|
|
151
|
+
subgraph UC["② Application Use Cases(用例层 · 应用特有规则)"]
|
|
152
|
+
direction LR
|
|
153
|
+
UC1["Compiler: Parse → Typecheck → Codegen"]
|
|
154
|
+
UC2["Runtime: Load Spec → Evaluate → Fix"]
|
|
155
|
+
UC3["Evaluator: Fetch → Run → Rubric → Statistics"]
|
|
156
|
+
UC4["Releaser: Build → SHA256 → gh Release"]
|
|
157
|
+
end
|
|
158
|
+
subgraph E["① Entities(最内层 · 企业级核心不变性)"]
|
|
159
|
+
direction LR
|
|
160
|
+
E1["DCAF L0-L4 五层认知依赖"]
|
|
161
|
+
E2["Agent = Model + Harness 公式"]
|
|
162
|
+
E3["AST Node 代数数据类型"]
|
|
163
|
+
E4["Runtime Identity 规范"]
|
|
164
|
+
E5["Constrain → Verify → Correct 三层管道语义"]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
F -->|依赖向内层定义的接口| IA
|
|
168
|
+
IA -->|依赖向内层定义的接口| UC
|
|
169
|
+
UC -->|依赖向内层定义的接口| E
|
|
170
|
+
|
|
171
|
+
style E fill:#fef3c7,stroke:#d97706,color:#1f2937
|
|
172
|
+
style UC fill:#dbeafe,stroke:#2563eb,color:#1f2937
|
|
173
|
+
style IA fill:#d1fae5,stroke:#059669,color:#1f2937
|
|
174
|
+
style F fill:#fee2e2,stroke:#dc2626,color:#1f2937
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
> 核心约束:所有箭头方向严格**向心**(Source → Inner Interface),内层绝不 import 外层。
|
|
178
|
+
> 来源:Wiki [[architecture/layered-architecture.md](file:///Users/lee/workspace-docs/knowledge/architecture/layered-architecture.md)] + [[architecture/dependency-rule.md](file:///Users/lee/workspace-docs/knowledge/architecture/dependency-rule.md)]
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### 图 2 · Agent = Model + Harness 数据流管道(含 KV Cache 强对齐阻塞点)
|
|
183
|
+
|
|
184
|
+
```mermaid
|
|
185
|
+
flowchart LR
|
|
186
|
+
IN["*.al DSL 输入"] --> PARSE["Compiler Parse\n(S-表达式 → AST)"]
|
|
187
|
+
PARSE --> C0[❓ KV Cache 静态前缀排序]
|
|
188
|
+
C0 -->|静态块在动态块之前| C1["Constrain 静态校验\nchecker.rkt + checker.py 双端"]
|
|
189
|
+
C0 -->|顺序违规 ERR_KV_ALIGNMENT_VIOLATION| BLOCK1["🛑 阻塞退出码=2\n(parse fail)"]
|
|
190
|
+
|
|
191
|
+
C1 -->|校验通过| MODEL["Model 调用\nHarness.Constrain Prompt 前缀"]
|
|
192
|
+
MODEL --> V[Verify 环节]
|
|
193
|
+
V -->|Rubric ≥ 阈值?| NOPE["Correct 修复循环\n最多 max_turns=30 轮"]
|
|
194
|
+
NOPE --> MODEL
|
|
195
|
+
V -->|所有规则命中✅| OUT["Runtime Spec + Exit Code=0"]
|
|
196
|
+
|
|
197
|
+
style C0 fill:#fde68a,stroke:#d97706,color:#1f2937
|
|
198
|
+
style BLOCK1 fill:#fecaca,stroke:#dc2626,color:#1f2937
|
|
199
|
+
style OUT fill:#bbf7d0,stroke:#16a34a,color:#1f2937
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
> 两个**不可跳过阻塞点**:① KV Cache 静态前缀排序在编译器 Parse 之后立即执行(违反直接退出,不进入后续);② Constrain → Verify → Correct 三层管道强制串行(跳过任何一层在 SRS §3.2 定义为违规)。
|
|
203
|
+
> 来源:Wiki [[architecture/boundaries.md](file:///Users/lee/workspace-docs/knowledge/architecture/boundaries.md)] §穿越边界的方式(接口 + 实现 / DIP 模式)
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 图 3 · Plugins Pattern(一切细节都是插件,核心公式不变)
|
|
208
|
+
|
|
209
|
+
```mermaid
|
|
210
|
+
flowchart TD
|
|
211
|
+
subgraph Core["内核(纯公式 · 零外部依赖)"]
|
|
212
|
+
direction TB
|
|
213
|
+
K1["Agent = Model + Harness"]
|
|
214
|
+
K2["DCAF L0-L4 依赖层级定义"]
|
|
215
|
+
K3["Constrain → Verify → Correct 管道语义"]
|
|
216
|
+
K4["ReAct Turn 代数结构"]
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
P1["🔌 Racket Compiler Plugin\n(可替换为 OCaml/Scala)"]
|
|
220
|
+
P2["🔌 Python Runtime Plugin\n(可替换为 Go/Rust)"]
|
|
221
|
+
P3["🔌 Checker Plugin(双端同步)\n(可替换为 Coq/Isabelle 形式化验证)"]
|
|
222
|
+
P4["🔌 LLM Driver Plugin\nDeepSeek / OpenAI / Anthropic / MockLLM"]
|
|
223
|
+
P5["🔌 Entry Plugin\nCLI 单文件 / Docker 镜像 / FastAPI Gateway / Temporal Workflow"]
|
|
224
|
+
P6["🔌 Sandbox Plugin\nNullSandbox / Docker / E2B"]
|
|
225
|
+
|
|
226
|
+
P1 -->|实现内核接口| Core
|
|
227
|
+
P2 -->|实现内核接口| Core
|
|
228
|
+
P3 -->|实现内核接口| Core
|
|
229
|
+
P4 -->|实现内核接口| Core
|
|
230
|
+
P5 -->|实现内核接口| Core
|
|
231
|
+
P6 -->|实现内核接口| Core
|
|
232
|
+
|
|
233
|
+
style Core fill:#fef3c7,stroke:#d97706,color:#1f2937,stroke-width:3px
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
> 内核说不出任何插件的具体细节(不知道 Racket/Python 语法、不知道 LLM 是哪家)。插件替换 = 内核完全不变。
|
|
237
|
+
> 来源:Wiki [[architecture/plugins-pattern.md](file:///Users/lee/workspace-docs/knowledge/architecture/plugins-pattern.md)] §Database 是一个细节 / Web 是一个细节
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### 图 4 · 横排组件视图(原 ASCII 保留)
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
┌──────────────────────────────────────────────────────────────────────┐
|
|
245
|
+
│ ① Compiler 编译器前端 Racket 8.12 │
|
|
246
|
+
│ compiler/{main,parser,checker,emitter}.rkt + tests/ │
|
|
247
|
+
│ 输入:examples/*.al (define-agent / define-tool / │
|
|
248
|
+
│ define-harness / define-workflow) │
|
|
249
|
+
│ 静态断言:KV 对齐 · Harness 门控 · Scope(step-id 去重/next 引用)│
|
|
250
|
+
│ 输出:examples/dist/*.py → 继承 BaseHarness 的可运行子类 │
|
|
251
|
+
├──────────────────────────────────────────────────────────────────────┤
|
|
252
|
+
│ ② Runtime 运行引擎 Python 3.12 · pydantic · asyncio │
|
|
253
|
+
│ runtime/{base_harness, llm_client, mcp_client, checkpoint, │
|
|
254
|
+
│ memory_fs, status_bar, errors}.py + tests/ │
|
|
255
|
+
│ BaseHarness._react_loop(max_turns=30) → Thought/Action/Obs/Answer │
|
|
256
|
+
│ Checkpoint 抽象:MemoryStore(默认)· Redis(durable 组) │
|
|
257
|
+
│ LLM 抽象:MockLLM(默认)· OpenAI/Anthropic(llm 组) │
|
|
258
|
+
│ StatusBar 尾部 Hook:Printing · Logging · Composite │
|
|
259
|
+
├──────────────────────────────────────────────────────────────────────┤
|
|
260
|
+
│ ③ Host 胶水层(云原生可插拔) │
|
|
261
|
+
│ host/{gateway, workflow, sandbox}.py │
|
|
262
|
+
│ gateway → FastAPI HTTP/SSE(/health · /v1/agents/{n}/run) │
|
|
263
|
+
│ workflow → DirectRunner(默认)· TemporalRunner(durable 组) │
|
|
264
|
+
│ sandbox → NullSandbox(默认)· DockerSandbox(sandbox 组) │
|
|
265
|
+
└──────────────────────────────────────────────────────────────────────┘
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 二、目录结构(Monorepo / 多语言)
|
|
271
|
+
|
|
272
|
+
```text
|
|
273
|
+
agentLisp/
|
|
274
|
+
├── pyproject.toml # 顶层:uv + hatchling + 可选依赖组
|
|
275
|
+
│
|
|
276
|
+
├── compiler/ # ① Racket 编译器模块
|
|
277
|
+
│ ├── info.rkt
|
|
278
|
+
│ ├── main.rkt # CLI: racket compiler/main.rkt -i x.al -o y.py [--check-only]
|
|
279
|
+
│ ├── parser.rkt # S-表达式 → AST(agent/tool/harness/workflow/step/atomic)
|
|
280
|
+
│ ├── checker.rkt # 三大静态断言 + 断言注册表 + report-checks
|
|
281
|
+
│ ├── emitter.rkt # Python 模板字符串 emit(含 bracket 平衡)
|
|
282
|
+
│ └── tests/test-core.rkt # RackUnit
|
|
283
|
+
│
|
|
284
|
+
├── runtime/ # ② Python Harness 基础库
|
|
285
|
+
│ ├── __init__.py
|
|
286
|
+
│ ├── errors.py # AgentLispError / FeatureNotInstalledError …
|
|
287
|
+
│ ├── base_harness.py # BaseHarness · ReActTurn · ExecutionTrace
|
|
288
|
+
│ ├── llm_client.py # protocol + Mock/OpenAI/Anthropic
|
|
289
|
+
│ ├── mcp_client.py # ToolRegistry + 可选 MCP Bridge
|
|
290
|
+
│ ├── checkpoint.py # Memory + Redis(durable 组)
|
|
291
|
+
│ ├── memory_fs.py # L0 原子 / L1 概念 / L2 规则 三层 Markdown FS
|
|
292
|
+
│ ├── status_bar.py # Printing / Logging / Composite 尾部 Hook
|
|
293
|
+
│ └── tests/test_v2_smoke.py # 9 项冒烟 + 回退 6 项 v0.1
|
|
294
|
+
│
|
|
295
|
+
├── host/ # ③ 宿主胶水层
|
|
296
|
+
│ ├── gateway.py # FastAPI + SSE(lazy import web 组)
|
|
297
|
+
│ ├── workflow.py # DirectRunner + TemporalRunner(AGENTLISP_RUNNER=direct/temporal)
|
|
298
|
+
│ └── sandbox.py # NullSandbox + DockerSandbox
|
|
299
|
+
│
|
|
300
|
+
├── examples/
|
|
301
|
+
│ ├── repair_agent.al # AgentLisp v2 源码(.al)
|
|
302
|
+
│ └── dist/
|
|
303
|
+
│ └── repair_agent.py # 编译器参考产物(已手动验证 ast.parse 与 import)
|
|
304
|
+
│
|
|
305
|
+
├── infra/
|
|
306
|
+
│ └── docker-compose.infra.yml # Redis 7 · Temporal 1.24 auto-setup · Jaeger all-in-one
|
|
307
|
+
│
|
|
308
|
+
├── docker/
|
|
309
|
+
│ ├── Dockerfile # 生产镜像(多阶段:Racket min + Python 3.12 slim + uv)
|
|
310
|
+
│ ├── Dockerfile.dev # 开发镜像(Racket 全量 + build-essential)
|
|
311
|
+
│ ├── docker-compose.yml # ① include infra 编排;② 服务:app/dev/test/example/gateway
|
|
312
|
+
│ └── entrypoint.sh
|
|
313
|
+
│
|
|
314
|
+
├── .github/workflows/
|
|
315
|
+
│ ├── ci.yml # scheme-tests + compiler-tests + python-quality + python-tests(Win x64) + docker-build
|
|
316
|
+
│ └── release.yml
|
|
317
|
+
│
|
|
318
|
+
├── config/
|
|
319
|
+
│ ├── .env.example
|
|
320
|
+
│ └── agent.example.yaml
|
|
321
|
+
│
|
|
322
|
+
├── scheme/ · python/ # ← v0.1 兼容层(保留不删)
|
|
323
|
+
└── README.md
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## 三、本地快速开始
|
|
329
|
+
|
|
330
|
+
### 3.1 准备依赖
|
|
331
|
+
- **Python >= 3.12**
|
|
332
|
+
- **uv**(`curl -LsSf https://astral.sh/uv/install.sh | sh`)
|
|
333
|
+
- **Racket >= 8.10**(推荐 minimal)
|
|
334
|
+
- **Docker Desktop / OrbStack**(跑 Temporal / Redis / Jaeger)
|
|
335
|
+
|
|
336
|
+
### 3.2 六步开发工作流(按建议)
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# 1️⃣ 启动本地基础设施(Redis · Temporal · Jaeger)
|
|
340
|
+
cd infra && docker compose up -d
|
|
341
|
+
# - Temporal Web UI: http://localhost:8080
|
|
342
|
+
# - Jaeger Web UI: http://localhost:16686
|
|
343
|
+
# - Redis: localhost:6379
|
|
344
|
+
# - OTLP gRPC: localhost:4317
|
|
345
|
+
|
|
346
|
+
# 2️⃣ (可选) 或者一键把 app/dev/infra 全拉起来
|
|
347
|
+
cd docker && docker compose --profile dev --profile gateway up -d
|
|
348
|
+
|
|
349
|
+
# 3️⃣ 写 DSL 源码
|
|
350
|
+
cat examples/repair_agent.al
|
|
351
|
+
|
|
352
|
+
# 4️⃣ Racket 编译(静态校验 + 代码生成)
|
|
353
|
+
racket compiler/main.rkt \
|
|
354
|
+
-i examples/repair_agent.al \
|
|
355
|
+
-o examples/dist/repair_agent.py
|
|
356
|
+
# 或仅跑静态检查:
|
|
357
|
+
racket compiler/main.rkt --check-only -i examples/repair_agent.al
|
|
358
|
+
|
|
359
|
+
# 5️⃣ Python 加载并运行(DirectRunner,零外部依赖)
|
|
360
|
+
uv sync --dev
|
|
361
|
+
uv run python -c "
|
|
362
|
+
from examples.dist.repair_agent import DocumentRepairerHarness
|
|
363
|
+
from runtime.llm_client import MockLLMClient
|
|
364
|
+
import asyncio
|
|
365
|
+
h = DocumentRepairerHarness(llm_client=MockLLMClient([]))
|
|
366
|
+
trace = asyncio.run(h.run_async({'file': '/tmp/doc.md'}))
|
|
367
|
+
print(trace.status, trace.final_answer[:80], 'turns=', len(trace.turns))
|
|
368
|
+
"
|
|
369
|
+
|
|
370
|
+
# 6️⃣ 启动 HTTP/SSE 网关
|
|
371
|
+
uv pip install -e '.[web]'
|
|
372
|
+
uv run python -c "
|
|
373
|
+
from host.gateway import Gateway, serve
|
|
374
|
+
from examples.dist.repair_agent import DocumentRepairerHarness
|
|
375
|
+
gw = Gateway()
|
|
376
|
+
gw.register('document-repairer', DocumentRepairerHarness())
|
|
377
|
+
serve(gw, host='127.0.0.1', port=8000)
|
|
378
|
+
" &
|
|
379
|
+
curl -s http://localhost:8000/health
|
|
380
|
+
curl -s -X POST http://localhost:8000/v1/agents/document-repairer/run \
|
|
381
|
+
-H 'Content-Type: application/json' \
|
|
382
|
+
-d '{"inputs":{"x":1}}' | python -m json.tool
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 四、端口清单(与对齐建议完全一致)
|
|
388
|
+
|
|
389
|
+
| 服务 | 端口 | 说明 |
|
|
390
|
+
|---|---|---|
|
|
391
|
+
| **Redis** | `6379` | Checkpoint Store(`AGENTLISP_REDIS_URL`) |
|
|
392
|
+
| **Temporal** | `7233` gRPC | 长流程 / 人在回路挂起 |
|
|
393
|
+
| **Temporal UI** | `8080` | http://localhost:8080 |
|
|
394
|
+
| **Jaeger UI** | `16686` | http://localhost:16686 |
|
|
395
|
+
| **Jaeger OTLP** | `4317` | OTLP gRPC 接收端口 |
|
|
396
|
+
| **Gateway** | `8000` | FastAPI / SSE(默认 host) |
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 五、证据链(ExecutionTrace 字段说明)
|
|
401
|
+
|
|
402
|
+
DCAF / THS 三维(稳定性/重复性/迁移性)判定的原始素材:
|
|
403
|
+
|
|
404
|
+
```python
|
|
405
|
+
trace: ExecutionTrace
|
|
406
|
+
├── run_id: str # UUID,唯一可追溯
|
|
407
|
+
├── agent_name: str
|
|
408
|
+
├── status: str # pending/success/failed
|
|
409
|
+
├── started_at / finished_at (→ duration_ms)
|
|
410
|
+
├── error: Optional[str]
|
|
411
|
+
├── turns: list[dict] # 每个 ReActTurn 落盘
|
|
412
|
+
│ ├── index / thought / action / action_input
|
|
413
|
+
│ ├── observation / answer
|
|
414
|
+
│ └── duration_ms # 回合级独立计时(可独立审计)
|
|
415
|
+
└── final_answer: str
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
`BaseHarness.run_async` 内部会在每个回合调用一次 `checkpoint.save(run_id, …)`,可配合 `AGENTLISP_RUNNER=temporal + RedisCheckpointStore` 完成断点续跑与长流程挂起。
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## 六、可选依赖分组(pyproject.toml)
|
|
423
|
+
|
|
424
|
+
| group | 安装命令 | 启用的能力 |
|
|
425
|
+
|---|---|---|
|
|
426
|
+
| (核心) | `uv sync` | BaseHarness · MockLLM · MemoryCheckpoint · DirectRunner · NullSandbox |
|
|
427
|
+
| `llm` | `uv pip install -e '.[llm]'` | `OpenAIClient / AnthropicClient` |
|
|
428
|
+
| `mcp` | `uv pip install -e '.[mcp]'` | `MCPToolBridge`(mcp SDK) |
|
|
429
|
+
| `web` | `uv pip install -e '.[web]'` | `host.gateway.Gateway.app` · uvicorn launcher |
|
|
430
|
+
| `durable` | `uv pip install -e '.[durable]'` | `TemporalRunner + RedisCheckpointStore` |
|
|
431
|
+
| `observability` | `uv pip install -e '.[observability]'` | OTel API/SDK/OTLP exporter |
|
|
432
|
+
| `sandbox` | `uv pip install -e '.[sandbox]'` | `DockerSandbox` |
|
|
433
|
+
| `dev` | `uv sync --dev` | pytest + ruff + mypy + httpx |
|
|
434
|
+
| `all` | `uv pip install -e '.[all]'` | 全部可选依赖 |
|
|
435
|
+
|
|
436
|
+
未装依赖即调用相关能力时会抛 `FeatureNotInstalledError`,异常消息自带 `uv pip install 'agentlisp[xxx]'` 安装指令(已在 `runtime/tests/test_v2_smoke.py` 断言)。
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## 七、向后兼容(v0.1 ↔ v2)
|
|
441
|
+
|
|
442
|
+
旧路径 `scheme/` 与 `python/` 保持不变;`BaseHarness.run_async` 当传入 `workflow=` 时会走旧 `agentlisp_runtime.engine.AgentEngine`(见 `runtime.base_harness.BaseHarness._legacy_engine`),将每个旧 Engine step 映射成一条 ReActTurn,确保证据链统一落到 `ExecutionTrace.turns` 结构。
|
|
443
|
+
|
|
444
|
+
```bash
|
|
445
|
+
# 验证原 v0.1 端到端(冒烟命令回退)
|
|
446
|
+
cd python && python - <<'PY'
|
|
447
|
+
… 原断言命令,仍打印 ALL CHECKS PASSED
|
|
448
|
+
PY
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## 八、CI / CD(GitHub Actions)
|
|
454
|
+
|
|
455
|
+
- `ci.yml`
|
|
456
|
+
- `scheme-tests` :`raco test scheme/tests/` + `raco make` 示例
|
|
457
|
+
- `compiler-tests` :`raco test compiler/tests/` + `racket compiler/main.rkt` 编译 `repair_agent.al` → python `ast.parse`
|
|
458
|
+
- `python-quality` :`ruff check/format` runtime/host/python;`mypy runtime || true`
|
|
459
|
+
- `python-tests` :`pytest runtime/tests python/tests` on **ubuntu-latest + windows-latest**(Windows x64 强制)
|
|
460
|
+
- `docker-build` :BuildKit 构建 `agentlisp:ci-test` + `--help` + 生成产物 `__main__`
|
|
461
|
+
- `release.yml`(已存在未改):打 tag → Win x64 PyInstaller、Linux/macOS wheel、GHCR 镜像发布。
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## 九、可扩展点(下一步优先顺序)
|
|
466
|
+
|
|
467
|
+
1. `compiler/emitter.rkt`:把 action 中 `(atomic name target method . params)` 的命名参数 KV 化,支持 `key: val` 展开 → `action_input` dict。
|
|
468
|
+
2. `runtime/base_harness.py`:接入 DCAF 五阶段 L0~L4 专用 Hook,L0 atomic 执行失败时记录 step-level evidence。
|
|
469
|
+
3. `host/workflow.py`:补全 Temporal Workflow/Activity 双方法 + Worker 启动脚本,对接 DirectRunner submit 接口。
|
|
470
|
+
4. `host/sandbox.py`:新增 E2BSandbox 实现(政务文档校验长任务沙箱隔离)。
|
|
471
|
+
5. `runtime/checkpoint.py`:THS ATU 四元组对齐的 capability 元数据与 checkpoint 版本号。
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## 十、FAQ / 已知坑
|
|
476
|
+
|
|
477
|
+
| 症状 | 处理 |
|
|
478
|
+
|---|---|
|
|
479
|
+
| Temporal 拉取镜像 600MB+ 启动慢 | `export AGENTLISP_RUNNER=direct`,使用 `DirectRunner` 跳过 |
|
|
480
|
+
| Docker Compose v1 不识别 `include:` | `docker compose -f infra/docker-compose.infra.yml -f docker/docker-compose.yml ...` 手工合并 |
|
|
481
|
+
| `host.gateway.Gateway().app` 抛 `FeatureNotInstalledError` | `uv pip install -e '.[web]'` |
|
|
482
|
+
| Racket 里 parser 对 `#hash((a . b))` 兼容问题 | `racket --version` 必须 ≥ 8.10;CI 使用 setup-racket v1.11 |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
host/__init__.py,sha256=zx6Crp_QDbKTccz4nDhaokksKEDk2glj8ofAlZlodF0,99
|
|
2
|
+
host/gateway.py,sha256=pdha7XUGhPH4peLz88L6yvS7P5tsZPznwLVR-rMSbhA,4876
|
|
3
|
+
host/gateway_sse.py,sha256=qEhLDv5-zE2lgB-cTb_rY2J9PkNyfFVHM-mLg0Ot7oI,29403
|
|
4
|
+
host/sandbox.py,sha256=7u-VHG7aeOQzfHRN6gkImfbzTqH9_jjCymVBDBEKGM4,4455
|
|
5
|
+
host/sandbox_e2b.py,sha256=76KVKOjMp7tMwtN3QuxDUiqQEnKvI0gNIwnSxGiUK4c,6489
|
|
6
|
+
host/workflow.py,sha256=G50Mea7w6tkTGzxyPov1FiVQfatwKrs9rMOjLN58bc4,34286
|
|
7
|
+
host/workflow_temporal.py,sha256=xJuIVXQ7bcZI41uRBTUh5TEYsKfpRs6rQU1Q18ccuy0,3856
|
|
8
|
+
host/tests/test_infra_docker_e2e.py,sha256=6WA1JS6Wzv9MVQp_QehbaOGzjq0cinFi4C4_7o1rjLY,9556
|
|
9
|
+
runtime/__init__.py,sha256=FdgvzMHkhicXaJxLqd0WniMsrNkIo8qyc6XGwU9t_jc,517
|
|
10
|
+
runtime/base_agent_harness.py,sha256=m0TSBSY2ArtJZNmI1cADHawuInhxnJQ2TMmSO3tkRvY,7075
|
|
11
|
+
runtime/base_harness.py,sha256=6q5J-ptQw5DIsTRvI5FY4aKN4KIRYJwlMNFYVNZaMfA,13756
|
|
12
|
+
runtime/base_harness_v2.py,sha256=VvdzObS1XkGdKkZzpoXNJD6fQgvix2P2mU6UIWpFqSM,63715
|
|
13
|
+
runtime/checker.py,sha256=xknABRu-_KWOlHx7rAtQjaOmYqCnFvTmzlDet4kSaNM,26366
|
|
14
|
+
runtime/checkpoint.py,sha256=pTr9b7sEnoEHVf0RXe7BR-SdufW0RQiyuP9l9IkN3fY,3949
|
|
15
|
+
runtime/errors.py,sha256=UTZ52_GisrJGSAdGmvv8XzTgLOwifG6EfMRlR6mret4,983
|
|
16
|
+
runtime/llm_client.py,sha256=lxR6K7ITBHcMaDKTNCYVI1LmiWhAoFri1AEFhPdutWs,25394
|
|
17
|
+
runtime/mcp_client.py,sha256=gkpoG8nLC6ZJaVdAPlGjUjr5X9EgtOI3rgxaSZMGPW4,2949
|
|
18
|
+
runtime/memory_fs.py,sha256=HDlUcVFEzT9D2FQ-MVQKpdWcTEnp9eFg-auuZ0Nt3ik,3179
|
|
19
|
+
runtime/otel_tracer.py,sha256=VRgGDt1vxblvWtU-echaQxRI8A6VZkSA5vp3yonK9vY,4097
|
|
20
|
+
runtime/status_bar.py,sha256=e6FbV22MJNrBwKGCqe1ONgXLuUnNTORTewhgvCgxLDk,3050
|
|
21
|
+
runtime/tests/test_ac1_rackunit_18cases_roundtrip.py,sha256=3pxDx84GndjXA-JPq99ZAN84LBjQv5Fipoyp28E8JZU,7601
|
|
22
|
+
runtime/tests/test_cli_if_cli_1_exit_encoding.py,sha256=6L30pz4AQggLF9mu6JERtJ5qn2CYY7VOzIQ-56r35_I,11212
|
|
23
|
+
runtime/tests/test_harness_v2.py,sha256=Mzre9cQ2ymfclc86IgzU3b4rC7uYEpmPomhaKNmW4bg,93686
|
|
24
|
+
runtime/tests/test_sideeffect_builtin_tools_racket_and_python_ssot_8_items_bitwise_equal.py,sha256=BEZAZHg05ZkgJeu3MPcN7RgvJE9bgZ07iTk8NubanDQ,4775
|
|
25
|
+
runtime/tests/test_srs_acceptance.py,sha256=zaKjG0GtOaVTwztKSGOkjo2m6nfWkPysaFtfXyMnqTM,59606
|
|
26
|
+
runtime/tests/test_t2_bench_dataset.py,sha256=0gBwNzT60IpBts16CCA7y9QXFM1vd9_BsOR3YGCSEUE,3441
|
|
27
|
+
runtime/tests/test_v2_smoke.py,sha256=pZQAMtQIKEEEAVa01gRsaCN-y1V6VKS9Ghd5YyNhzKM,4186
|
|
28
|
+
agentlisp_runtime/__init__.py,sha256=9PKf99wlgICSO_KX9uz4o0Ktgl-g4YbuGAWY222hemA,526
|
|
29
|
+
agentlisp_runtime/cli.py,sha256=v3GdESdxwitQ7aowg8dUGqUoF0rUXQTYRkSmZszXu_w,4633
|
|
30
|
+
agentlisp_runtime/engine.py,sha256=8MyOUd9T8DA6od2Q2TA7UuCFj5p4VOYzTKqtkMbiIGQ,8292
|
|
31
|
+
agentlisp_runtime/loader.py,sha256=kKQVivMqj0IN4eLFVOy_0AnuH19mRbB3vcW8P8LJFs8,3831
|
|
32
|
+
agentlisp_runtime/models.py,sha256=4WT59juYH4JA7uShSymAmu-sSD1fAgzldMq9f89C7G0,3433
|
|
33
|
+
agentlisp-2.0.0.dist-info/METADATA,sha256=yXJLp9BTgRKzlaX8wbUWHQ_WoU23Sfo9XNKe5Hb3xGE,24165
|
|
34
|
+
agentlisp-2.0.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
35
|
+
agentlisp-2.0.0.dist-info/entry_points.txt,sha256=cAeu8SXaQqlDreUm-SIomY4gkCRPg3oxwn0uVMikvYE,85
|
|
36
|
+
agentlisp-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Agent Lisp Runtime - Python execution engine for Scheme-defined Agent DSL."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .engine import AgentEngine
|
|
6
|
+
from .loader import AgentLoader
|
|
7
|
+
from .models import (
|
|
8
|
+
Agent,
|
|
9
|
+
AtomicAction,
|
|
10
|
+
ExecutionContext,
|
|
11
|
+
ExecutionResult,
|
|
12
|
+
Step,
|
|
13
|
+
Tool,
|
|
14
|
+
Workflow,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__version__ = "0.1.0"
|
|
18
|
+
__all__ = [
|
|
19
|
+
"Agent",
|
|
20
|
+
"AgentEngine",
|
|
21
|
+
"AgentLoader",
|
|
22
|
+
"AtomicAction",
|
|
23
|
+
"ExecutionContext",
|
|
24
|
+
"ExecutionResult",
|
|
25
|
+
"Step",
|
|
26
|
+
"Tool",
|
|
27
|
+
"Workflow",
|
|
28
|
+
"__version__",
|
|
29
|
+
]
|