Practical technical guides / Agent-era architecture

Many Agents, One Budget: Conditional Decrements, Escrow Allocations and Reclaim

Eight agent workers granting credit from one daily budget. Compare check-then-act, a central conditional decrement and escrow with and without reclaim.

By Sandeep Belgavi · Published 2026-12-04 · Prepared 2026-12-03

One shared limit, many agent workers
Original explanatory diagram; synthetic values where shown.

Eight agent workers granting credit from one daily budget. Compare check-then-act, a central conditional decrement and escrow with and without reclaim.

Many agents, one budget

Once a team runs more than one agent worker, some limit is usually shared between them. At the help desk of Belgavi's Book Store, agents may grant goodwill credit to customers whose orders went wrong: a damaged copy, a late delivery, a return that took too long. The business sets a daily goodwill budget of 6,000 credit points. Eight agent workers handle cases in parallel, and each decides on its own whether a case deserves credit and how much.

The judgement is the part that needs a model. Whether the total stays under 6,000 does not. A shared limit is an invariant, and invariants belong in deterministic code that every worker must pass through. The interesting design question is not whether to enforce the limit but where, because the obvious place creates a bottleneck and the obvious way around the bottleneck quietly breaks the limit.

Database researchers met this problem long before agents. Patrick O'Neil's 1986 paper on the escrow transactional method (ACM Transactions on Database Systems, DOI 10.1145/7239.7265) addresses aggregate fields, such as a quantity on hand, that many transactions update at once. Instead of locking the field for the whole transaction, each transaction reserves the amount it needs, provided the reservation keeps the field within its bounds. The same idea, applied to agent workers, gives a budget design that scales without overspending.

Four designs for the same budget

Check-then-act. Each worker reads the remaining budget, decides, and later records its spend. This is what you get when an agent calls a tool that returns "remaining: 2,140" and then calls another tool to grant credit. Between the read and the write, other workers do the same thing against the same stale number.

Central conditional decrement. Every grant is a single atomic operation on one counter: subtract the amount only if the result stays at or above zero. In SQL that is an UPDATE ... SET remaining = remaining - :amount WHERE remaining >= :amount, and the row count tells you whether the grant happened. It cannot overspend, but every grant touches the same row.

Escrow. Part of the budget is split into per-worker allocations up front. A worker approves from its own allocation without touching the shared counter, and asks the shared pool for a refill only when its allocation runs short. The sum of allocations plus the pool never exceeds the budget, so overspending is impossible by construction.

Escrow with reclaim. Like escrow, but when the shared pool cannot cover a refill, unused allocations are pulled back from the other workers first.

Worked example: one day of goodwill credit

The companion lab replays a synthetic day: 400 credit requests arriving on average every 200 ms, a mean request of 20 points, eight workers, a 6,000-point budget, and, for check-then-act, 1,500 ms between reading the balance and the write landing, which is roughly what a model call between two tool calls costs. Escrow pre-allocates half the budget, 375 points per worker, and refills in blocks of 200. The figures below are from that simulation, not from production traffic.

DesignApprovedPoints grantedOverspendRejected while budget remained elsewhereShared-counter operations
Check-then-act2986,1311310400
Central decrement2966,00000400
Escrow3055,984079110
Escrow with reclaim2966,00000213

Check-then-act overspends by 131 points even at this modest rate. Shorten the gap between requests to 20 ms and it grants 7,494 points against a 6,000 budget, an overspend of 1,494. The approvals are not wrong individually; each worker saw enough budget when it looked.

Plain escrow cuts shared-counter traffic from 400 operations to 110, but rejects 79 requests while budget was still sitting with other workers, and ends the day with 16 points unused in worker allocations. It approves more requests than the central counter but grants fewer points, so the set of customers who received credit changed. Whether a request succeeds now depends on which worker it landed on, which is not a policy anyone chose. Pre-allocating the whole budget makes this worse: 106 rejections, all of them while points remained elsewhere, and 92 points left unused at the end of the day.

Escrow with reclaim matches the central counter exactly on outcomes, with 213 shared operations instead of 400. The cost appears in the peak: reclaiming touches every worker's allocation at once, so the busiest second has 18 shared operations instead of 10.

The reservation is the deterministic part

Whichever design you choose, the worker's model never writes to the budget directly. It proposes a grant; deterministic code reserves it or refuses it, and the agent sees the result as a tool response.

import sqlite3

def setup(db, budget):
    db.execute("CREATE TABLE IF NOT EXISTS pool (day TEXT PRIMARY KEY, remaining INTEGER NOT NULL CHECK (remaining >= 0))")
    db.execute("CREATE TABLE IF NOT EXISTS grants (case_id TEXT PRIMARY KEY, day TEXT, amount INTEGER)")
    db.execute("INSERT OR IGNORE INTO pool VALUES ('2026-12-03', ?)", (budget,))

def reserve(db, day, case_id, amount):
    """Grant credit only if the budget covers it. Safe to retry with the same case_id."""
    with db:  # one transaction
        if db.execute("SELECT 1 FROM grants WHERE case_id = ?", (case_id,)).fetchone():
            return "already granted"
        cur = db.execute("UPDATE pool SET remaining = remaining - ? WHERE day = ? AND remaining >= ?",
                         (amount, day, amount))
        if cur.rowcount != 1:
            return "refused: budget exhausted"
        db.execute("INSERT INTO grants VALUES (?, ?, ?)", (case_id, day, amount))
        return "granted"

db = sqlite3.connect(":memory:")
setup(db, 50)
print([reserve(db, "2026-12-03", c, 20) for c in ("CASE-6001", "CASE-6002", "CASE-6001", "CASE-6003")])
# ['granted', 'granted', 'already granted', 'refused: budget exhausted']

An escrow allocation is the same function with a different row: each worker has its own remaining, and a refill is a transaction that moves points from the pool row to the worker row with the same conditional update on the pool. The CHECK constraint is a last line of defence; the conditional WHERE clause is what makes the refusal a normal outcome instead of an error.

Note what the agent's tool returns. It should report the outcome, not the remaining balance. A balance invites the model to reason about it, and reasoning about a number that other workers are changing is exactly check-then-act again.

Choosing a design

Start with the central conditional decrement. A single row updated a few times a second is not a bottleneck for any mainstream database, and agent workers are slow: each decision includes at least one model call. Most teams never need anything else.

Move to escrow when the shared counter genuinely limits throughput or availability: workers in several regions, a counter in a store with per-key write limits, or a requirement that workers keep approving small amounts while the central store is unreachable. Add reclaim, or a short allocation lifetime that returns unused points to the pool, as soon as you do, because plain escrow trades shared traffic for false rejections, and a customer turned away while budget remained is a policy failure even if no limit was broken.

Migration steps

  1. Find every place an agent reads a budget, quota or stock level before acting. Each one is a check-then-act race unless the act itself re-checks.
  2. Replace the pair of tools with one reservation tool that takes the case id and amount and returns granted, refused or already granted. Make it idempotent on the case id so retries are safe.
  3. Remove the balance from the agent's context, or label it as informational and stale.
  4. Measure grants per second on the shared counter. Only if it is a real constraint, introduce per-worker allocations, a refill size and a reclaim rule.
  5. Reconcile daily: the sum of grants must equal the budget minus the remaining pool and allocations. A mismatch is an incident.

Failure modes

  • Overspend under load. Check-then-act looks fine in testing and fails when traffic rises, because the race window is the model latency.
  • Stranded budget. Escrow without reclaim rejects requests while points sit unused with idle workers. Track rejections that happened while budget remained elsewhere as their own metric.
  • Lost allocations. A worker that crashes holding an allocation takes those points with it until something returns them. Give allocations an owner and an expiry.
  • Reclaim storms. Reclaim touches every allocation at once. If it fires on every shortfall near the end of the day, peak load on the shared store rises, as the example shows.

When agents are unnecessary

If the decision is a fixed rule, such as "late delivery earns 10 points", there is no judgement to delegate and the whole flow is a deterministic function plus a reservation. Use an agent where the amount or eligibility genuinely needs reading the case. Even then the agent proposes and the reservation decides. The budget is the same whether one worker or eight are asking, and its enforcement should not change when the model does.

Interactive experiment

Shared agent budget: check-then-act, central counter or escrow. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.

Primary references and authorship

Sources checked 2026-12-03. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/shared_budget_escrow. Views are my own and do not represent any employer, past or present.