Skip to content

Commit 1ae944b

Browse files
xuanyang15copybara-github
authored andcommitted
chore: Migrate computer to use the new feature decorator
Co-authored-by: Xuan Yang <[email protected]> PiperOrigin-RevId: 842287104
1 parent 32e87f6 commit 1ae944b

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

src/google/adk/tools/computer_use/base_computer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
import pydantic
2323

24-
from ...utils.feature_decorator import experimental
24+
from ...features import experimental
25+
from ...features import FeatureName
2526

2627

27-
@experimental
28+
@experimental(FeatureName.COMPUTER_USE)
2829
class ComputerEnvironment(str, Enum):
2930
"""Case insensitive enum for computer environments."""
3031

@@ -34,7 +35,7 @@ class ComputerEnvironment(str, Enum):
3435
"""Operates in a web browser."""
3536

3637

37-
@experimental
38+
@experimental(FeatureName.COMPUTER_USE)
3839
class ComputerState(pydantic.BaseModel):
3940
"""Represents the current state of the computer environment.
4041
@@ -51,7 +52,7 @@ class ComputerState(pydantic.BaseModel):
5152
)
5253

5354

54-
@experimental
55+
@experimental(FeatureName.COMPUTER_USE)
5556
class BaseComputer(abc.ABC):
5657
"""async defines an interface for computer environments.
5758

src/google/adk/tools/computer_use/computer_use_tool.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
from typing import Any
2020
from typing import Callable
2121

22-
from google.genai import types
2322
from typing_extensions import override
2423

24+
from ...features import experimental
25+
from ...features import FeatureName
2526
from ...models.llm_request import LlmRequest
26-
from ...utils.feature_decorator import experimental
2727
from ..function_tool import FunctionTool
2828
from ..tool_context import ToolContext
2929
from .base_computer import ComputerState
3030

3131
logger = logging.getLogger("google_adk." + __name__)
3232

3333

34-
@experimental
34+
@experimental(FeatureName.COMPUTER_USE)
3535
class ComputerUseTool(FunctionTool):
3636
"""A tool that wraps computer control functions for use with LLMs.
3737
3838
This tool automatically normalizes coordinates from a virtual coordinate space
3939
(by default 1000x1000) to the actual screen size. This allows LLMs to work
40-
with a consistent coordinate system regardless of the actual screen dimensions,
41-
making their output more predictable and easier to handle.
40+
with a consistent coordinate system regardless of the actual screen
41+
dimensions, making their output more predictable and easier to handle.
4242
"""
4343

4444
def __init__(
@@ -52,13 +52,14 @@ def __init__(
5252
5353
Args:
5454
func: The computer control function to wrap.
55-
screen_size: The actual screen size as (width, height) in pixels.
56-
This represents the real dimensions of the target screen/display.
57-
virtual_screen_size: The virtual coordinate space dimensions as (width, height)
58-
that the LLM uses to specify coordinates. Coordinates from the LLM are
59-
automatically normalized from this virtual space to the actual screen_size.
60-
Default is (1000, 1000), meaning the LLM thinks it's working with a
61-
1000x1000 pixel screen regardless of the actual screen dimensions.
55+
screen_size: The actual screen size as (width, height) in pixels. This
56+
represents the real dimensions of the target screen/display.
57+
virtual_screen_size: The virtual coordinate space dimensions as (width,
58+
height) that the LLM uses to specify coordinates. Coordinates from the
59+
LLM are automatically normalized from this virtual space to the actual
60+
screen_size. Default is (1000, 1000), meaning the LLM thinks it's
61+
working with a 1000x1000 pixel screen regardless of the actual screen
62+
dimensions.
6263
6364
Raises:
6465
ValueError: If screen_size or virtual_screen_size is not a valid tuple
@@ -161,6 +162,5 @@ async def run_async(
161162
async def process_llm_request(
162163
self, *, tool_context: ToolContext, llm_request: LlmRequest
163164
) -> None:
164-
"""ComputerUseToolset will add this tool to the LLM request and add computer
165-
use configuration to the LLM request."""
165+
"""ComputerUseToolset will add this tool to the LLM request and add computer use configuration to the LLM request."""
166166
pass

src/google/adk/tools/computer_use/computer_use_toolset.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
from typing_extensions import override
2626

2727
from ...agents.readonly_context import ReadonlyContext
28+
from ...features import experimental
29+
from ...features import FeatureName
2830
from ...models.llm_request import LlmRequest
29-
from ...utils.feature_decorator import experimental
3031
from ..base_toolset import BaseToolset
3132
from ..tool_context import ToolContext
3233
from .base_computer import BaseComputer
@@ -38,7 +39,7 @@
3839
logger = logging.getLogger("google_adk." + __name__)
3940

4041

41-
@experimental
42+
@experimental(FeatureName.COMPUTER_USE)
4243
class ComputerUseToolset(BaseToolset):
4344

4445
def __init__(
@@ -68,9 +69,12 @@ async def adapt_computer_use_tool(
6869
"""Adapt a computer use tool by replacing it with a modified version.
6970
7071
Args:
71-
method_name: The name of the method (of BaseComputer class) to adapt (e.g. 'wait').
72-
adapter_func: A function that accepts existing computer use async function and returns a new computer use async function.
73-
Can be either sync or async function. The name of the returned function will be used as the new tool name.
72+
method_name: The name of the method (of BaseComputer class) to adapt (e.g.
73+
'wait').
74+
adapter_func: A function that accepts existing computer use async function
75+
and returns a new computer use async function. Can be either sync or
76+
async function. The name of the returned function will be used as the
77+
new tool name.
7478
llm_request: The LLM request containing the tools dictionary.
7579
"""
7680
# Validate that the method is a valid BaseComputer method
@@ -173,8 +177,7 @@ async def close(self) -> None:
173177
async def process_llm_request(
174178
self, *, tool_context: ToolContext, llm_request: LlmRequest
175179
) -> None:
176-
"""Add its tools to the LLM request and add computer
177-
use configuration to the LLM request."""
180+
"""Add its tools to the LLM request and add computer use configuration to the LLM request."""
178181
try:
179182

180183
# Add this tool to the tools dictionary

0 commit comments

Comments
 (0)