Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/google/adk/a2a/converters/event_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _get_context_metadata(
("custom_metadata", event.custom_metadata),
("usage_metadata", event.usage_metadata),
("error_code", event.error_code),
("actions", event.actions),
]

for field_name, field_value in optional_fields:
Expand Down
28 changes: 28 additions & 0 deletions src/google/adk/features/_feature_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
class FeatureName(str, Enum):
"""Feature names."""

BIG_QUERY_TOOLSET = "BIG_QUERY_TOOLSET"
BIG_QUERY_TOOL_CONFIG = "BIG_QUERY_TOOL_CONFIG"
BIGTABLE_TOOL_SETTINGS = "BIGTABLE_TOOL_SETTINGS"
COMPUTER_USE = "COMPUTER_USE"
GOOGLE_CREDENTIALS_CONFIG = "GOOGLE_CREDENTIALS_CONFIG"
GOOGLE_TOOL = "GOOGLE_TOOL"
JSON_SCHEMA_FOR_FUNC_DECL = "JSON_SCHEMA_FOR_FUNC_DECL"
PROGRESSIVE_SSE_STREAMING = "PROGRESSIVE_SSE_STREAMING"
SPANNER_TOOLSET = "SPANNER_TOOLSET"
SPANNER_TOOL_SETTINGS = "SPANNER_TOOL_SETTINGS"


class FeatureStage(Enum):
Expand Down Expand Up @@ -59,15 +66,36 @@ class FeatureConfig:

# Central registry: FeatureName -> FeatureConfig
_FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
FeatureName.BIG_QUERY_TOOLSET: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.BIG_QUERY_TOOL_CONFIG: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.BIGTABLE_TOOL_SETTINGS: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.COMPUTER_USE: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.GOOGLE_CREDENTIALS_CONFIG: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.GOOGLE_TOOL: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.JSON_SCHEMA_FOR_FUNC_DECL: FeatureConfig(
FeatureStage.WIP, default_on=False
),
FeatureName.PROGRESSIVE_SSE_STREAMING: FeatureConfig(
FeatureStage.WIP, default_on=False
),
FeatureName.SPANNER_TOOLSET: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.SPANNER_TOOL_SETTINGS: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
}

# Track which experimental features have already warned (warn only once)
Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/_google_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
from ..auth.auth_credential import AuthCredentialTypes
from ..auth.auth_credential import OAuth2Auth
from ..auth.auth_tool import AuthConfig
from ..utils.feature_decorator import experimental
from ..features import experimental
from ..features import FeatureName
from .tool_context import ToolContext


@experimental
@experimental(FeatureName.GOOGLE_CREDENTIALS_CONFIG)
class BaseGoogleCredentialsConfig(BaseModel):
"""Base Google Credentials Configuration for Google API tools (Experimental).

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/bigquery/bigquery_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

from __future__ import annotations

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName
from .._google_credentials import BaseGoogleCredentialsConfig

BIGQUERY_TOKEN_CACHE_KEY = "bigquery_token_cache"
BIGQUERY_DEFAULT_SCOPE = ["https://www.googleapis.com/auth/bigquery"]


@experimental
@experimental(FeatureName.GOOGLE_CREDENTIALS_CONFIG)
class BigQueryCredentialsConfig(BaseGoogleCredentialsConfig):
"""BigQuery Credentials Configuration for Google API tools (Experimental).

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/bigquery/bigquery_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
from . import data_insights_tool
from . import metadata_tool
from . import query_tool
from ...features import experimental
from ...features import FeatureName
from ...tools.base_tool import BaseTool
from ...tools.base_toolset import BaseToolset
from ...tools.base_toolset import ToolPredicate
from ...tools.google_tool import GoogleTool
from ...utils.feature_decorator import experimental
from .bigquery_credentials import BigQueryCredentialsConfig
from .config import BigQueryToolConfig


@experimental
@experimental(FeatureName.BIG_QUERY_TOOLSET)
class BigQueryToolset(BaseToolset):
"""BigQuery Toolset contains tools for interacting with BigQuery data and metadata."""

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/bigquery/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from pydantic import ConfigDict
from pydantic import field_validator

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName


class WriteMode(Enum):
Expand All @@ -47,7 +48,7 @@ class WriteMode(Enum):
"""All write operations are allowed."""


@experimental('Config defaults may have breaking change in the future.')
@experimental(FeatureName.BIG_QUERY_TOOL_CONFIG)
class BigQueryToolConfig(BaseModel):
"""Configuration for BigQuery tools."""

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/bigtable/bigtable_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

from __future__ import annotations

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName
from .._google_credentials import BaseGoogleCredentialsConfig

BIGTABLE_TOKEN_CACHE_KEY = "bigtable_token_cache"
Expand All @@ -24,7 +25,7 @@
]


@experimental
@experimental(FeatureName.GOOGLE_CREDENTIALS_CONFIG)
class BigtableCredentialsConfig(BaseGoogleCredentialsConfig):
"""Bigtable Credentials Configuration for Google API tools (Experimental).

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/bigtable/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

from pydantic import BaseModel

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName


@experimental('Tool settings defaults may have breaking change in the future.')
@experimental(FeatureName.BIGTABLE_TOOL_SETTINGS)
class BigtableToolSettings(BaseModel):
"""Settings for Bigtable tools."""

Expand Down
9 changes: 5 additions & 4 deletions src/google/adk/tools/computer_use/base_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

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."""

Expand All @@ -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.

Expand All @@ -51,7 +52,7 @@ class ComputerState(pydantic.BaseModel):
)


@experimental
@experimental(FeatureName.COMPUTER_USE)
class BaseComputer(abc.ABC):
"""async defines an interface for computer environments.

Expand Down
28 changes: 14 additions & 14 deletions src/google/adk/tools/computer_use/computer_use_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
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

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__(
Expand All @@ -52,13 +52,14 @@ def __init__(

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
Expand Down Expand Up @@ -161,6 +162,5 @@ async def run_async(
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
17 changes: 10 additions & 7 deletions src/google/adk/tools/computer_use/computer_use_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
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
Expand All @@ -38,7 +39,7 @@
logger = logging.getLogger("google_adk." + __name__)


@experimental
@experimental(FeatureName.COMPUTER_USE)
class ComputerUseToolset(BaseToolset):

def __init__(
Expand Down Expand Up @@ -68,9 +69,12 @@ async def adapt_computer_use_tool(
"""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
Expand Down Expand Up @@ -173,8 +177,7 @@ async def close(self) -> None:
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
Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/google_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
from pydantic import BaseModel
from typing_extensions import override

from ..utils.feature_decorator import experimental
from ..features import experimental
from ..features import FeatureName
from ._google_credentials import BaseGoogleCredentialsConfig
from ._google_credentials import GoogleCredentialsManager
from .function_tool import FunctionTool
from .tool_context import ToolContext


@experimental
@experimental(FeatureName.GOOGLE_TOOL)
class GoogleTool(FunctionTool):
"""GoogleTool class for tools that call Google APIs.

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/spanner/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from pydantic import BaseModel
from pydantic import model_validator

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName

# Vector similarity search nearest neighbors search algorithms.
EXACT_NEAREST_NEIGHBORS = "EXACT_NEAREST_NEIGHBORS"
Expand Down Expand Up @@ -138,7 +139,7 @@ def __post_init__(self):
return self


@experimental("Tool settings defaults may have breaking change in the future.")
@experimental(FeatureName.SPANNER_TOOL_SETTINGS)
class SpannerToolSettings(BaseModel):
"""Settings for Spanner tools."""

Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/spanner/spanner_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

from __future__ import annotations

from ...utils.feature_decorator import experimental
from ...features import experimental
from ...features import FeatureName
from .._google_credentials import BaseGoogleCredentialsConfig

SPANNER_TOKEN_CACHE_KEY = "spanner_token_cache"
Expand All @@ -24,7 +25,7 @@
]


@experimental
@experimental(FeatureName.GOOGLE_CREDENTIALS_CONFIG)
class SpannerCredentialsConfig(BaseGoogleCredentialsConfig):
"""Spanner Credentials Configuration for Google API tools (Experimental).
Expand Down
5 changes: 3 additions & 2 deletions src/google/adk/tools/spanner/spanner_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
from google.adk.tools.spanner import search_tool
from typing_extensions import override

from ...features import experimental
from ...features import FeatureName
from ...tools.base_tool import BaseTool
from ...tools.base_toolset import BaseToolset
from ...tools.base_toolset import ToolPredicate
from ...tools.google_tool import GoogleTool
from ...utils.feature_decorator import experimental
from .settings import Capabilities
from .settings import SpannerToolSettings
from .spanner_credentials import SpannerCredentialsConfig

DEFAULT_SPANNER_TOOL_NAME_PREFIX = "spanner"


@experimental
@experimental(FeatureName.SPANNER_TOOLSET)
class SpannerToolset(BaseToolset):
"""Spanner Toolset contains tools for interacting with Spanner data, database and table information.

Expand Down
Loading
Loading