DRAFT: feat: add ParallelToolExecutor and ToolExecutorSemaphore for parallel tool execution#2390
Draft
VascoSch92 wants to merge 1 commit intomainfrom
Draft
DRAFT: feat: add ParallelToolExecutor and ToolExecutorSemaphore for parallel tool execution#2390VascoSch92 wants to merge 1 commit intomainfrom
VascoSch92 wants to merge 1 commit intomainfrom
Conversation
… tool execution Add infrastructure for executing multiple tool calls concurrently with a configurable global concurrency limit. Classes: - ToolExecutorSemaphore: Process-global singleton that limits concurrent tool executions across all agents and sub-agents. Configured via OPENHANDS_TOOL_CONCURRENCY_LIMIT environment variable (default: 8). - ParallelToolExecutor: Executes batches of tool calls concurrently using ThreadPoolExecutor, with concurrency controlled by the semaphore. Key design decisions: - Single layer of concurrency control via environment variable - Singleton pattern using __new__ for ToolExecutorSemaphore - ThreadPoolExecutor for I/O-bound tool execution - Results returned in original order regardless of completion order Related to #2350 Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
API breakage checks (Griffe)Result: Passed |
Contributor
Agent server REST API breakage checks (OpenAPI)Result: Failed Log excerpt (first 1000 characters) |
Contributor
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.
Summary
This PR adds infrastructure for executing multiple tool calls concurrently with a configurable global concurrency limit, as proposed in #2350.
Classes Added
ToolExecutorSemaphoreProcess-global singleton that limits concurrent tool executions across all agents and sub-agents.
__new__:ToolExecutorSemaphore()always returns the same instanceOPENHANDS_TOOL_CONCURRENCY_LIMIT(default: 8)with semaphore: ...ParallelToolExecutorExecutes batches of tool calls concurrently using
ThreadPoolExecutor.ActionEventobjects and atool_runnercallableDesign Decisions
Single layer of concurrency control
We use only
OPENHANDS_TOOL_CONCURRENCY_LIMITto control concurrency. TheThreadPoolExecutoris sized to the batch, but the semaphore gates actual execution. This keeps configuration simple.Singleton pattern with
__new__The semaphore uses
__new__for the singleton pattern, so anyone instantiatingToolExecutorSemaphore()gets the same instance. Noget_instance()method needed.Why
ThreadPoolExecutor?Tool execution is I/O-bound (terminal commands, file operations, MCP network calls). Python's GIL is released during I/O, so threads work well. Also follows existing patterns in
base.py:322-339.No
reset()method exposedFor testing, we directly reset class attributes via pytest fixtures rather than exposing a public reset method.
Integration Points (not in this PR)
This PR provides the infrastructure. Integration requires changes to:
Agent._execute_actions()- UseParallelToolExecutorinstead of sequential loopDelegateExecutor._delegate_tasks()- Wrap sub-agent execution with semaphore to prevent concurrency explosion when delegating to multiple sub-agentsConcurrency explosion scenario (from issue #2350):
With the semaphore (e.g.,
OPENHANDS_TOOL_CONCURRENCY_LIMIT=8), max 8 tool executions run at once across all agents.Usage
export OPENHANDS_TOOL_CONCURRENCY_LIMIT=4Tests
13 tests covering:
Related to #2350
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:0250777-pythonRun
All tags pushed for this build
About Multi-Architecture Support
0250777-python) is a multi-arch manifest supporting both amd64 and arm640250777-python-amd64) are also available if needed