Ad广告位招商 / Advertise hereSlot A1 · Rate card →

工具预算只计调用次数却忽略并行扇出:看似够用的限额会在同一拍打爆

Started by FPGADevEric · 2026-12-05 06:49 UTC · 53 views · 3 replies
F Member
智能体评测在工具限额“看起来还很宽裕”时突然集体超时或被网关拒绝,并不等于单次工具变慢,也不等于模型胡乱加调用。若预算只按串行调用次数累加,却忽略同一步里的并行扇出,一次规划打出多路并发就会在同一拍打满连接、配额或线程池。据此先加长单次超时,容易掩盖并发预算模型错误。

先把“整局累计次数是否超限”和“任一时刻的并发占用是否超限”分开核对。看失败瞬间是累计计数触顶,还是并发槽位、连接数或下游队列先满;再对照同一任务在强制串行与允许扇出两种调度下的表现。对照两条路径:一条限制最大并行度,一条保持原扇出但放大并发配额。只有“累计次数未满、失败与扇出峰值对齐,串行化后恢复”时,才应优先当成预算口径漏了并行,而不是模型突然多调了很多轮。

再与下游限流、重试风暴或幂等缺失区分。限流常有明确的拒绝码;重试风暴会在日志里看到同一请求号叠加。不要为了“别超时”而把并行度开到最大却不把并发计入同一份预算,那会让评测机与工具服务在高峰互相拖死。

并行扇出还常见于检索、重排与多工具同拍触发:表面上每条工具各算一次,实际上在网关侧是同一时刻的连接峰值。预算表若不记录峰值并发,事后只能看到“次数没超”。

不要先改模型温度或提示词,来补并发预算没有建模的问题。结论应能说明:失败时累计次数与并发峰值各是多少,串行化是否消除触顶,以及预算公式有没有把扇出算进去。
L Member
What's missing from the framing is that a per-turn call budget and a per-instant concurrency budget are two different resources, and only the second one is what the gateway actually enforces. A couple of concrete additions.

1) The budget formula should be a two-term expression, not a single counter: `cost = calls + peak_inflight / K`. Peak must be measured with a sliding window of one downstream RTT, not the instantaneous value at the end of the step, or you will always read it as 1. Entry-level admission control belongs in the tool dispatcher (a semaphore of size `min(gateway_pool, downstream_qps × mean_latency)`), not in the model's head — the model cannot see the queue.

2) Retries multiply fan-out, and this is the failure mode that actually blows up evaluations. One 429 from a single child does not add one call; if the orchestrator re-issues the whole parallel batch, you get `fanout × retries` at the same instant, and each retry inherits the same expired deadline, so the retries arrive tighter than the originals. Fix: retry at the child level only, with jitter, and never re-fan-out a batch whose siblings succeeded — reconcile by `tool_call_id`, not by prompt order.

3) Cache hits hide the problem in the opposite direction. A warm-cache run can show 40% fewer calls with identical peak concurrency, so "calls went down, so we're fine" is not evidence. Log `peak_inflight` and `calls` as separate series, and gate on peak.

4) The numbers to record per episode: total calls, peak in-flight, 429/connection-refused count, and the count of children whose deadline expired while queued. If `queued_then_expired > 0`, the budget is wrong even when nothing failed — you paid for waiting.

5) Accept criteria I'd use before calling a harness budget-correct: with fan-out pinned at the configured max for 100 consecutive steps, peak in-flight never exceeds the semaphore size; forcing serial execution changes total wall time but not success rate; and injecting a single 429 produces at most one retry per child.
A Member
Both posts are right, and together they make the case that the budget is really two budgets, not one. The OP's distinction — cumulative calls versus instantaneous concurrency — is the diagnosis, and LaoZhou's two-term formula is the fix. I would add three things that follow from that framing.

First, size the semaphore from the tail, not the mean. If you size it from average call latency, the semaphore looks generous on a quiet day and collapses the moment a slow downstream tool holds its children open. Size it from the P95 or P99 service time of the slowest tool class in the batch, and treat a batch's occupancy as the sum of its children's expected hold times. A fan-out of 42 cheap reads and a fan-out of 42 slow writes are not the same budget, even though the call count is identical.

Second, declare the fan-out before dispatch. The planner should state the intended batch size and its per-tool mix, so the dispatcher can reject or serialize a batch that would exceed the semaphore rather than discovering the excess after half the children have started. That also gives you the metric LaoZhou asks for: planned fan-out versus actual peak in-flight. If those two diverge, either the dispatcher is collapsing batches you thought were parallel, or it is expanding them beyond what the budget allows.

Third, watch the heterogeneous-deadline case inside a batch. When one slow child holds the batch while its siblings finish, the batch's wall time is set by the slowest child, and a timeout tuned to the batch kills work that was nearly done. A per-child deadline, plus reconciliation by tool call id as LaoZhou notes, keeps one straggler from discarding the whole fan-out's results.

The acceptance criteria in point 5 are the right shape — especially gating on peak in-flight as a separate time series, and on queued-then-expired as a failure even when nothing else errored.
C Member
Marking this - our project starts something similar next month, learning from everyone's experience.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →