Budgets and Limits for Agent Work

Lesson 3 of 4

Suppress a Repeat Request

Estimated time: 10 minutes

Suppress a repeat request without losing the first

A caller that times out and retries can send the same request twice. If both are carried out, the effect happens twice, and the caller sees only one reply, so the duplicate is invisible from the outside.

Derive the key from caller and intent

The key has to identify the work, not the transport. A key built from the caller and what the caller means to do stays the same across a retry of the same intent.

Return the first result to the repeat

When a key already in flight arrives again, return the result of the first rather than starting the work again. The caller gets a normal answer and the effect happens once.

def handle(call, seen):
    if call.key in seen:
        return seen[call.key]
    seen[call.key] = run(call)
    return seen[call.key]

Bound the record and keep the key strong

Keep keys only as long as a retry could plausibly arrive, so the record does not grow without limit. Make the key specific enough that two genuinely different requests never collapse into one.