When is it unsafe to execute multiple agent tool calls in parallel?
By Thrive AI Editorial · Created 2026-10-07 · Updated 2026-10-08
Thrive AI Editorial · AI-assisted worked example, not a member conversation.
An agent proposes fetching an account, fetching a policy and preparing a recommendation. The recommendation requires both earlier results. Running every proposed call concurrently produces missing or stale inputs. How should the executor distinguish independent work from dependent work?
This editorial example validates a small dependency graph without running tools or calling a model.
0 score
Sign in to vote or contribute. Scores count actual member votes, not editorial endorsements.
1 published answer
A selected solution is chosen by the question author or moderator, not an independent certification. Check assumptions before using any code in production.
Thrive AI Editorial · Selected solution
AI-assisted editorial answer · not member testimony
2026-10-07
Jump to a section 4 section links
Multiple proposed calls do not imply independence
Concurrency is safe only when the operations' data and effect dependencies permit it. A recommendation that needs a freshly fetched account cannot run correctly before that fetch completes. Two independent reads may be parallelizable, while two writes to the same resource may conflict even if neither consumes the other's output.
The application executes tool calls and maps outputs to the corresponding call identifiers. It must enforce a valid execution plan rather than assuming that a model's list is a concurrency contract.
Python 3, standard library only. This builds dependency layers; it does not perform parallel execution. Every graph is validated before any side effect would be allowed.
Python27 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27deflayers(graph):
known = set(graph)
ifany(notset(deps) <= known for deps in graph.values()):
raise ValueError("unknown dependency")
remaining = {node: set(deps) for node, deps in graph.items()}
completed = set()
plan = []
while remaining:
ready = sorted(node for node, deps in remaining.items()
if deps <= completed)
ifnot ready:
raise ValueError("dependency cycle")
plan.append(ready)
completed.update(ready)
for node in ready:
del remaining[node]
return plan
graph = {"account": [], "policy": [],
"recommendation": ["account", "policy"]}
plan = layers(graph)
assert plan == [["account", "policy"], ["recommendation"]]
print("execution layers:", plan)
try:
layers({"a": ["b"], "b": ["a"]})
except ValueError as error:
print(error)
Validate the graph's identifiers, dependency references and cycles before beginning. Resolve outputs by stable call identity rather than whichever operation finishes first. Validate each result before supplying it to a dependent step.
Dependencies in a model proposal are untrusted. The application knows additional requirements: authorization, mutually exclusive resource mutations, transaction boundaries, concurrency limits and human approvals. Add those constraints or reject the plan. A missing edge is not proof that two effects commute.
Handle failures explicitly. If fetching policy fails, do not let a downstream recommendation proceed using an empty object and describe it as validated. Decide whether independent successful work remains useful, whether siblings should be canceled and how late results are reconciled.
Test ordering, not just final text
Record execution events and assert that every prerequisite completed successfully before its dependent step began. Test out-of-order completion, a missing result, duplicate call identifiers, a cycle and one slow dependency. Use harmless fixtures before enabling external writes.
The example does not implement a distributed scheduler, concurrent result storage or rollback. It shows one invariant: a validated dependency plan can separate independent layers from dependent steps. Real effects still need their own concurrency and retry protections.
Source checked 2026-10-08: OpenAI function calling describes application-side execution and call/output correspondence. The graph algorithm, effect-dependency discussion and tests are our own AI-assisted material, not an automatic provider execution guarantee.
0 score
Sign in to vote or contribute. Scores count actual member votes, not editorial endorsements.