🔶 为什么人类语法会难倒 LLM(以及如何修复智能体编程)
英文标题:🔶 Why human syntax breaks LLMs (and how to fix agentic coding)
作者称,在代码智能体生成代码的过程中,模型有 32% 至 41% 的推理计算耗费在语法修复循环中,根源在于 Python 缩进规则和 Rust 借用检查等人类中心语法对 Transformer 自回归生成机制提出的结构性挑战。为此,团队推出开源静态类型语言 AgentScript(ASL),采用单遍 S 表达式语法,并可编译至 Rust、Go、TypeScript 和 WebAssembly。其测试称,ASL 将相较 Rust 基线的语法修复迭代次数从 4.8 次降至 0.08 次,降幅达 98.3%,语法修复浪费仅占 1.2%。团队还报告,在严格隔离环境下,搭载 Gemma 4 31B 的 ASL 在 Terminal-Bench 4.0 的 89 项任务中通过 12 项,并相较标准 Agent CLI 基线节省 77.3% Token。
43 B
中文
完整技术文章,含基准测试与 AST 拆解:https://aslang.dev/blog/why-llms-struggle-with-python-and-rust
过去两年里,在观察代码智能体生成代码时,我们不断注意到一种完全相同的失败模式:模型有 32% 到 41% 的推理计算被困在语法修复循环中。
当我们研究其背后的信息论问题时,发现问题不在于模型规模,而在于 Transformer 注意力头面对以人类为中心的语法时所呈现的计算几何特性:
- Python 的 off-side(缩进)规则:词法分析需要内部维护一个 LIFO 缩进栈。关闭 3 个代码块不会输出任何字符。一次空白字符的 Token 切分,就可能悄然改变 AST 子树的父级归属。
- Rust 的借用检查器:有效性取决于跨生命周期和控制流图(CFG)的非局部约束求解。自回归生成严格遵循前向因果关系(
O(1)前馈);它无法在生成期间,将生命周期冲突反向传播回先前内容。
我们构建了 AgentScript(ASL):一种开源、静态类型语言,使用单遍 S 表达式,可直接编译为原生 Rust、Go、TypeScript 和 WebAssembly(wasm32-wasip1)。
通过语言构造机制保证的关键特性:
- 由语法保证括号配对:从左至右处理的注意力头始终能够了解父级作用域。
- 封闭词汇表(
prelude.json):100% 的内置项都会被进行类型检查和求值;不存在未建模的外部调用。 - 亚毫秒级 Wasm 沙箱:在内存中执行 WASI preview1 的耗时为 0.038ms,无需启动 Docker 或 microVM。
- 语法修复大幅收敛:模型在 Rust 中会将 46.5% 的生成 Token 用于修复语法问题(我们的高难度基线),在 Python 中则为 34.2%。在 AgentScript 中,相较 Rust 基线,修复迭代次数下降 98.3%(从 4.8 次降至 0.08 次),语法修复浪费仅为 1.2%。
我们的使命:为小模型的本地开发打造最佳 Harness
云端集群上的前沿模型能够在一定程度上以暴力计算方式应对混乱的人类语法;而我们的使命,是为直接运行在开发者机器上的小语言模型(SLM,即 Qwen、Gemma、Llama 等 3B 至 31B 模型)构建最有效的自主开发 Harness。
在 Apple Silicon 或笔记本电脑上,内存和注意力资源都十分宝贵。单遍、括号配对的语言,加上常驻 AST 批量 RPC,可消除会让小模型偏离轨道的语法反复修复和上下文衰减问题。
预发布 Alpha 与积极开发中:AgentScript 目前仍处于早期预发布 Alpha 阶段——我们尚未发布带标签的 v0.1 版本,并且正在积极迁移至 100% 自托管的编译器与 WASI 运行时。但即使处于这一阶段,其在智能体循环中的实证结果也极具吸引力。
在本地及你的 Agent Skills 中试用:我们不提供浏览器内 Playground——请直接在真实的智能体工作流中测试:
- CLI 工具链:
curl -fsSL https://aslang.dev/install.sh | bash(或克隆GenSEAM/asl并执行cargo build --release) - 为 Agent Skills(Claude Code、Cursor、Antigravity)配备 AST 验证和批量 RPC:
asl rpc '(:batch (:out "src/main.asl") (:sym "my_func"))'
Terminal-Bench 4.0 基线(宏观结果,而非挑选性展示):我们将基线提交打包并用于 Terminal-Bench 4.0 测试(在严格隔离边界下测试 Gemma 4 31B):
- 宏观通过率:在全部 89 项评估任务中,通过率为 13.5%(12 项验证通过 / 89 项任务总数)。
- 基线对比:常见 Harness(Claude Code、Codex、CLI 循环)在搭配开放权重模型时,在该测试套件中的得分为 0.0%;原因是子 Shell 状态丢失、引用漂移和上下文膨胀。纯 ASL 在隔离环境中的 Gemma 31B 上达到 13.5%。
- Token 经济性:相较标准 Agent CLI 基线节省 77.3% Token。
测试记录与提交 tarball:https://github.com/GenSEAM/harness
核心编译器与运行时仓库:https://github.com/GenSEAM/asl
我们希望获得编译器工程师、语言设计师和系统构建者针对语法设计及智能体引导架构的批判性反馈!
English / 原文
Full technical essay with benchmarks & AST breakdowns: https://aslang.dev/blog/why-llms-struggle-with-python-and-rust
Over the past two years, watching coding agents generate code, we kept noticing an identical failure pattern: models spend 32% to 41% of their inference compute trapped in syntax repair loops.
When we investigated the information theory behind this, we realized the problem is not model scale—it is the computational geometry of transformer attention heads when confronted with human-centric grammars: 1. Python's off-side rule: Lexing requires an internal LIFO indentation stack. Closing 3 blocks emits 0 characters. A single whitespace token split silently re-parents AST subtrees. 2. Rust's borrow checker: Validity depends on non-local constraint solving across lifetimes and CFGs. Autoregressive generation is strictly forward causal (O(1) feedforward); it cannot backpropagate lifetime conflicts backward during generation.
We built AgentScript (ASL): an open-source, statically typed language using single-pass S-expressions that compiles directly to native Rust, Go, TypeScript, and WebAssembly (wasm32-wasip1).
Key properties enforced by construction: * Balanced parentheses by grammar: Left-to-right attention heads always know parent scope. * Closed vocabulary (prelude.json): 100% of builtins are type-checked and evaluated; no unmodeled foreign calls. * Sub-millisecond Wasm sandboxing: In-memory WASI preview1 execution in 0.038ms without Docker/microVM spin-up. * Syntax repair collapse: Models spend 46.5% of generated tokens fixing syntax in Rust (our hard baseline) and 34.2% in Python. In AgentScript, repair iterations drop by 98.3% vs Rust baseline (from 4.8 cycles to 0.08), cutting syntax repair waste to just 1.2%.
Our Mission: The Best Harness for Local Development with Small Models While frontier models on cloud clusters partially brute-force messy human grammars, our mission is to build the most effective autonomous harness for local development with small models (SLMs: 3B to 31B like Qwen, Gemma, Llama) running directly on developer machines.
On Apple Silicon or laptops, memory and attention are precious. A single-pass, parenthesis-balanced language combined with resident AST batch RPC eliminates the syntax churn and context rot that derail small models.
Pre-Release Alpha & Active Development: AgentScript is in early pre-release alpha—we do not have a tagged v0.1 release yet and are actively migrating to a 100% self-hosted compiler & WASI runtime. But even at this stage, empirical results inside agent loops are remarkably compelling.
Try It Locally & In Your Agent Skills: We do not offer an in-browser playground—test the real thing directly in realistic agent workflows: 1. CLI toolchain: curl -fsSL https://aslang.dev/install.sh | bash (or clone GenSEAM/asl & cargo build --release) 2. Equip agent skills (Claude Code, Cursor, Antigravity) with AST verification and batch RPC: asl rpc '(:batch (:out "src/main.asl") (:sym "my_func"))'
Terminal-Bench 4.0 Baseline (Macro Results, Not Cherry-Picked): We packaged our baseline submission on Terminal-Bench 4.0 (tested on Gemma 4 31B under strict airgap boundaries): * Macro Pass Rate: 13.5% across all 89 evaluated tasks (12 verified passes / 89 total tasks). * Baseline Comparison: Common harnesses (Claude Code, Codex, CLI loops) score 0.0% on this suite when paired with open-weights models due to subshell state loss, quoting drift, and context blowup. Pure ASL achieves 13.5% on Gemma 31B in airgap. * Token Economy: 77.3% token savings vs standard agent CLI baselines.
Transcripts & submission tarball: https://github.com/GenSEAM/harness Core compiler & runtime repo: https://github.com/GenSEAM/asl
We would love critical feedback from compiler engineers, language designers, and systems builders on the grammar design and agent steering architecture!