将LLM作为代码组件,用程序控制流程,提升智能体稳定性
LLM-as-Code: Agentic Programming for Agent Harness

- 程序主导控制流,LLM仅在需要推理时被调用
- 上下文长度由调用深度决定,避免令牌爆炸
- 适合需要长序列稳定执行的自动化任务
当前主流LLM智能体框架将模型设为编排者,决定下一步操作、工具调用和终止时机。我们指出,令牌膨胀、控制流幻觉和不可靠完成并非实现缺陷,而是将循环、分支和顺序等确定性工作交由概率系统导致的架构问题。更强的提示或模型也无法保证智能体可靠性。为此我们提出「智能体编程」:由程序掌控全部控制流,而LLM作为其中可适应的组件(即LLM-as-Code),仅在任务需推理或生成时被调用。每次调用中模型保持灵活性,但无法更改程序执行路径。控制权归程序后,上下文基于执行历史的调用树构建,形成有向无环图(DAG)。每个调用的上下文长度由其调用深度决定,而非随步骤累积。对计算机使用智能体的案例研究显示,该设计不仅理论可行,且显著提升了长时间视觉操作序列的稳定性。
原文摘要 · Abstract (English)
Every major LLM agent framework gives the LLM the role of orchestrator; the model decides what to do next, when to call tools, and when to stop. We argue that token explosion, control-flow hallucination, and unreliable completion are not implementation bugs but architectural consequences of assigning the deterministic work of looping, branching, and sequencing to a probabilistic system. A better prompt or a stronger model cannot guarantee the reliability of the LLM agent. We therefore propose Agentic Programming, in which the program governs all control flow, and the LLM is itself part of it, an adaptive component we call LLM-as-Code and invoke only where a task calls for reasoning or generation. Within each call the model keeps full flexibility, but it cannot alter the program's execution path. With control in the program, the LLM's context is built from the execution history's call tree and forms a directed acyclic graph (DAG). Each call's context length is then determined by its call depth rather than by accumulation over steps. A case study of computer-use agents shows that the design is practical, not just a theoretical stance, substantially improving the stability of long visual operation sequences.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。