Controlling Spawning, Concurrency and Batching
This lesson covers spawning limits, concurrency limits, batching and load levelling, the controls that keep multi-agent execution scalable and predictable when an orchestrator can create subagents and run tasks in parallel.
Learning outcomes
After completing this lesson, you will be able to:
- Limit the spawning of subagent runs.
- Cap concurrency against TPM and RPM limits.
- Use the Batch deployment type and queues to level load.
Controlling spawning
Spawning is the creation of subagent runs by an orchestrator. Without limits, a planner can decompose a task into dozens of subtasks, each of which spawns more. Controls include a maximum number of subagents per run, a maximum delegation depth, a token and time budget per subagent and for the run as a whole, and deduplication of identical subtasks. When a limit is reached, the orchestrator must complete with what it has or escalate, not fail silently.
Spawn controls
Concurrency limits and rate limits
Model deployments have tokens-per-minute (TPM) and requests-per-minute (RPM) limits; tools have their own limits. Concurrency is capped with a semaphore or a worker pool sized so that peak usage stays within quota, and HTTP 429 responses are handled with backoff that honours Retry-After. Spreading load across several deployments or regions through an API Management back-end pool raises the effective limit.
limit = asyncio.Semaphore(8) # sized from the deployment's TPM and average tokens per call
async def run_subagent(task):
async with limit:
return await subagent.run(task, max_tokens=2000)
results = await asyncio.gather(*(run_subagent(t) for t in tasks[:MAX_SUBTASKS]), return_exceptions=True)A concurrency cap that does nothing
Batching and load levelling
Batching groups work. The Batch deployment type processes large volumes of requests from a file asynchronously, within a 24-hour target, at a lower price and with separate quota, which suits offline jobs such as classifying a backlog of documents. Application-level batching combines several small items in one request, for example classifying ten short messages at once, which reduces per-call overhead.
Queue-based load levelling places work items on an Azure Service Bus queue and processes them with workers that scale with queue length (for example Container Apps jobs or apps with KEDA scaling), so bursts are absorbed without exceeding limits. The following table summarizes the controls.
| Control | Protects against | Mechanism |
|---|---|---|
| Spawn limits | Runaway decomposition | Max subagents, depth and budget per run |
| Concurrency cap | Quota exhaustion, HTTP 429 | Semaphores, worker pools sized to TPM |
| Batch deployments | High cost of offline volume | Asynchronous file-based processing |
| Load levelling | Bursts | Service Bus queue with autoscaling workers |
Scaling controls
A nightly backlog
Each night, an agent pipeline enriches 300,000 product descriptions. Running it with high parallelism on the standard deployment causes HTTP 429 errors that slow the daytime customer assistant, which shares the deployment. Results are needed by the next morning.
The enrichment has no real-time requirement, so it should use a Batch deployment, which has its own quota, a lower price and a 24-hour target. The customer assistant keeps the standard deployment to itself. Raising the concurrency cap would worsen the throttling, and provisioned throughput would cost more than needed for an offline job.
How should concurrency be sized for a model deployment?
Show answer
To its tokens-per-minute and requests-per-minute limits, with backoff on HTTP 429 using the Retry-After value.
Exam Tips
Remember for the exam
- Cap subagent count, depth and budget; finish or escalate when limits are hit.
- Size concurrency to TPM and RPM; back off on HTTP 429 with Retry-After.
- Offline volume: Batch deployments. Bursts: Service Bus with autoscaling workers.