From 98f504cebe16bd949206c79fd14d460c50110cd9 Mon Sep 17 00:00:00 2001 From: Liang Wu Date: Wed, 21 May 2025 11:44:46 -0700 Subject: [PATCH] feat!: use BuiltInCodeExecutor in Runner for CFC. The BuiltInCodeExecutionTool is deleted. PiperOrigin-RevId: 761608273 --- src/google/adk/runners.py | 6 +- .../tools/_built_in_code_execution_tool.py | 70 ------------------- 2 files changed, 3 insertions(+), 73 deletions(-) delete mode 100644 src/google/adk/tools/_built_in_code_execution_tool.py diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index 41887e2..d5a16e8 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -34,6 +34,7 @@ from .agents.llm_agent import LlmAgent from .agents.run_config import RunConfig from .artifacts.base_artifact_service import BaseArtifactService from .artifacts.in_memory_artifact_service import InMemoryArtifactService +from .code_executors.built_in_code_executor import BuiltInCodeExecutor from .events.event import Event from .memory.base_memory_service import BaseMemoryService from .memory.in_memory_memory_service import InMemoryMemoryService @@ -41,7 +42,6 @@ from .sessions.base_session_service import BaseSessionService from .sessions.in_memory_session_service import InMemorySessionService from .sessions.session import Session from .telemetry import tracer -from .tools._built_in_code_execution_tool import built_in_code_execution logger = logging.getLogger('google_adk.' + __name__) @@ -409,8 +409,8 @@ class Runner: f'CFC is not supported for model: {model_name} in agent:' f' {self.agent.name}' ) - if built_in_code_execution not in self.agent.canonical_tools(): - self.agent.tools.append(built_in_code_execution) + if not isinstance(self.agent.code_executor, BuiltInCodeExecutor): + self.agent.code_executor = BuiltInCodeExecutor() return InvocationContext( artifact_service=self.artifact_service, diff --git a/src/google/adk/tools/_built_in_code_execution_tool.py b/src/google/adk/tools/_built_in_code_execution_tool.py deleted file mode 100644 index 0209cd1..0000000 --- a/src/google/adk/tools/_built_in_code_execution_tool.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import annotations - -import logging -from typing import TYPE_CHECKING - -from deprecated import deprecated -from google.genai import types -from typing_extensions import override - -from .base_tool import BaseTool -from .tool_context import ToolContext - -if TYPE_CHECKING: - from ..models import LlmRequest - -logger = logging.getLogger('google_adk.' + __name__) - - -@deprecated( - 'No longer supported. Please use the new BuiltInCodeExecutor instead.' -) -class BuiltInCodeExecutionTool(BaseTool): - """A built-in code execution tool that is automatically invoked by Gemini 2 models. - - This tool operates internally within the model and does not require or perform - local code execution. - """ - - def __init__(self): - # Name and description are not used because this is a model built-in tool. - super().__init__(name='code_execution', description='code_execution') - - @override - async def process_llm_request( - self, - *, - tool_context: ToolContext, - llm_request: LlmRequest, - ) -> None: - logger.warning( - 'BuiltInCodeExecutionTool is deprecated and will be removed in 1.1.0.' - ' Please use the new BuiltInCodeExecutor instead.' - ) - if llm_request.model and llm_request.model.startswith('gemini-2'): - llm_request.config = llm_request.config or types.GenerateContentConfig() - llm_request.config.tools = llm_request.config.tools or [] - llm_request.config.tools.append( - types.Tool(code_execution=types.ToolCodeExecution()) - ) - else: - raise ValueError( - f'Code execution tool is not supported for model {llm_request.model}' - ) - - -built_in_code_execution = BuiltInCodeExecutionTool()