Skip to content

Commit 1366a0b

Browse files
VascoSch92openhands-agentenyst
authored
Deprecate DelegateTool in favor of TaskToolSet (#2668)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: enyst <engel.nyst@gmail.com>
1 parent 887698b commit 1366a0b

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

openhands-tools/openhands/tools/delegate/definition.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
"""Delegate tool definitions for OpenHands agents."""
1+
"""Delegate tool definitions for OpenHands agents.
2+
3+
.. deprecated:: 1.16.0
4+
DelegateTool is deprecated in favor of TaskToolSet. Use TaskToolSet for
5+
sub-agent delegation. DelegateTool will be removed in version 1.23.0.
6+
"""
27

38
import pathlib
49
from collections.abc import Sequence
@@ -14,6 +19,7 @@
1419
ToolAnnotations,
1520
ToolDefinition,
1621
)
22+
from openhands.sdk.utils.deprecation import warn_deprecated
1723

1824

1925
if TYPE_CHECKING:
@@ -61,7 +67,12 @@ class DelegateObservation(Observation):
6167

6268

6369
class DelegateTool(ToolDefinition[DelegateAction, DelegateObservation]):
64-
"""A ToolDefinition subclass that automatically initializes a DelegateExecutor."""
70+
"""A ToolDefinition subclass that automatically initializes a DelegateExecutor.
71+
72+
.. deprecated:: 1.16.0
73+
DelegateTool is deprecated in favor of TaskToolSet. Use TaskToolSet for
74+
sub-agent delegation. DelegateTool will be removed in version 1.23.0.
75+
"""
6576

6677
@classmethod
6778
def create(
@@ -72,6 +83,9 @@ def create(
7283
) -> Sequence["DelegateTool"]:
7384
"""Initialize DelegateTool with a DelegateExecutor.
7485
86+
.. deprecated:: 1.16.0
87+
Use TaskToolSet instead. DelegateTool will be removed in version 1.23.0.
88+
7589
Args:
7690
conv_state: Conversation state (used to get workspace location)
7791
max_children: Maximum number of concurrent sub-agents (default: 5)
@@ -84,6 +98,13 @@ def create(
8498
Returns:
8599
List containing a single delegate tool definition
86100
"""
101+
warn_deprecated(
102+
"DelegateTool",
103+
deprecated_in="1.16.0",
104+
removed_in="1.23.0",
105+
details="Use TaskToolSet instead for sub-agent delegation.",
106+
)
107+
87108
# Import here to avoid circular imports
88109
from openhands.sdk.subagent import get_factory_info
89110
from openhands.tools.delegate.impl import DelegateExecutor

tests/tools/delegate/test_delegation.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import json
44
import uuid
5+
import warnings
56
from pathlib import Path
67
from unittest.mock import MagicMock, patch
78

9+
from deprecation import DeprecatedWarning
810
from pydantic import SecretStr
911

1012
from openhands.sdk.agent.utils import fix_malformed_tool_arguments
@@ -21,7 +23,7 @@
2123
DelegateExecutor,
2224
DelegateObservation,
2325
)
24-
from openhands.tools.delegate.definition import DelegateAction
26+
from openhands.tools.delegate.definition import DelegateAction, DelegateTool
2527
from openhands.tools.preset import register_builtins_agents
2628

2729

@@ -547,3 +549,22 @@ def test_spawn_no_persistence_when_parent_has_none():
547549
sub_conv = executor._sub_agents["sub1"]
548550
# The sub-conversation should have no persistence_dir
549551
assert sub_conv._state.persistence_dir is None
552+
553+
554+
def test_delegate_tool_create_emits_deprecation_warning():
555+
"""DelegateTool.create() emits a deprecation warning."""
556+
register_builtins_agents()
557+
558+
conv_state = MagicMock()
559+
conv_state.workspace.working_dir = "/tmp"
560+
561+
with warnings.catch_warnings(record=True) as w:
562+
warnings.simplefilter("always")
563+
DelegateTool.create(conv_state)
564+
565+
deprecation_warnings = [
566+
warning for warning in w if issubclass(warning.category, DeprecatedWarning)
567+
]
568+
assert len(deprecation_warnings) == 1
569+
assert "DelegateTool" in str(deprecation_warnings[0].message)
570+
assert "TaskToolSet" in str(deprecation_warnings[0].message)

0 commit comments

Comments
 (0)