Parallel AI Agent Execution: Concurrency Without Chaos
Parallel AI agents help when useful work can proceed independently. The engineering challenge is keeping tasks independent long enough to benefit: shared files, external services, review capacity, and failed workers can turn apparent concurrency into extra coordination. Start with a dependency graph and a resource budget, then decide how many agents to run.
AI-assisted technical guide with linked primary sources. Examples are illustrative unless stated otherwise. How these guides are made.
Find independent outputs before starting more agents
Separate a task because its outputs can be produced independently, not because its prompt contains several verbs. Reading three independent specifications is a reasonable fan-out operation. Implementing a database migration and code that depends on its final schema usually needs an agreed contract first. Otherwise one worker guesses while another changes the assumptions.
Anthropic’s agent architecture guide describes parallelization for independently divisible work or multiple perspectives. Its pattern is useful vocabulary, not a guarantee that concurrent agents improve a particular repository. Evaluate the resulting workflow against a simpler baseline.
For each candidate task, write its required inputs, owned outputs, and acceptance evidence. Add an edge whenever one output depends on another. An independent reviewer can begin exploring a codebase early, but reviewing the final implementation remains downstream of that implementation. Counting both activities as fully parallel hides a real dependency.
Work through the critical path of one change
Consider an illustrative account-export feature. Assume contract definition takes 10 minutes, a serializer takes 20, an endpoint takes 30, and integration review takes 15. These are invented planning estimates, not measured agent performance. A serial schedule takes 75 minutes. If the contract makes the serializer and endpoint independent, the ideal parallel schedule takes 10 + max(20, 30) + 15 = 55 minutes, before coordination overhead.
| Work item | Owns | Must wait for |
|---|---|---|
| Serializer worker | Export formatting and unit tests | Approved input/output contract |
| Endpoint worker | Authorization, route, route tests | Approved serializer interface |
| Integration owner | Combined behavior and merge | Both completed outputs |
Suppose coordination adds 12 minutes. The estimate becomes 67 minutes, leaving little advantage over serial work. A third worker cannot shorten the 30-minute endpoint branch merely by existing. Focus on the longest dependency chain, and record actual timings later to replace guesses. Include approval and review waiting in elapsed delivery time.
Budget workers, tools, and reviewers separately
A single maximum-agent setting is insufficient. Three agents may each launch four tool calls, all of which hit one rate-limited API. Define separate limits for active workers, outstanding provider requests, heavyweight local test processes, and changes waiting for review. A worker slot should not imply unlimited access to every downstream resource.
Start conservatively and adjust from observed queue age, failure rates, and resource use. A small task that mainly waits on network responses has different constraints from a repository build that consumes local memory. Increasing concurrency when the laptop is already swapping can make every worker slower.
Assign budgets to the whole task, including retries. A worker that receives a fresh unlimited budget after every failure can consume more than the coordinator intended. Stop accepting new work when a task’s deadline or shared budget makes completion implausible, and surface the partial result explicitly.
Isolate mutable resources beyond the working directory
Git worktrees provide separate checked-out directories associated with one repository. A practical parallel coding setup gives each worker its own branch and worktree, then assigns the package manifest, dependency lockfile, and other shared decisions to explicit owners. Read the worktree workflow for setup and cleanup.
File separation does not isolate database schemas, development ports, shared caches, cloud accounts, or deployment targets. Give tests task-specific fixtures or databases where practical. Allocate ports before launching development servers. Serialize operations that mutate a shared environment when isolation is unavailable.
Do not let two workers resolve a common dependency version independently. Agree that change before fan-out or assign it to one owner and make the other tasks depend on its result. Worktrees are an editing convenience, not a security boundary: permissions still determine what a process can read or change.
Apply backpressure before the pending queue grows
Bound both execution and admission. A semaphore can limit active calls while leaving thousands of tasks already allocated in memory. For a long task stream, use a bounded input queue with a fixed worker pool. Python’s asyncio queue documentation specifies that a positive maximum size makes an awaited put wait when the queue is full. That mechanism can make a producer slow down instead of accumulating unlimited pending work.
A proposed scheduler might admit at most six pending coding assignments while running two workers. These numbers are illustrative policy choices. Admission should also pause if the completed-review queue exceeds its limit. Otherwise the system optimizes implementation activity while your actual bottleneck is reviewing and integrating changes.
Queue records should identify the task, input revision, dependencies, resource requirements, and deadline. Reject stale inputs before execution. Keeping a queue small makes it easier to reconsider priorities when new evidence changes the plan.
Choose what the join does when a worker fails
Fan-in requires a policy, not simply a list of responses. For the account-export example, a missing authorization implementation blocks release even if the serializer succeeded. Preserve the successful artifact, mark the combined task incomplete, and decide whether the failed branch is retryable. A research summary might instead accept partial coverage if it clearly identifies what is missing.
Python’s TaskGroup documentation describes structured task lifetimes and sibling cancellation when a task fails with an exception other than cancellation. It also cautions against swallowing cancellation exceptions. Those are runtime semantics; your application must still decide whether a failure should propagate or become an explicit partial-result record.
Cancellation is not rollback. A request may have reached an external service before its caller was cancelled. Before retrying an operation with side effects, determine whether it already happened and whether the operation supports a stable idempotency key. Preserve worker outputs and diagnostics before cleanup, and require deliberate review for uncertain external state.
Integrate artifacts with evidence and traceable ownership
Require a compact completion record: task identifier, starting revision, changed files or artifact location, checks executed, results, and unresolved decisions. Keep worker errors distinct from missing validation. A successful process exit cannot establish that the intended behavior exists.
Integrate one branch at a time, using the repository’s merge policy, then test combined behavior. Separate worker tests can pass while the endpoint supplies values in a format the serializer does not accept. Add a check through the actual export path, including authorization and escaping. Record the exact integrated revision so later failures can be reproduced.
For local Claude Code and Codex sessions, Purrvio can reduce the effort of finding a waiting worker. Its Mac preview observes supported session records and processes and offers supported terminal navigation. It does not dispatch the workers, enforce queue limits, or verify the merge. If local session visibility is your missing piece, try the free Mac preview. It supports macOS 13+ on Apple silicon and Intel; the locally signed preview is not Apple-notarized.
Use a checklist before increasing concurrency
- Confirm that each worker has stable inputs and an independently reviewable output.
- Identify the critical path and include coordination, human waiting, and integration in the estimate.
- Assign ownership of shared files, external environments, ports, and dependency changes.
- Bound pending tasks, active workers, downstream tool calls, and review inventory separately.
- Choose fail-fast or partial-result behavior before launching the workers.
- Preserve successful artifacts and reconcile uncertain side effects before retries.
- Validate the integrated revision before declaring the parent task complete.
Increase concurrency only when these observations show room to benefit. If review queues grow or integration mistakes dominate, narrow the task split or reduce active workers. The useful outcome is verified delivery, not the largest number of simultaneous agent processes.
Frequently asked questions
How many AI agents should I run in parallel?
Choose a limit from the independence of the work, local resources, provider limits, and your review capacity. Start with a small number, measure elapsed delivery and integration failures, and increase only when the bottleneck can benefit.
Does a semaphore prevent an agent queue from growing indefinitely?
A semaphore limits the work that enters its protected operation. It does not automatically bound already-created tasks or queued input. Use bounded admission and a fixed worker pool when the input stream can grow.
Will cancelling a worker undo its tool actions?
No. Cancellation requests that ongoing work stop; it does not reverse completed changes or external requests already accepted. Preserve evidence, inspect the affected systems, and follow an explicit recovery policy before retrying.
Sources and further reading
Primary references checked for this guide on 10 November 2026. Documentation can change; confirm version-specific behavior before using commands in a production workflow.
- Anthropic: Building effective agents
Primary description of parallelization and the tradeoffs of adding agentic workflow complexity.
- Git worktree documentation
Primary reference for separate working trees associated with one repository; does not establish security isolation.
- Python asyncio queues
Documents positive queue capacity, blocked put operations, and asynchronous queue behavior used to explain backpressure.
- Python asyncio coroutines and tasks
Documents TaskGroup failure propagation, cancellation behavior, and structured concurrency caveats.