为何人类语法会“击溃”大型语言模型(以及如何修复智能体编码)
3 分•作者: aslang•18 天前
完整的技术论文,包含基准测试和抽象语法树(AST)分解:
https://aslang.dev/blog/why-llms-struggle-with-python-and-rust
在过去两年中,我们在观察代码生成代理生成代码时,不断注意到一个相同的失败模式:模型将 32% 到 41% 的推理计算量耗费在语法修复循环中。
当我们深入研究其背后的信息论时,我们意识到问题不在于模型规模,而在于 Transformer 注意力头在面对以人类为中心的语法时所产生的计算几何学:
1. Python 的“越位规则”:词法分析需要一个内部的 LIFO(后进先出)缩进堆栈。关闭 3 个块只发出 0 个字符。单个空格标记的拆分会悄无声息地重新父化 AST 子树。
2. Rust 的借用检查器:有效性取决于跨生命周期和控制流图(CFG)的非局部约束求解。自回归生成是严格向前因果的(O(1) 前馈);它无法在生成过程中向后反向传播生命周期冲突。
我们构建了 AgentScript (ASL):一种开源的、静态类型的语言,使用单遍 S 表达式,可以直接编译为原生 Rust、Go、TypeScript 和 WebAssembly (wasm32-wasip1)。
通过设计强制执行的关键属性:
* 语法平衡括号:从左到右的注意力头始终知道父作用域。
* 封闭词汇表 (prelude.json):100% 的内置函数都经过类型检查和求值;没有未建模的外部调用。
* 亚毫秒级 Wasm 沙箱:在 0.038 毫秒内进行内存中的 WASI preview1 执行,无需 Docker/microVM 启动。
* 语法修复崩溃:模型在 Rust 中花费 46.5% 的生成 token 来修复语法(这是我们的硬基线),在 Python 中则为 34.2%。在 AgentScript 中,与 Rust 基线相比,修复迭代次数减少了 98.3%(从 4.8 个周期减少到 0.08 个),语法修复浪费仅为 1.2%。
我们的使命:为本地开发与小型模型提供最佳的驱动器
虽然云集群上的前沿模型在一定程度上通过暴力破解混乱的人类语法,但我们的使命是为本地开发与小型模型(SLM:3B 到 31B,如 Qwen、Gemma、Llama)构建最有效的自主驱动器,使其直接在开发人员的机器上运行。
在 Apple Silicon 或笔记本电脑上,内存和注意力是宝贵的资源。单遍、括号平衡的语言结合驻留 AST 批量 RPC,消除了导致小型模型失控的语法混乱和上下文衰退。
预发布 Alpha 版和积极开发中:
AgentScript 处于早期预发布 Alpha 阶段——我们还没有 v0.1 的正式发布版本,并且正在积极迁移到 100% 自托管的编译器和 WASI 运行时。但即使在这个阶段,代理循环内的实证结果也令人瞩目。
在本地和您的代理技能中尝试:
我们不提供浏览器内 playground——直接在真实的代理工作流中测试真实的东西:
1. CLI 工具链:curl -fsSL https://aslang.dev/install.sh | bash (或者克隆 GenSEAM/asl & cargo build --release)
2. 为代理技能(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 个总任务)。
* 基线比较:常见的驱动器(Claude Code、Codex、CLI 循环)由于子 shell 状态丢失、引用漂移和上下文膨胀,与开源模型配对时在此套件上得分为 0.0%。纯 ASL 在隔离环境下的 Gemma 31B 上实现了 13.5%。
* Token 经济:与标准代理 CLI 基线相比,节省了 77.3% 的 token。
记录和提交 tarball:https://github.com/GenSEAM/harness
核心编译器和运行时仓库:https://github.com/GenSEAM/asl
我们非常欢迎编译器工程师、语言设计者和系统构建者对语法设计和代理控制架构提出宝贵的反馈!
查看原文
Full technical essay with benchmarks & AST breakdowns:
https://aslang.dev/blog/why-llms-struggle-with-python-and-rust<p>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.<p>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.<p>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).<p>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%.<p>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.<p>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.<p>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.<p>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"))'<p>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.<p>Transcripts & submission tarball: https://github.com/GenSEAM/harness
Core compiler & runtime repo: https://github.com/GenSEAM/asl<p>We would love critical feedback from compiler engineers, language designers, and systems builders on the grammar design and agent steering architecture!