Problem 9 of 15 in the Harnessing Agentic AI Systems series — read the index for the framing. Previous: Schema Enforcement & Self-Correction Pattern · Next: Mock Tool Virtualization Pattern.
The Problem — Not blocking the loop on long tools
Some tools take minutes. The loop must stay live while the work happens elsewhere, and cancellation must be a contract. There is no named anti-pattern; its failure modes — the blocking loop and the abandoned worker — are in the tradeoffs.
| Field | P10 — Asynchronous Tool Worker Queue (pattern) |
|---|---|
| Forces | Responsiveness vs correctness; tracking ID vs done work; cancellation contract vs worker completion. |
| Solution | Offload long-running processes to background task workers and hand a tracking ID to the looping agent. |
| Consequences | The loop stays live; the context holds a tracking ID instead of the worker's output, so the window stays lean. A worker queue is a daemon that satisfies all four durable-daemon conditions. |
| Tradeoffs | Asynchrony introduces the races of A12; cancellation must be a contract (ABORTED_BEFORE_DISPATCH vs ABORTED); workers must be exactly-once or idempotent; the queue is infrastructure the team owns forever. |
| Evidence | Celery, the production standard for background task execution (docs); DeepSeek's cancellation contract (DeepSeek teardown). |
| Related | Composes with P7 (durability) and P14 (the board's slow writers); its consistency risk is A12. |
Discussion
The queue decouples the loop from the tool: the agent holds a tracking ID, not the worker's output, so the window stays lean and the loop stays live — the context-budgeting benefit is as important as the latency one. The cost is consistency: cancellation must be a contract ("cancellation never abandons the body"), workers must be idempotent, and the queue is infrastructure the team owns forever. Its named risk is A12: asynchrony is how races enter the system.
Key Insight
The loop must never wait on a tool. The tracking ID is the interface, cancellation is the contract, and idempotency is the price of retry — a retried task double-executes unless the worker can deduplicate.
References
Celery (docs); archive: DeepSeek teardown, durable daemons execution.