Heuristic:3641397194 wq Gpt6 Astra Round Limit Clamping
| Knowledge Sources | |
|---|---|
| Domains | AI_Agents, Optimization |
| Last Updated | 2026-10-26 14:00 GMT |
Overview
Clamp the AI agent loop's maximum rounds to the range [1, 16] with a default of 8 to bound cost and prevent runaway loops.
Description
The `runAgent` function accepts a `maxRounds` parameter from user input. Before use, the value is passed through the `integer()` helper, which applies a default of 8 when the value is undefined/empty, and throws if the value is outside [1, 16]. This ensures the agent loop always has a finite, bounded number of iterations regardless of user input, preventing both runaway loops (cost explosion) and zero-round loops (no execution).
Usage
Use this heuristic when configuring AI agent loops that make paid API calls per round. The clamp prevents accidental cost overruns from misconfigured round limits while ensuring at least one round executes. The default of 8 provides a reasonable balance between thoroughness and cost for most security analysis tasks.
The Insight (Rule of Thumb)
- Action: Pass `maxRounds` through `integer(input.maxRounds, 8, 1, 16, 'maxRounds')`
- Value: Default = 8, Min = 1, Max = 16
- Trade-off: Complex tasks may hit the 16-round ceiling without completing; the loop returns `status: 'partial'` with a round-limit message
- Compatibility: Hard limit; throws if user provides a value outside range
Reasoning
Each agent round makes one API call to the relay adapter, which costs API credits. Without an upper bound, a misconfigured or adversarial input could cause hundreds of rounds, incurring significant cost. The 16-round maximum caps worst-case cost at 16 API calls per task. The minimum of 1 ensures the loop executes at least once. The default of 8 covers most web recon and binary analysis chains (e.g., resolve → scan → inspect → crawl → find → check = 6 tools, plus retry rounds).
Code Evidence
Round limit clamping from `agent.js:31`:
const rounds = integer(input.maxRounds, 8, 1, 16, 'maxRounds');
The `integer` helper from `common.js:3-7`:
function integer(value, fallback, min, max, label = 'number') {
const n = value === undefined || value === '' ? fallback : Number(value);
if (!Number.isSafeInteger(n) || n < min || n > max) throw new Error(`${label}: expected integer ${min}..${max}`);
return n;
}
Round-limit return from `agent.js:48`:
return { status: 'partial', summary: '已到本次 AI 调用轮数上限;保留实际结果,尚未取得最终总结。', calls, rounds };