Skip to content

Commit ec0c61f

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

3 files changed

Lines changed: 41 additions & 61 deletions

File tree

agentplatform/_genai/_evals_builtin_tools.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
2727
**If the server catalog changes, this SDK-side copy must be updated to match.**
2828
29-
This module also provides sandbox-detection helpers
30-
(``SANDBOX_TOOL_NAMES``, ``is_sandbox_only_turn``) used by the display
31-
path (``_evals_common._interaction_dict_to_agent_data``).
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.
3232
"""
3333

3434
from typing import Any, Optional
@@ -76,26 +76,12 @@
7676
}
7777

7878

79-
# Sandbox-environment orchestration tool declarations.
80-
#
81-
# Source of truth: interaction_converter.py, _SANDBOX_FUNCTION_DECLARATIONS
82-
SANDBOX_DECLARATIONS: list[genai_types.FunctionDeclaration] = [
83-
genai_types.FunctionDeclaration(
84-
name="provision_sandbox",
85-
description="Provisions a sandbox environment.",
86-
),
87-
genai_types.FunctionDeclaration(
88-
name="load_sandbox",
89-
description="Loads a previously provisioned sandbox environment.",
90-
),
91-
]
92-
93-
94-
# Names of sandbox orchestration tools, derived from ``SANDBOX_DECLARATIONS``
95-
# so there is a single source of truth.
96-
SANDBOX_TOOL_NAMES: frozenset[str] = frozenset(
97-
decl.name for decl in SANDBOX_DECLARATIONS if decl.name
98-
)
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+
})
9985

10086

10187
def is_sandbox_only_turn(
@@ -146,7 +132,6 @@ def is_sandbox_only_turn(
146132

147133
def agent_tools_to_config_tools(
148134
agent_tools: Optional[list[Any]],
149-
has_environment: bool = False,
150135
) -> Optional[list[genai_types.Tool]]:
151136
"""Maps Gemini Agents API tools to ``genai_types.Tool`` for display.
152137
@@ -163,18 +148,19 @@ def agent_tools_to_config_tools(
163148
* ``mcp_server`` is represented as a named declaration with a
164149
human-readable label.
165150
* Tools carrying explicit ``function_declarations`` are passed through.
166-
* When ``has_environment`` is True, sandbox orchestration tools
167-
(``provision_sandbox``, ``load_sandbox``) are appended.
151+
152+
Sandbox orchestration tools (``provision_sandbox``, ``load_sandbox``)
153+
are intentionally excluded. They are infrastructure initialization,
154+
not user-facing capabilities.
168155
169156
Args:
170157
agent_tools: The ``tools`` list from a fetched Gemini agent dict.
171-
has_environment: Whether the agent has a sandbox environment configured.
172158
173159
Returns:
174160
A list of ``genai_types.Tool``, or ``None`` if there are no mappable
175161
tools.
176162
"""
177-
if not agent_tools and not has_environment:
163+
if not agent_tools:
178164
return None
179165
tools: list[genai_types.Tool] = []
180166
for tool in agent_tools or []:
@@ -218,7 +204,4 @@ def agent_tools_to_config_tools(
218204
elif remainder:
219205
tools.append(genai_types.Tool.model_validate(remainder))
220206

221-
if has_environment:
222-
tools.append(genai_types.Tool(function_declarations=list(SANDBOX_DECLARATIONS)))
223-
224207
return tools or None

agentplatform/_genai/_evals_common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,8 @@ def _fetch_agent_config_dict(
903903
instruction = agent_dict.get("system_instruction") or None
904904
description = agent_dict.get("description") or None
905905
agent_type = agent_dict.get("base_agent") or None
906-
has_environment = bool(
907-
agent_dict.get("environment_config")
908-
or agent_dict.get("base_environment")
909-
)
910906
tools = _agent_tools_to_config_tools(
911-
agent_dict.get("tools"), has_environment=has_environment
907+
agent_dict.get("tools")
912908
)
913909
except Exception as e: # pylint: disable=broad-exception-caught
914910
logger.warning(

tests/unit/agentplatform/genai/test_evals.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12010,8 +12010,8 @@ def test_filesystem_expands_to_file_tools(self):
1201012010
"move_file",
1201112011
}
1201212012

12013-
def test_environment_adds_sandbox_tools(self):
12014-
"""When agent has environment_config, sandbox tools are appended."""
12013+
def test_environment_does_not_add_sandbox_tools(self):
12014+
"""Sandbox tools should NOT appear even when agent has environment."""
1201512015
agent_json = {
1201612016
"tools": [{"type": "code_execution"}],
1201712017
"environment_config": {"some_field": "value"},
@@ -12022,17 +12022,17 @@ def test_environment_adds_sandbox_tools(self):
1202212022
mock_api_client,
1202312023
"projects/p/locations/l/agents/a",
1202412024
)
12025-
# code_execution + sandbox tool
12026-
assert len(result.tools) == 2
12025+
# Only code_execution, no sandbox tools.
12026+
assert len(result.tools) == 1
1202712027
all_decl_names = {
1202812028
fd.name
1202912029
for t in result.tools
1203012030
if t.function_declarations
1203112031
for fd in t.function_declarations
1203212032
}
1203312033
assert "run_command" in all_decl_names
12034-
assert "provision_sandbox" in all_decl_names
12035-
assert "load_sandbox" in all_decl_names
12034+
assert "provision_sandbox" not in all_decl_names
12035+
assert "load_sandbox" not in all_decl_names
1203612036

1203712037
def test_mcp_server_kept_as_named_declaration(self):
1203812038
"""mcp_server entries are kept as named declarations, not dropped."""
@@ -12062,17 +12062,23 @@ def test_mcp_server_kept_as_named_declaration(self):
1206212062
def test_catalog_in_sync_with_server(self):
1206312063
"""SDK catalog keys and function names match the server-side catalog.
1206412064
12065-
The SDK-side BUILTIN_TOOL_DECLARATIONS and SANDBOX_DECLARATIONS in
12066-
_evals_builtin_tools are a display-only copy of the authoritative
12067-
server-side catalog in interaction_converter.py. This test imports
12068-
both and asserts that tool-type keys and declaration names stay in
12069-
sync. If this test fails, update _evals_builtin_tools.py to match.
12065+
The SDK-side BUILTIN_TOOL_DECLARATIONS in _evals_builtin_tools is a
12066+
display-only copy of the authoritative server-side catalog in
12067+
interaction_converter.py. This test imports both and asserts that
12068+
tool-type keys and declaration names stay in sync. If this test
12069+
fails, update _evals_builtin_tools.py to match.
12070+
12071+
Sandbox tool declarations (provision_sandbox, load_sandbox) are
12072+
intentionally excluded from both the SDK and server AgentConfig
12073+
tool catalogs, so no sync check is needed for them.
1207012074
"""
1207112075
# pylint: disable=g-import-not-at-top
1207212076
try:
1207312077
from cloud.ai.platform.evaluation.utils import interaction_converter
1207412078
except ImportError:
12075-
pytest.skip("interaction_converter not available outside google3")
12079+
pytest.skip(
12080+
"interaction_converter not available outside google3"
12081+
)
1207612082
# pylint: enable=g-import-not-at-top
1207712083

1207812084
# --- Built-in tool types: keys must match ---
@@ -12090,9 +12096,7 @@ def test_catalog_in_sync_with_server(self):
1209012096
for tool_type in server_builtin_keys:
1209112097
server_names = {
1209212098
fd.name
12093-
for fd in interaction_converter._BUILTIN_TOOL_FUNCTION_DECLARATIONS[
12094-
tool_type
12095-
]
12099+
for fd in interaction_converter._BUILTIN_TOOL_FUNCTION_DECLARATIONS[tool_type]
1209612100
}
1209712101
sdk_names = {
1209812102
fd.name
@@ -12104,17 +12108,14 @@ def test_catalog_in_sync_with_server(self):
1210412108
f" SDK: {sorted(sdk_names)}"
1210512109
)
1210612110

12107-
# --- Sandbox declarations: names must match ---
12108-
server_sandbox_names = {
12109-
fd.name for fd in interaction_converter.sandbox_function_declarations()
12110-
}
12111-
sdk_sandbox_names = {
12112-
fd.name for fd in _evals_builtin_tools.SANDBOX_DECLARATIONS
12113-
}
12114-
assert sdk_sandbox_names == server_sandbox_names, (
12115-
f"SANDBOX_DECLARATIONS names out of sync.\n"
12111+
# --- Sandbox tool names: SDK names must match server names ---
12112+
server_sandbox_names = set(
12113+
interaction_converter._SANDBOX_TOOL_NAMES
12114+
)
12115+
assert _evals_builtin_tools.SANDBOX_TOOL_NAMES == server_sandbox_names, (
12116+
f"SANDBOX_TOOL_NAMES out of sync.\n"
1211612117
f" Server: {sorted(server_sandbox_names)}\n"
12117-
f" SDK: {sorted(sdk_sandbox_names)}"
12118+
f" SDK: {sorted(_evals_builtin_tools.SANDBOX_TOOL_NAMES)}"
1211812119
)
1211912120

1212012121

0 commit comments

Comments
 (0)