Skip to content

Commit dc6e552

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: Remove sandbox tool declarations from SDK AgentConfig display.
PiperOrigin-RevId: 953393888
1 parent e46d239 commit dc6e552

3 files changed

Lines changed: 42 additions & 51 deletions

File tree

agentplatform/_genai/_evals_builtin_tools.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
publishing internal tool contract details.
2626
2727
**If the server catalog changes, this SDK-side copy must be updated to match.**
28+
29+
Sandbox orchestration tools (``provision_sandbox``, ``load_sandbox``) are
30+
intentionally excluded from the tool catalog. They are infrastructure
31+
initialization, not user-facing agent capabilities.
2832
"""
2933

3034
from typing import Any, Optional
@@ -72,24 +76,16 @@
7276
}
7377

7478

75-
# Sandbox-environment orchestration tool declarations.
76-
#
77-
# Source of truth: interaction_converter.py, _SANDBOX_FUNCTION_DECLARATIONS
78-
SANDBOX_DECLARATIONS: list[genai_types.FunctionDeclaration] = [
79-
genai_types.FunctionDeclaration(
80-
name="provision_sandbox",
81-
description="Provisions a sandbox environment.",
82-
),
83-
genai_types.FunctionDeclaration(
84-
name="load_sandbox",
85-
description="Loads a previously provisioned sandbox environment.",
86-
),
87-
]
79+
# Sandbox-environment orchestration tools.
80+
# Source of truth: interaction_converter.py, _SANDBOX_TOOL_NAMES
81+
SANDBOX_TOOL_NAMES: frozenset[str] = frozenset({
82+
"provision_sandbox",
83+
"load_sandbox",
84+
})
8885

8986

9087
def agent_tools_to_config_tools(
9188
agent_tools: Optional[list[Any]],
92-
has_environment: bool = False,
9389
) -> Optional[list[genai_types.Tool]]:
9490
"""Maps Gemini Agents API tools to ``genai_types.Tool`` for display.
9591
@@ -106,18 +102,19 @@ def agent_tools_to_config_tools(
106102
* ``mcp_server`` is represented as a named declaration with a
107103
human-readable label.
108104
* Tools carrying explicit ``function_declarations`` are passed through.
109-
* When ``has_environment`` is True, sandbox orchestration tools
110-
(``provision_sandbox``, ``load_sandbox``) are appended.
105+
106+
Sandbox orchestration tools (``provision_sandbox``, ``load_sandbox``)
107+
are intentionally excluded. They are infrastructure initialization,
108+
not user-facing capabilities.
111109
112110
Args:
113111
agent_tools: The ``tools`` list from a fetched Gemini agent dict.
114-
has_environment: Whether the agent has a sandbox environment configured.
115112
116113
Returns:
117114
A list of ``genai_types.Tool``, or ``None`` if there are no mappable
118115
tools.
119116
"""
120-
if not agent_tools and not has_environment:
117+
if not agent_tools:
121118
return None
122119
tools: list[genai_types.Tool] = []
123120
for tool in agent_tools or []:
@@ -161,7 +158,4 @@ def agent_tools_to_config_tools(
161158
elif remainder:
162159
tools.append(genai_types.Tool.model_validate(remainder))
163160

164-
if has_environment:
165-
tools.append(genai_types.Tool(function_declarations=list(SANDBOX_DECLARATIONS)))
166-
167161
return tools or None

agentplatform/_genai/_evals_common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,12 +896,8 @@ def _fetch_agent_config_dict(
896896
instruction = agent_dict.get("system_instruction") or None
897897
description = agent_dict.get("description") or None
898898
agent_type = agent_dict.get("base_agent") or None
899-
has_environment = bool(
900-
agent_dict.get("environment_config")
901-
or agent_dict.get("base_environment")
902-
)
903899
tools = _agent_tools_to_config_tools(
904-
agent_dict.get("tools"), has_environment=has_environment
900+
agent_dict.get("tools")
905901
)
906902
except Exception as e: # pylint: disable=broad-exception-caught
907903
logger.warning(

tests/unit/agentplatform/genai/test_evals.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11779,8 +11779,8 @@ def test_filesystem_expands_to_file_tools(self):
1177911779
"move_file",
1178011780
}
1178111781

11782-
def test_environment_adds_sandbox_tools(self):
11783-
"""When agent has environment_config, sandbox tools are appended."""
11782+
def test_environment_does_not_add_sandbox_tools(self):
11783+
"""Sandbox tools should NOT appear even when agent has environment."""
1178411784
agent_json = {
1178511785
"tools": [{"type": "code_execution"}],
1178611786
"environment_config": {"some_field": "value"},
@@ -11791,17 +11791,17 @@ def test_environment_adds_sandbox_tools(self):
1179111791
mock_api_client,
1179211792
"projects/p/locations/l/agents/a",
1179311793
)
11794-
# code_execution + sandbox tool
11795-
assert len(result.tools) == 2
11794+
# Only code_execution, no sandbox tools.
11795+
assert len(result.tools) == 1
1179611796
all_decl_names = {
1179711797
fd.name
1179811798
for t in result.tools
1179911799
if t.function_declarations
1180011800
for fd in t.function_declarations
1180111801
}
1180211802
assert "run_command" in all_decl_names
11803-
assert "provision_sandbox" in all_decl_names
11804-
assert "load_sandbox" in all_decl_names
11803+
assert "provision_sandbox" not in all_decl_names
11804+
assert "load_sandbox" not in all_decl_names
1180511805

1180611806
def test_mcp_server_kept_as_named_declaration(self):
1180711807
"""mcp_server entries are kept as named declarations, not dropped."""
@@ -11831,17 +11831,23 @@ def test_mcp_server_kept_as_named_declaration(self):
1183111831
def test_catalog_in_sync_with_server(self):
1183211832
"""SDK catalog keys and function names match the server-side catalog.
1183311833
11834-
The SDK-side BUILTIN_TOOL_DECLARATIONS and SANDBOX_DECLARATIONS in
11835-
_evals_builtin_tools are a display-only copy of the authoritative
11836-
server-side catalog in interaction_converter.py. This test imports
11837-
both and asserts that tool-type keys and declaration names stay in
11838-
sync. If this test fails, update _evals_builtin_tools.py to match.
11834+
The SDK-side BUILTIN_TOOL_DECLARATIONS in _evals_builtin_tools is a
11835+
display-only copy of the authoritative server-side catalog in
11836+
interaction_converter.py. This test imports both and asserts that
11837+
tool-type keys and declaration names stay in sync. If this test
11838+
fails, update _evals_builtin_tools.py to match.
11839+
11840+
Sandbox tool declarations (provision_sandbox, load_sandbox) are
11841+
intentionally excluded from both the SDK and server AgentConfig
11842+
tool catalogs, so no sync check is needed for them.
1183911843
"""
1184011844
# pylint: disable=g-import-not-at-top
1184111845
try:
1184211846
from cloud.ai.platform.evaluation.utils import interaction_converter
1184311847
except ImportError:
11844-
pytest.skip("interaction_converter not available outside google3")
11848+
pytest.skip(
11849+
"interaction_converter not available outside google3"
11850+
)
1184511851
# pylint: enable=g-import-not-at-top
1184611852

1184711853
# --- Built-in tool types: keys must match ---
@@ -11859,9 +11865,7 @@ def test_catalog_in_sync_with_server(self):
1185911865
for tool_type in server_builtin_keys:
1186011866
server_names = {
1186111867
fd.name
11862-
for fd in interaction_converter._BUILTIN_TOOL_FUNCTION_DECLARATIONS[
11863-
tool_type
11864-
]
11868+
for fd in interaction_converter._BUILTIN_TOOL_FUNCTION_DECLARATIONS[tool_type]
1186511869
}
1186611870
sdk_names = {
1186711871
fd.name
@@ -11873,17 +11877,14 @@ def test_catalog_in_sync_with_server(self):
1187311877
f" SDK: {sorted(sdk_names)}"
1187411878
)
1187511879

11876-
# --- Sandbox declarations: names must match ---
11877-
server_sandbox_names = {
11878-
fd.name for fd in interaction_converter.sandbox_function_declarations()
11879-
}
11880-
sdk_sandbox_names = {
11881-
fd.name for fd in _evals_builtin_tools.SANDBOX_DECLARATIONS
11882-
}
11883-
assert sdk_sandbox_names == server_sandbox_names, (
11884-
f"SANDBOX_DECLARATIONS names out of sync.\n"
11880+
# --- Sandbox tool names: SDK names must match server names ---
11881+
server_sandbox_names = set(
11882+
interaction_converter._SANDBOX_TOOL_NAMES
11883+
)
11884+
assert _evals_builtin_tools.SANDBOX_TOOL_NAMES == server_sandbox_names, (
11885+
f"SANDBOX_TOOL_NAMES out of sync.\n"
1188511886
f" Server: {sorted(server_sandbox_names)}\n"
11886-
f" SDK: {sorted(sdk_sandbox_names)}"
11887+
f" SDK: {sorted(_evals_builtin_tools.SANDBOX_TOOL_NAMES)}"
1188711888
)
1188811889

1188911890

0 commit comments

Comments
 (0)