当代码变成LLM调用:智能体系统中调用点契约的实证研究 When Code Becomes an LLM Call: An Empirical Study of Call-Site Contracts in Agentic Systems 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-10-17
⬇️ 1 次下载
👁️ 预览文献
💡 AI 中文简介
研究分析了40个开源智能体系统(共496个LLM调用点),发现48%的模型输出直接影响程序控制流或执行,其中73%不经过人工审核。程序在代码中强制了78%的约束,但在提示中67%的约束仅向模型请求。尽管82%的调用点前后有检查,63%的预期约束未被满足,仅5.3%的调用点完全满足契约。研究识别出10种重复模式解释99%的差距,并证明小代码修复可阻止全部38种运行时触发机制。
领域软件工程 / 智能体系统
适合谁读需要一定专业背景(软件工程、LLM应用开发者)
核心贡献首次大规模实证揭示LLM调用点契约的普遍缺失:仅5.3%调用点满足完整契约,并归纳出10种可解释99%差距的模式;提出通过小代码修复强制预期约束可阻止全部38种运行时触发机制。
关键数据分析40个系统(13.4百万行代码,4种语言),496个LLM调用点;48%输出影响控制流/执行,73%无人工介入;代码强制78%约束,提示中67%仅请求;82%调用点有前后检查,但63%预期约束未满足,仅5.3%完全满足;10种模式解释99%差距;38种机制运行时触发,小修复全部阻止。
推荐理由如果你在构建或使用LLM智能体,这项研究用硬数据告诉你:有检查不等于安全,契约缺失是普遍风险,且小修复能解决大问题。
关键词["智能体系统", "LLM调用契约", "软件质量保证", "实证研究", "程序验证", "提示工程"]

原文摘要

查看英文原文摘要

Software quality has long rested on specifications that state what code must do, and on testing and verification that check that the code does it. Agentic systems change this foundation: they replace parts of their logic, such as choosing the next tool, judging whether an action is allowed, or writing code to run, with calls to a large language model (LLM). The program still relies on what this logic must guarantee, but the model's behavior is not fixed by code, varies across runs, and can be steered by its input. The guarantee must therefore come from the program around each LLM call site, as a contract of pre-conditions, prompt constraints, and post-conditions. We present an empirical study of these contracts in 496 LLM call sites of 40 popular open-source agentic systems (13.4 MLOC, four languages). Using a multi-agent pipeline validated by 17,428 human judgments, we trace where every model output flows, derive an expected contract for each call site without access to its code, and compare it with the contract that the code implements. We find that 48% of LLM outputs reach control flow or execution, and 73% of these never reach a person. Programs enforce 78% of their constraints in code, but in the prompt, 67% of the constraints are only requested from the model. Although 82% of call sites are checked before and after the call, 63% of the expected constraints are unmet and only 5.3% of call sites satisfy their whole contract; ten recurring patterns explain 99% of the gaps. 38 mechanisms behind these gaps trigger at runtime, and a small code fix that enforces the expected constraint stops all 38. Our results show that the presence of checks says little about their adequacy, and we derive implications for agent developers, framework maintainers, and researchers.