chore: Migrate computer to use the new feature decorator

Co-authored-by: Xuan Yang <xygoogle@google.com>
PiperOrigin-RevId: 842287104
This commit is contained in:
Xuan Yang
2025-12-09 10:03:43 -08:00
committed by Copybara-Service
parent 32e87f6381
commit 1ae944b39d
3 changed files with 29 additions and 25 deletions
@@ -21,10 +21,11 @@ from typing import Optional
import pydantic
from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName
@experimental
@experimental(FeatureName.COMPUTER_USE)
class ComputerEnvironment(str, Enum):
"""Case insensitive enum for computer environments."""
@@ -34,7 +35,7 @@ class ComputerEnvironment(str, Enum):
"""Operates in a web browser."""
@experimental
@experimental(FeatureName.COMPUTER_USE)
class ComputerState(pydantic.BaseModel):
"""Represents the current state of the computer environment.
@@ -51,7 +52,7 @@ class ComputerState(pydantic.BaseModel):
)
@experimental
@experimental(FeatureName.COMPUTER_USE)
class BaseComputer(abc.ABC):
"""async defines an interface for computer environments.
@@ -19,11 +19,11 @@ import logging
from typing import Any
from typing import Callable
from google.genai import types
from typing_extensions import override
from ...features import experimental
from ...features import FeatureName
from ...models.llm_request import LlmRequest
from ...utils.feature_decorator import experimental
from ..function_tool import FunctionTool
from ..tool_context import ToolContext
from .base_computer import ComputerState
@@ -31,14 +31,14 @@ from .base_computer import ComputerState
logger = logging.getLogger("google_adk." + __name__)
@experimental
@experimental(FeatureName.COMPUTER_USE)
class ComputerUseTool(FunctionTool):
"""A tool that wraps computer control functions for use with LLMs.
This tool automatically normalizes coordinates from a virtual coordinate space
(by default 1000x1000) to the actual screen size. This allows LLMs to work
with a consistent coordinate system regardless of the actual screen dimensions,
making their output more predictable and easier to handle.
with a consistent coordinate system regardless of the actual screen
dimensions, making their output more predictable and easier to handle.
"""
def __init__(
@@ -52,13 +52,14 @@ class ComputerUseTool(FunctionTool):
Args:
func: The computer control function to wrap.
screen_size: The actual screen size as (width, height) in pixels.
This represents the real dimensions of the target screen/display.
virtual_screen_size: The virtual coordinate space dimensions as (width, height)
that the LLM uses to specify coordinates. Coordinates from the LLM are
automatically normalized from this virtual space to the actual screen_size.
Default is (1000, 1000), meaning the LLM thinks it's working with a
1000x1000 pixel screen regardless of the actual screen dimensions.
screen_size: The actual screen size as (width, height) in pixels. This
represents the real dimensions of the target screen/display.
virtual_screen_size: The virtual coordinate space dimensions as (width,
height) that the LLM uses to specify coordinates. Coordinates from the
LLM are automatically normalized from this virtual space to the actual
screen_size. Default is (1000, 1000), meaning the LLM thinks it's
working with a 1000x1000 pixel screen regardless of the actual screen
dimensions.
Raises:
ValueError: If screen_size or virtual_screen_size is not a valid tuple
@@ -161,6 +162,5 @@ class ComputerUseTool(FunctionTool):
async def process_llm_request(
self, *, tool_context: ToolContext, llm_request: LlmRequest
) -> None:
"""ComputerUseToolset will add this tool to the LLM request and add computer
use configuration to the LLM request."""
"""ComputerUseToolset will add this tool to the LLM request and add computer use configuration to the LLM request."""
pass
@@ -25,8 +25,9 @@ from google.genai import types
from typing_extensions import override
from ...agents.readonly_context import ReadonlyContext
from ...features import experimental
from ...features import FeatureName
from ...models.llm_request import LlmRequest
from ...utils.feature_decorator import experimental
from ..base_toolset import BaseToolset
from ..tool_context import ToolContext
from .base_computer import BaseComputer
@@ -38,7 +39,7 @@ EXCLUDED_METHODS = {"screen_size", "environment", "close"}
logger = logging.getLogger("google_adk." + __name__)
@experimental
@experimental(FeatureName.COMPUTER_USE)
class ComputerUseToolset(BaseToolset):
def __init__(
@@ -68,9 +69,12 @@ class ComputerUseToolset(BaseToolset):
"""Adapt a computer use tool by replacing it with a modified version.
Args:
method_name: The name of the method (of BaseComputer class) to adapt (e.g. 'wait').
adapter_func: A function that accepts existing computer use async function and returns a new computer use async function.
Can be either sync or async function. The name of the returned function will be used as the new tool name.
method_name: The name of the method (of BaseComputer class) to adapt (e.g.
'wait').
adapter_func: A function that accepts existing computer use async function
and returns a new computer use async function. Can be either sync or
async function. The name of the returned function will be used as the
new tool name.
llm_request: The LLM request containing the tools dictionary.
"""
# Validate that the method is a valid BaseComputer method
@@ -173,8 +177,7 @@ class ComputerUseToolset(BaseToolset):
async def process_llm_request(
self, *, tool_context: ToolContext, llm_request: LlmRequest
) -> None:
"""Add its tools to the LLM request and add computer
use configuration to the LLM request."""
"""Add its tools to the LLM request and add computer use configuration to the LLM request."""
try:
# Add this tool to the tools dictionary