Repository navigation
Conversation
Expose max_parallel_workers on Agent and forward it to the existing worker scheduler. Validate worker-only limits and preserve ordered outputs, cancellation, and resume behavior. Fixes google#7641
Serialize cancellation persistence and terminal status. Retain completed sibling identities through native replay, free saved-winner capacity from unneeded retries, and require cleanup before repeated winner selection succeeds.
me-her
marked this pull request as ready for review
October 21, 2026 03:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Closes #7641. Related: #7642.
A workflow coordinator can fan out work today, but it lacks an owned group of
handles for inspecting, messaging, selectively cancelling, and accepting results
from those concurrent children. Agent workers also lack the concurrency limit
already available to function workers.
Add
Context.parallel_tasks()and publicParallelTask/ParallelTaskstypes,using the existing dynamic node scheduler and Runner event stream:
The coordinator can continue while children run, wait for any/all handles, gather
ordered results, or cancel an individual owned task.
firstevaluates synchronousor asynchronous acceptance predicates, records its winner, and cancels and drains
remaining work before returning. Rejected results and failed candidates allow
alternatives to continue. Queued admission pauses while acceptance is evaluated.
Explicit task groups add correlation to native events. Bounded FIFO messages have explicit queued,
delivered, and undelivered receipts; delivery occurs at the addressed agent's next
model boundary. Cancellation preserves completed sibling tool results and closes
otherwise unanswered local tool calls. Durable cancellation and merge decisions
survive human-input resume, including transferred child runs.
Completed siblings retain their results through native replay. A restored winner
cannot be blocked by an unnecessary retry occupying the concurrency limit, and
retrying selection after a cleanup timeout still waits for actual termination.
Ordinary
parallel_worker=Trueuses the same task group while retaining orderedoutputs, event metadata, fail-fast cleanup, resume, and O(concurrency-limit) active handles. Expose
max_parallel_workerson Agent/LlmAgent and preserve the original agent whenconstructing its internal worker copy. Update two GEPA mocked-agent fixtures for
the new default field.
State remains native shared session state. Explicit merge accepts returned mapping
proposals, validates selected keys before writes, and records the state delta and
merge disposition in one event. It does not isolate arbitrary worker writes or
undo external side effects. Cancellation is cooperative; a cleanup timeout is
reported, and already sent provider requests may still incur cost. This change
makes no Rust or production latency claim.
The usage guide and runnable three-agent verified-winner sample are included in
this PR. Test fixtures initialize event metadata and consistently
mock cached credential aliases, keeping the full suite independent of local ADC.
Testing Plan
Validation targets
d36495faae14b7514bf05e9d41fe32fdf5e1298c. The full Linuxunit suite passes on all four supported Python versions.
cancellation, model/tool cleanup, bounded admission, observer cancellation,
failures, messaging races, merge conflicts, and both native resume modes.
passes: 407 tests on uv-managed Python 3.12.
exact-revision validation run.
Python 3.11: 20,754 passed; 3.12: 20,745 passed; 3.13: 20,745 passed;
3.14: 20,746 passed. Runs have 93–94 skips, 18 expected failures, and two
non-strict unexpected passes. No failures or errors.
native collaboration
and agent-worker limits
with scripted models and no provider credentials. The collaboration case verifies
four simultaneous agent calls, a rejected early result, an accepted winner,
delivered steering, closed losing generators, progress correlation, and persisted
selected state.
1, 2, and unlimited produce observed peaks 1, 2, and 4 with ordered outputs.
uv buildproducesthe wheel and source distribution.
comparison with unchanged upstream
7c53386introduces no new errors.records 12 repetitions per policy against this installed wheel: median wall
time 138.4 ms for gathering all answers versus 80.6 ms for the first acceptable
result. Both start four local model calls; the latter cancels two workers and
verifies all generators close. Fixed simulated delays establish selection
behavior, not production latency, token savings, or a Python/Rust comparison.
Checklist