Two agents politely disagreeing for forty rounds is not “reasoning” — it is a token furnace. Production swarms need budgets, stop conditions, and a human gate after N rounds so ping-pong cannot become the default control flow.
⚡ TL;DR: Cap rounds, tokens, and wall-clock per run. Detect oscillation (repeated REJECT reasons). After N critic failures, route to a human with a one-page brief — never auto-loop overnight.
Budgets as first-class state
# runtime/budget.py
from dataclasses import dataclass
@dataclass
class RunBudget:
max_rounds: int = 4
max_tokens: int = 200_000
max_wall_s: int = 900
tokens_used: int = 0
rounds: int = 0
def charge(self, tokens: int):
self.tokens_used += tokens
if self.tokens_used > self.max_tokens:
raise RuntimeError("budget_tokens_exhausted")
def tick_round(self):
self.rounds += 1
if self.rounds > self.max_rounds:
raise RuntimeError("budget_rounds_exhausted")
Detect oscillation
def oscillating(history: list[str]) -> bool:
if len(history) < 4:
return False
# ✅ same reject fingerprint twice in a row pair
return history[-1] == history[-3] and history[-2] == history[-4]
When oscillation trips, stop — do not “try a stronger model” in a loop without a new plan hash.
Human after N rounds
// gates/human.ts
export type Gate = { kind: "continue" } | { kind: "human"; brief: string };
export function afterCritic(rounds: number, verdict: { decision: string; evidence: string[] }): Gate {
if (verdict.decision === "ACCEPT") return { kind: "continue" };
if (rounds >= 3) {
return {
kind: "human",
brief: `Stuck after ${rounds} rounds.\nEvidence:\n- ${verdict.evidence.join("\n- ")}`,
};
}
return { kind: "continue" };
}
❌ “Keep going until ACCEPT” with no human path — that is how weekend bills appear.
Closing checklist
- [ ] Enforce round + token + wall-clock budgets
- [ ] Hash reject reasons; detect oscillation
- [ ] Escalate to humans with a structured brief
- [ ] Persist budget counters in the run record
- [ ] Alert when runs hit caps frequently
Series navigation
Day 52: Blackboard vs Message Bus Orchestration · Day 54: Specialist Tools per Agent
Last updated September 11, 2026
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.
