Held While Waiting: What LLM Agent Sessions Reserve on Serverless and Agent Runtimes

Agent Other Agents AI Systems and Hardware Other AI Sys & HW
2026年11月19日
大语言模型(LLM)智能体几乎将全部时间耗费在等待模型响应上。在 Amazon Bedrock 的 AgentCore 平台上,我们的智能体每次等待模型回复的中位时长为 2.7 秒,而实际执行计算的时间仅需约 5 至 40 毫秒。AgentCore 在等待期间不向用户收取 CPU 使用费用;但其为每一场对话单独预留一个运行环境——即一台拥有独立内存的虚拟机,并持续保留该环境,直至对话正式结束。因此,1000 场并发对话会占用 1000 个独立环境,而这些环境所承载的实际计算负载,仅相当于 2 至 15 个处理器核心的工作量。换言之,服务往往先因环境资源耗尽而达到瓶颈,远早于其计算能力被完全用尽。 这一资源短缺问题源于两个原因,且各自均有对应的解决路径。其一,对话结束后环境仍被持续保留:在我们开展的客服场景基准测试中,单场对话平均持续时间为 33 秒,但其对应环境却默认额外保留长达 15 分钟,除非客户端主动显式关闭该对话;其二,每个环境仅服务于单一对话,而该对话绝大部分时间处于空闲等待状态:在我们的模拟实验中,若让 64 场对话共享同一个环境,则所需环境总数可减少至原先的 1/59;同时,99% 的模型回复延迟可控制在最多 40 毫秒以内。 上述毫秒级延迟数值仅为估算值,因其实际测量难度较大:我们曾尝试采用三种不同方法——使用模拟模型(stubbed model)、在模型调用外层添加计时器、以及将各执行步骤严格串行运行——结果均得到看似合理却明显偏低的数值。本文亦将说明如何规避这三种测量方式各自的系统性偏差。在上述两项优化措施中,“及时关闭环境”仅需客户端配合即可实现;而“环境共享”则需平台层支持——在我们调研的各类智能体运行时(agent runtimes)中,目前仅有一款部分支持该功能。其之所以坚持为每场对话分配独立环境,根本原因在于:智能体需运行由模型动态选择的工具乃至任意代码,故必须确保各对话间严格隔离。当前尚未解决的关键开放性问题是:如何在不为每场对话长期独占预留环境的前提下,依然保障其运行时的安全隔离性。
LLM agents spend nearly all their time waiting for the model. On Amazon Bedrock AgentCore, our agents waited a median of 2.7 seconds for each model reply, then computed for an estimated 5 to 40 milliseconds. AgentCore does not charge for CPU during the wait. But it reserves a separate environment, a virtual machine with its own memory, for every conversation, and keeps it reserved until the conversation is closed. So 1,000 conversations reserve 1,000 environments to do the work of 2 to 15 processor cores. A service runs out of environments long before it runs out of processing power. The shortage has two causes, and each has a fix. An environment stays reserved after its conversation ends: in the customer-service benchmark we ran, a conversation lasts 33 seconds on average, but its environment is held for 15 minutes more unless the client closes it. And an environment serves only one conversation, which is mostly waiting: in our simulation, 64 conversations sharing one environment need 59 times fewer environments, and 99 of every 100 replies are delayed by at most 40 milliseconds. The milliseconds are an estimate because they are hard to measure: a stubbed model, a timer around the model call, and steps run back to back each gave a plausible number that was too low. We show how to avoid all three. Of the two fixes, closing needs only the client. Sharing needs the platform, and of the agent runtimes we surveyed only one allows it, in part. They keep conversations apart because an agent runs tools, and sometimes code, chosen by a model. The open problem is to keep them apart without reserving an environment for each while it waits.
许愿