Skip to content

Commit 32573fb

Browse files
authored
feat(tools/tom_consult): declare resources for parallel execution (#2663)
1 parent ffaa96f commit 32573fb

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

openhands-tools/openhands/tools/tom_consult/definition.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
from openhands.sdk.io import LocalFileStore
1313
from openhands.sdk.llm import ImageContent, TextContent
14-
from openhands.sdk.tool import Action, Observation, ToolDefinition, register_tool
14+
from openhands.sdk.tool import (
15+
Action,
16+
DeclaredResources,
17+
Observation,
18+
ToolDefinition,
19+
register_tool,
20+
)
1521

1622

1723
if TYPE_CHECKING:
@@ -143,6 +149,14 @@ def to_llm_content(self) -> Sequence[TextContent | ImageContent]:
143149
class TomConsultTool(ToolDefinition[ConsultTomAction, ConsultTomObservation]):
144150
"""Tool for consulting Tom agent."""
145151

152+
def declared_resources(self, action: Action) -> DeclaredResources: # noqa: ARG002
153+
"""Declare resources for parallel execution.
154+
155+
Consulting Tom is a read-only LLM call with no shared mutable
156+
state, so it is always safe to run in parallel.
157+
"""
158+
return DeclaredResources(keys=(), declared=True)
159+
146160
@classmethod
147161
@override
148162
def create(

tests/tools/tom_consult/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Tests for TomConsultTool declared_resources."""
2+
3+
import pytest
4+
5+
from openhands.sdk.tool import DeclaredResources
6+
from openhands.tools.tom_consult.definition import (
7+
ConsultTomAction,
8+
ConsultTomObservation,
9+
TomConsultTool,
10+
)
11+
12+
13+
@pytest.mark.parametrize(
14+
"action",
15+
[
16+
ConsultTomAction(reason="unclear intent", use_user_message=True),
17+
ConsultTomAction(
18+
reason="need guidance",
19+
use_user_message=False,
20+
custom_query="What does the user prefer?",
21+
),
22+
],
23+
ids=["use-user-message", "custom-query"],
24+
)
25+
def test_consult_tom_declared_resources(action):
26+
"""TomConsultTool always declares safe with no resource keys."""
27+
tool = TomConsultTool(
28+
action_type=ConsultTomAction,
29+
observation_type=ConsultTomObservation,
30+
description="test",
31+
executor=None,
32+
)
33+
34+
resources = tool.declared_resources(action)
35+
36+
assert isinstance(resources, DeclaredResources)
37+
assert resources.declared is True
38+
assert resources.keys == ()

0 commit comments

Comments
 (0)