arXiv:2605.28617cs.AIcs.PL2026-05被引 1

让大模型自己写运行代码,还能保证安全,不乱来。

LACUNA: Safe Agents as Recursive Program Holes

  • 用类型检查约束模型生成的代码,确保每步操作合法
  • 测试中8.6%代码被拒绝,平均0.7次重试,准确率达27.1%
  • 适合需要高安全性与复杂逻辑的智能体系统

大型语言模型代理越来越依赖编写代码执行任务,但运行时环境与模型生成的代码之间存在割裂:运行时控制流程、上下文和循环结构由外部决定,模型无法参与。若允许模型生成的代码修改运行时本身,虽能提升表达力,却也加剧安全风险——一次提示注入、错误调用工具或中途失败,都可能造成不可逆状态。本文提出LACUNA,一种新型代理编程模型,在保持安全的前提下弥合这一鸿沟。每个代理动作以类型化形式 `agent[T](task)` 表示,由大模型填充代码,执行前进行类型检查。若代码不合规,则整条动作被拒绝,环境不变,且通过编译诊断引导重试。该机制同时限制工具使用、数据流与作用域。其原语可自然表达ReAct循环、子代理、技能调用、并行分解与多模型规划等复杂结构。在BrowseComp-Plus和τ²-bench两个基准上评估:在BrowseComp-Plus中,8.6%的生成代码被拒绝,平均0.7次重试/查询,达到27.1%准确率;在τ²-bench上,使用强模型完成392项任务中的76.0%,性能与基线相当。

原文摘要 · Abstract (English)

LLM agents increasingly act by writing code, yet a split persists between the runtime that drives the agent and the code the model writes. The runtime owns the loop, context, and control flow, and the model has little say over any of them. Letting model-written code shape the runtime itself would make agents more expressive, but it would also sharpen safety problems. A model can be diverted by a prompt injection, call the wrong tool, or fail partway and leave an inconsistent state, and each such failure reaches further when the code shapes the runtime than when it expresses a single action. We present LACUNA, a programming model for agents that closes this split while preserving safety. Each agent action is a typed call $\texttt{agent[T](task)}$ that the LLM fills with code when execution reaches it, and the code is type-checked against the surrounding program before it runs. Because each action is accepted or rejected as a whole, a rejected one leaves the environment untouched, and its compiler diagnostics drive a retry. The same check also bounds which tools and data an action may use and how they flow. Our primitive expresses ReAct loops, sub-agents, skills, parallel decomposition, and multi-model planning as ordinary control flow. We evaluate LACUNA on a collection of test cases, BrowseComp-Plus, and $τ^2$-bench. On BrowseComp-Plus, $8.6\%$ of generations are rejected before execution, with 0.7 retries per query on average, and the agent reaches $27.1\%$ accuracy. On $τ^2$-bench, LACUNA solves $76.0\%$ of $392$ tasks across four domains with a capable model, on par with the baseline agent.

智能体安全代码生成类型检查

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。