Skip to content

Commit 2fe9544

Browse files
authored
Merge branch 'google:main' into Issue-google#4796
2 parents 320bbdb + 71f8c5b commit 2fe9544

3 files changed

Lines changed: 104 additions & 2 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
repos:
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.6.0
18+
hooks:
19+
- id: check-added-large-files
20+
- id: check-yaml
21+
- id: end-of-file-fixer
22+
- id: trailing-whitespace
23+
- repo: local
24+
hooks:
25+
- id: isort
26+
name: isort
27+
entry: isort
28+
language: system
29+
types: [python]
30+
- id: pyink
31+
name: pyink
32+
entry: pyink --config pyproject.toml
33+
language: system
34+
types: [python]

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ def __init__(
4848
self,
4949
*,
5050
computer: BaseComputer,
51+
excluded_predefined_functions: Optional[list[str]] = None,
5152
):
5253
super().__init__()
5354
self._computer = computer
55+
self._excluded_predefined_functions = excluded_predefined_functions
5456
self._initialized = False
5557
self._tools = None
5658

@@ -203,6 +205,13 @@ async def get_tools(
203205
if method_name == "session_state":
204206
continue
205207

208+
# Skip methods excluded by configuration
209+
if (
210+
self._excluded_predefined_functions
211+
and method_name in self._excluded_predefined_functions
212+
):
213+
continue
214+
206215
# Check if it's a method defined in Computer class
207216
attr = getattr(BaseComputer, method_name, None)
208217
if attr is not None and callable(attr):
@@ -259,11 +268,18 @@ async def process_llm_request(
259268
types.Environment.ENVIRONMENT_BROWSER,
260269
)
261270
llm_request.config.tools.append(
262-
types.Tool(computer_use=types.ComputerUse(environment=environment))
271+
types.Tool(
272+
computer_use=types.ComputerUse(
273+
environment=environment,
274+
excluded_predefined_functions=self._excluded_predefined_functions,
275+
)
276+
)
263277
)
264278
logger.debug(
265-
"Added computer use tool with environment: %s",
279+
"Added computer use tool with environment: %s,"
280+
" excluded_functions: %s",
266281
environment,
282+
self._excluded_predefined_functions,
267283
)
268284

269285
except Exception as e:

‎tests/unittests/tools/computer_use/test_computer_use_toolset.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,23 @@ async def test_get_tools_excludes_utility_methods(self, toolset):
202202
for method in expected_methods:
203203
assert method in tool_names
204204

205+
@pytest.mark.asyncio
206+
async def test_get_tools_filters_excluded_functions(self, mock_computer):
207+
"""Test that get_tools filters out excluded functions."""
208+
excluded_funcs = ["drag_and_drop", "key_combination"]
209+
toolset = ComputerUseToolset(
210+
computer=mock_computer,
211+
excluded_predefined_functions=excluded_funcs,
212+
)
213+
214+
tools = await toolset.get_tools()
215+
tool_names = [tool.func.__name__ for tool in tools]
216+
217+
for func in excluded_funcs:
218+
assert func not in tool_names
219+
220+
assert "click_at" in tool_names
221+
205222
@pytest.mark.asyncio
206223
async def test_get_tools_with_readonly_context(self, toolset):
207224
"""Test get_tools with readonly_context parameter."""
@@ -362,6 +379,41 @@ async def test_process_llm_request(self, toolset, mock_computer):
362379
== types.Environment.ENVIRONMENT_BROWSER
363380
)
364381

382+
@pytest.mark.asyncio
383+
async def test_process_llm_request_with_excluded_functions(
384+
self, mock_computer
385+
):
386+
"""Test that process_llm_request passes excluded_predefined_functions."""
387+
excluded_funcs = ["drag_and_drop", "key_combination"]
388+
toolset = ComputerUseToolset(
389+
computer=mock_computer,
390+
excluded_predefined_functions=excluded_funcs,
391+
)
392+
393+
llm_request = LlmRequest(
394+
model="gemini-1.5-flash",
395+
config=types.GenerateContentConfig(),
396+
)
397+
398+
await toolset.process_llm_request(
399+
tool_context=MagicMock(), llm_request=llm_request
400+
)
401+
402+
# Should have computer use tool
403+
computer_use_tools = [
404+
tool
405+
for tool in llm_request.config.tools
406+
if hasattr(tool, "computer_use") and tool.computer_use
407+
]
408+
assert len(computer_use_tools) == 1
409+
410+
# Should have correct excluded functions
411+
computer_use_tool = computer_use_tools[0]
412+
assert (
413+
computer_use_tool.computer_use.excluded_predefined_functions
414+
== excluded_funcs
415+
)
416+
365417
@pytest.mark.asyncio
366418
async def test_process_llm_request_with_existing_computer_use(
367419
self, toolset, mock_computer

0 commit comments

Comments
 (0)