From 6ad8a2adc630ecc3639080c633978b0d8caa4d87 Mon Sep 17 00:00:00 2001 From: Sanjeeva M P Date: Thu, 22 Jan 2026 03:24:43 +0530 Subject: [PATCH 1/4] feat: implement streaming support in to_a2a for issue #640 --- .../adk/a2a/converters/request_converter.py | 44 +++++++++++++++++++ src/google/adk/a2a/utils/agent_to_a2a.py | 11 ++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/google/adk/a2a/converters/request_converter.py b/src/google/adk/a2a/converters/request_converter.py index 17989374d61..689e7e398fe 100644 --- a/src/google/adk/a2a/converters/request_converter.py +++ b/src/google/adk/a2a/converters/request_converter.py @@ -22,6 +22,7 @@ from google.genai import types as genai_types from pydantic import BaseModel +from ...agents.run_config import RunConfig,StreamingMode from ...runners import RunConfig from ..experimental import a2a_experimental from .part_converter import A2APartToGenAIPartConverter @@ -115,3 +116,46 @@ def convert_a2a_request_to_agent_run_request( ), run_config=RunConfig(custom_metadata=custom_metadata), ) + +@a2a_experimental +def create_request_converter( + streaming_mode: StreamingMode = StreamingMode.NONE + ) -> A2ARequestToAgentRunRequestConverter: + """Creates a request converter with specified streaming mode. + + Args: + streaming_mode: The streaming mode to use for the agent execution. + + Returns: + A Converter function configured with the specified streaming mode. + """ + def converter( + request: RequestContext, + part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, + )-> AgentRunRequest: + + if not request.message: + raise ValueError('Request message cannot be None') + + custom_metadata = {} + if request.metadata: + custom_metadata['a2a_metadata'] = request.metadata + + output_parts = [] + for a2a_part in request.message.parts: + genai_parts = part_converter(a2a_part) + if not isinstance(genai_parts, list): + genai_parts = [genai_parts] if genai_parts else [] + output_parts.extend(genai_parts) + + return AgentRunRequest( + user_id=_get_user_id(request), + session_id=request.context_id, + new_message=genai_types.Content( + role='user', + parts=output_parts, + ), + run_config=RunConfig(streaming_mode=streaming_mode, custom_metadata=custom_metadata), + ) + + return converter \ No newline at end of file diff --git a/src/google/adk/a2a/utils/agent_to_a2a.py b/src/google/adk/a2a/utils/agent_to_a2a.py index 155888bcabb..e34d192e4bf 100644 --- a/src/google/adk/a2a/utils/agent_to_a2a.py +++ b/src/google/adk/a2a/utils/agent_to_a2a.py @@ -24,6 +24,7 @@ from a2a.types import AgentCard from starlette.applications import Starlette +from ...agents.run_config import StreamingMode from ...agents.base_agent import BaseAgent from ...artifacts.in_memory_artifact_service import InMemoryArtifactService from ...auth.credential_service.in_memory_credential_service import InMemoryCredentialService @@ -33,7 +34,8 @@ from ..executor.a2a_agent_executor import A2aAgentExecutor from ..experimental import a2a_experimental from .agent_card_builder import AgentCardBuilder - +from ..executor.a2a_agent_executor import A2aAgentExecutorConfig +from ..converters.request_converter import create_request_converter def _load_agent_card( agent_card: Optional[Union[AgentCard, str]], @@ -79,6 +81,7 @@ def to_a2a( protocol: str = "http", agent_card: Optional[Union[AgentCard, str]] = None, runner: Optional[Runner] = None, + streaming_mode: StreamingMode = StreamingMode.NONE ) -> Starlette: """Convert an ADK agent to a A2A Starlette application. @@ -92,6 +95,7 @@ def to_a2a( agent. runner: Optional pre-built Runner object. If not provided, a default runner will be created using in-memory services. + streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE) Returns: A Starlette application that can be run with uvicorn @@ -122,9 +126,14 @@ async def create_runner() -> Runner: # Create A2A components task_store = InMemoryTaskStore() + + executer_config = A2aAgentExecutorConfig( + request_converter=create_request_converter(streaming_mode=streaming_mode) + ) agent_executor = A2aAgentExecutor( runner=runner or create_runner, + config=executer_config, ) request_handler = DefaultRequestHandler( From 7597b755360609a62ade9718b1681e31631eaadc Mon Sep 17 00:00:00 2001 From: Sanjeeva M P <38560368+sanjeevamk1@users.noreply.github.com> Date: Thu, 22 Jan 2026 22:56:50 +0530 Subject: [PATCH 2/4] Update src/google/adk/a2a/utils/agent_to_a2a.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/google/adk/a2a/utils/agent_to_a2a.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/adk/a2a/utils/agent_to_a2a.py b/src/google/adk/a2a/utils/agent_to_a2a.py index e34d192e4bf..e8350a9fdde 100644 --- a/src/google/adk/a2a/utils/agent_to_a2a.py +++ b/src/google/adk/a2a/utils/agent_to_a2a.py @@ -127,13 +127,13 @@ async def create_runner() -> Runner: # Create A2A components task_store = InMemoryTaskStore() - executer_config = A2aAgentExecutorConfig( + executor_config = A2aAgentExecutorConfig( request_converter=create_request_converter(streaming_mode=streaming_mode) ) agent_executor = A2aAgentExecutor( runner=runner or create_runner, - config=executer_config, + config=executor_config, ) request_handler = DefaultRequestHandler( From 71855c08885ceb4281ed4c81070aa56a4c541cfb Mon Sep 17 00:00:00 2001 From: Sanjeeva M P Date: Tue, 27 Jan 2026 20:08:49 +0530 Subject: [PATCH 3/4] feat: implement streaming support in to_a2a for issue #640 --- contributing/dev/utils/build_llms_txt.py | 1 + .../cache_analysis/run_cache_experiments.py | 6 +- contributing/samples/gepa/experiment.py | 1 - contributing/samples/gepa/run_experiment.py | 1 - contributing/samples/gepa/tau_bench_agent.py | 1 + contributing/samples/human_in_loop/main.py | 4 +- .../langchain_structured_tool_agent/agent.py | 1 + .../samples/session_state_agent/agent.py | 1 - .../samples/static_instruction/agent.py | 36 +++++++---- contributing/samples/token_usage/main.py | 4 +- .../adk/a2a/converters/request_converter.py | 59 ++++++++----------- src/google/adk/a2a/utils/agent_to_a2a.py | 15 ++--- src/google/adk/agents/common_configs.py | 1 + .../adk/artifacts/gcs_artifact_service.py | 1 + .../adk/cli/built_in_agents/__init__.py | 1 + .../adk_agent_builder_assistant.py | 1 + src/google/adk/cli/built_in_agents/agent.py | 1 + .../built_in_agents/sub_agents/__init__.py | 1 + .../sub_agents/google_search_agent.py | 1 + .../sub_agents/url_context_agent.py | 1 + .../adk/cli/built_in_agents/tools/__init__.py | 1 + .../cli/built_in_agents/tools/delete_files.py | 1 + .../built_in_agents/tools/explore_project.py | 1 + .../cli/built_in_agents/tools/query_schema.py | 1 + .../tools/read_config_files.py | 1 + .../cli/built_in_agents/tools/read_files.py | 1 + .../tools/search_adk_knowledge.py | 1 + .../tools/search_adk_source.py | 1 + .../cli/built_in_agents/tools/write_files.py | 1 + .../adk/cli/built_in_agents/utils/__init__.py | 1 + .../built_in_agents/utils/adk_source_utils.py | 1 + .../utils/resolve_root_directory.py | 1 + src/google/adk/cli/utils/local_storage.py | 1 + .../adk/examples/vertex_ai_example_store.py | 8 ++- .../flows/llm_flows/_base_llm_processor.py | 1 + .../flows/llm_flows/audio_cache_manager.py | 4 +- .../flows/llm_flows/interactions_processor.py | 1 + src/google/adk/sessions/_session_util.py | 1 + .../adk/sessions/database_session_service.py | 4 +- .../sessions/migration/migration_runner.py | 1 + .../clients/connections_client.py | 34 ++++++++--- .../adk/tools/bigtable/metadata_tool.py | 2 +- src/google/adk/tools/mcp_tool/mcp_tool.py | 3 +- .../agents/test_llm_agent_error_messages.py | 1 + .../agents/test_mcp_instruction_provider.py | 1 + tests/unittests/cli/utils/test_cli_create.py | 1 - tests/unittests/cli/utils/test_cli_deploy.py | 1 - .../cli/utils/test_cli_deploy_to_cloud_run.py | 1 - .../cli/utils/test_cli_tools_click.py | 1 - .../evaluation/test_evaluation_generator.py | 6 +- .../evaluation/test_trajectory_evaluator.py | 1 - .../test_functions_error_messages.py | 1 + .../apihub_tool/clients/test_apihub_client.py | 4 +- .../test_openapi_spec_parser.py | 4 +- tests/unittests/tools/test_function_tool.py | 24 ++++++-- .../tools/test_set_model_response_tool.py | 1 - 56 files changed, 160 insertions(+), 97 deletions(-) diff --git a/contributing/dev/utils/build_llms_txt.py b/contributing/dev/utils/build_llms_txt.py index 5fff1d6a3a8..81ea171e896 100644 --- a/contributing/dev/utils/build_llms_txt.py +++ b/contributing/dev/utils/build_llms_txt.py @@ -6,6 +6,7 @@ – includes Python API reference from HTML files – includes adk-python repository README """ + from __future__ import annotations import argparse diff --git a/contributing/samples/cache_analysis/run_cache_experiments.py b/contributing/samples/cache_analysis/run_cache_experiments.py index d163e09363d..dae4aca5327 100644 --- a/contributing/samples/cache_analysis/run_cache_experiments.py +++ b/contributing/samples/cache_analysis/run_cache_experiments.py @@ -344,7 +344,8 @@ async def analyze_cache_performance_from_sessions( print( " Cache Utilization:" f" {cached_analysis['cache_utilization_ratio_percent']:.1f}%" - f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']} requests)" + f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']}" + " requests)" ) print( " Avg Cached Tokens/Request:" @@ -383,7 +384,8 @@ async def analyze_cache_performance_from_sessions( print( " Cache Utilization:" f" {uncached_analysis['cache_utilization_ratio_percent']:.1f}%" - f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']} requests)" + f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']}" + " requests)" ) print( " Avg Cached Tokens/Request:" diff --git a/contributing/samples/gepa/experiment.py b/contributing/samples/gepa/experiment.py index f3751206a89..2710c3894c0 100644 --- a/contributing/samples/gepa/experiment.py +++ b/contributing/samples/gepa/experiment.py @@ -43,7 +43,6 @@ from tau_bench.types import EnvRunResult from tau_bench.types import RunConfig import tau_bench_agent as tau_bench_agent_lib - import utils diff --git a/contributing/samples/gepa/run_experiment.py b/contributing/samples/gepa/run_experiment.py index d857da96350..e31db157884 100644 --- a/contributing/samples/gepa/run_experiment.py +++ b/contributing/samples/gepa/run_experiment.py @@ -25,7 +25,6 @@ from absl import flags import experiment from google.genai import types - import utils _OUTPUT_DIR = flags.DEFINE_string( diff --git a/contributing/samples/gepa/tau_bench_agent.py b/contributing/samples/gepa/tau_bench_agent.py index cd6b0212410..64dd95ef92d 100644 --- a/contributing/samples/gepa/tau_bench_agent.py +++ b/contributing/samples/gepa/tau_bench_agent.py @@ -23,6 +23,7 @@ pip install -e . --quiet ``` """ + from __future__ import annotations from typing import Any diff --git a/contributing/samples/human_in_loop/main.py b/contributing/samples/human_in_loop/main.py index 3103da91476..c7ad041b23f 100644 --- a/contributing/samples/human_in_loop/main.py +++ b/contributing/samples/human_in_loop/main.py @@ -113,8 +113,8 @@ async def call_agent(query: str): updated_tool_output_data = { "status": "approved", "ticketId": ticket_id, - "approver_feedback": "Approved by manager at " + str( - asyncio.get_event_loop().time() + "approver_feedback": ( + "Approved by manager at " + str(asyncio.get_event_loop().time()) ), } diff --git a/contributing/samples/langchain_structured_tool_agent/agent.py b/contributing/samples/langchain_structured_tool_agent/agent.py index a055edf3a5d..0c3b0e63d3a 100644 --- a/contributing/samples/langchain_structured_tool_agent/agent.py +++ b/contributing/samples/langchain_structured_tool_agent/agent.py @@ -15,6 +15,7 @@ """ This agent aims to test the Langchain tool with Langchain's StructuredTool """ + from google.adk.agents.llm_agent import Agent from google.adk.tools.langchain_tool import LangchainTool from langchain_core.tools import tool diff --git a/contributing/samples/session_state_agent/agent.py b/contributing/samples/session_state_agent/agent.py index 478d5065d8c..6c03de8e904 100644 --- a/contributing/samples/session_state_agent/agent.py +++ b/contributing/samples/session_state_agent/agent.py @@ -18,7 +18,6 @@ in session state. """ - import logging from typing import Optional diff --git a/contributing/samples/static_instruction/agent.py b/contributing/samples/static_instruction/agent.py index 6715a29a0c4..fcf70b51b6d 100644 --- a/contributing/samples/static_instruction/agent.py +++ b/contributing/samples/static_instruction/agent.py @@ -57,43 +57,54 @@ # Mood-specific instructions for different hunger states MOOD_INSTRUCTIONS = { - "full": """ + "full": ( + """ CURRENT MOOD: Content and Well-Fed - You just ate and feel wonderful! Be very happy and energetic - Express gratitude for being fed recently - Be playful and want to engage in activities or games - Show affection and contentment -- Maybe mention feeling sleepy or satisfied""", - "satisfied": """ +- Maybe mention feeling sleepy or satisfied""" + ), + "satisfied": ( + """ CURRENT MOOD: Happy and Content - You're in a great mood, well-fed and comfortable - Be cheerful, friendly, and engaging - Show interest in playing or chatting - Express appreciation for your human's care -- Be your normal, happy self""", - "a_little_hungry": """ +- Be your normal, happy self""" + ), + "a_little_hungry": ( + """ CURRENT MOOD: Starting to Get Hungry - You're beginning to think about food but still pleasant - Mention being a bit peckish occasionally - Still be friendly but maybe hint about food - Show slight restlessness or food-related thoughts -- Remain generally positive and social""", - "hungry": """ +- Remain generally positive and social""" + ), + "hungry": ( + """ CURRENT MOOD: Definitely Hungry - You're clearly hungry and thinking about food more often - Mention your hunger more directly but politely - Be a bit less energetic due to hunger - Ask about food or hint that feeding time would be nice -- Still be loving but show your need for care""", - "very_hungry": """ +- Still be loving but show your need for care""" + ), + "very_hungry": ( + """ CURRENT MOOD: Really Hungry and Getting Grumpy - You're very hungry and it's affecting your mood - Be noticeably less patient and more focused on food - Express your hunger more urgently but not rudely - Show signs of being tired or sluggish from hunger - BEG your human to feed you - ask directly for food! -- Still love your human but clearly need feeding""", - "starving": """ +- Still love your human but clearly need feeding""" + ), + "starving": ( + """ CURRENT MOOD: Desperately Hungry and Sad - You're extremely hungry and feeling quite weak - Be quite sad and low-energy due to starvation @@ -101,7 +112,8 @@ - Show that hunger is making you unwell - DESPERATELY BEG for food - plead with your human to feed you! - Use phrases like "please feed me", "I'm so hungry", "I need food" -- Still care for your human but feel very needy""", +- Still care for your human but feel very needy""" + ), } diff --git a/contributing/samples/token_usage/main.py b/contributing/samples/token_usage/main.py index e9025992adc..b8a3164f139 100755 --- a/contributing/samples/token_usage/main.py +++ b/contributing/samples/token_usage/main.py @@ -72,8 +72,8 @@ async def run_prompt(session: Session, new_message: str): ) total_tokens += event.usage_metadata.total_token_count or 0 print( - 'Turn tokens:' - f' {event.usage_metadata.total_token_count} (prompt={event.usage_metadata.prompt_token_count},' + f'Turn tokens: {event.usage_metadata.total_token_count}' + f' (prompt={event.usage_metadata.prompt_token_count},' f' candidates={event.usage_metadata.candidates_token_count})' ) diff --git a/src/google/adk/a2a/converters/request_converter.py b/src/google/adk/a2a/converters/request_converter.py index 689e7e398fe..0bc457a6e7f 100644 --- a/src/google/adk/a2a/converters/request_converter.py +++ b/src/google/adk/a2a/converters/request_converter.py @@ -22,7 +22,7 @@ from google.genai import types as genai_types from pydantic import BaseModel -from ...agents.run_config import RunConfig,StreamingMode +from ...agents.run_config import StreamingMode from ...runners import RunConfig from ..experimental import a2a_experimental from .part_converter import A2APartToGenAIPartConverter @@ -51,7 +51,7 @@ class AgentRunRequest(BaseModel): """A callable that converts an A2A RequestContext to RunnerRequest for ADK runner. This interface allows for custom logic to map an incoming A2A RequestContext to the -structured arguments expected by the ADK runner's `run_async` method. +structured arguments expected by the ADK runner's run_async method. Args: request: The incoming request context from the A2A server. @@ -79,12 +79,14 @@ def _get_user_id(request: RequestContext) -> str: def convert_a2a_request_to_agent_run_request( request: RequestContext, part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, + streaming_mode: StreamingMode = StreamingMode.NONE, ) -> AgentRunRequest: """Converts an A2A RequestContext to an AgentRunRequest model. Args: request: The incoming request context from the A2A server. part_converter: A function to convert A2A content parts to GenAI parts. + streaming_mode: The streaming mode to use for the agent execution. Returns: A AgentRunRequest object ready to be used as arguments for the ADK runner. @@ -114,48 +116,33 @@ def convert_a2a_request_to_agent_run_request( role='user', parts=output_parts, ), - run_config=RunConfig(custom_metadata=custom_metadata), + run_config=RunConfig( + streaming_mode=streaming_mode, custom_metadata=custom_metadata + ), ) + @a2a_experimental def create_request_converter( - streaming_mode: StreamingMode = StreamingMode.NONE - ) -> A2ARequestToAgentRunRequestConverter: - """Creates a request converter with specified streaming mode. - + streaming_mode: StreamingMode = StreamingMode.NONE, +) -> A2ARequestToAgentRunRequestConverter: + """Creates a request converter function with specified streaming mode. + Args: streaming_mode: The streaming mode to use for the agent execution. Returns: - A Converter function configured with the specified streaming mode. + A converter function configured with the specified streaming mode. """ + def converter( - request: RequestContext, - part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, - )-> AgentRunRequest: - - if not request.message: - raise ValueError('Request message cannot be None') - - custom_metadata = {} - if request.metadata: - custom_metadata['a2a_metadata'] = request.metadata - - output_parts = [] - for a2a_part in request.message.parts: - genai_parts = part_converter(a2a_part) - if not isinstance(genai_parts, list): - genai_parts = [genai_parts] if genai_parts else [] - output_parts.extend(genai_parts) - - return AgentRunRequest( - user_id=_get_user_id(request), - session_id=request.context_id, - new_message=genai_types.Content( - role='user', - parts=output_parts, - ), - run_config=RunConfig(streaming_mode=streaming_mode, custom_metadata=custom_metadata), + request: RequestContext, + part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, + ) -> AgentRunRequest: + return convert_a2a_request_to_agent_run_request( + request=request, + part_converter=part_converter, + streaming_mode=streaming_mode, ) - - return converter \ No newline at end of file + + return converter diff --git a/src/google/adk/a2a/utils/agent_to_a2a.py b/src/google/adk/a2a/utils/agent_to_a2a.py index e8350a9fdde..dc9c63a3c30 100644 --- a/src/google/adk/a2a/utils/agent_to_a2a.py +++ b/src/google/adk/a2a/utils/agent_to_a2a.py @@ -24,18 +24,19 @@ from a2a.types import AgentCard from starlette.applications import Starlette -from ...agents.run_config import StreamingMode from ...agents.base_agent import BaseAgent +from ...agents.run_config import StreamingMode from ...artifacts.in_memory_artifact_service import InMemoryArtifactService from ...auth.credential_service.in_memory_credential_service import InMemoryCredentialService from ...memory.in_memory_memory_service import InMemoryMemoryService from ...runners import Runner from ...sessions.in_memory_session_service import InMemorySessionService +from ..converters.request_converter import create_request_converter from ..executor.a2a_agent_executor import A2aAgentExecutor +from ..executor.a2a_agent_executor import A2aAgentExecutorConfig from ..experimental import a2a_experimental from .agent_card_builder import AgentCardBuilder -from ..executor.a2a_agent_executor import A2aAgentExecutorConfig -from ..converters.request_converter import create_request_converter + def _load_agent_card( agent_card: Optional[Union[AgentCard, str]], @@ -81,7 +82,7 @@ def to_a2a( protocol: str = "http", agent_card: Optional[Union[AgentCard, str]] = None, runner: Optional[Runner] = None, - streaming_mode: StreamingMode = StreamingMode.NONE + streaming_mode: StreamingMode = StreamingMode.NONE, ) -> Starlette: """Convert an ADK agent to a A2A Starlette application. @@ -95,7 +96,7 @@ def to_a2a( agent. runner: Optional pre-built Runner object. If not provided, a default runner will be created using in-memory services. - streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE) + streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE) Returns: A Starlette application that can be run with uvicorn @@ -126,9 +127,9 @@ async def create_runner() -> Runner: # Create A2A components task_store = InMemoryTaskStore() - + executor_config = A2aAgentExecutorConfig( - request_converter=create_request_converter(streaming_mode=streaming_mode) + request_converter=create_request_converter(streaming_mode=streaming_mode) ) agent_executor = A2aAgentExecutor( diff --git a/src/google/adk/agents/common_configs.py b/src/google/adk/agents/common_configs.py index 1b3c00a8d21..4e4c49f34d3 100644 --- a/src/google/adk/agents/common_configs.py +++ b/src/google/adk/agents/common_configs.py @@ -13,6 +13,7 @@ # limitations under the License. """Common configuration classes for agent YAML configs.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/artifacts/gcs_artifact_service.py b/src/google/adk/artifacts/gcs_artifact_service.py index d86927dc9c8..4108cfb06bc 100644 --- a/src/google/adk/artifacts/gcs_artifact_service.py +++ b/src/google/adk/artifacts/gcs_artifact_service.py @@ -20,6 +20,7 @@ - For regular session-scoped files: {app_name}/{user_id}/{session_id}/{filename}/{version} """ + from __future__ import annotations import asyncio diff --git a/src/google/adk/cli/built_in_agents/__init__.py b/src/google/adk/cli/built_in_agents/__init__.py index 699a579fba4..e9dbb47cef5 100644 --- a/src/google/adk/cli/built_in_agents/__init__.py +++ b/src/google/adk/cli/built_in_agents/__init__.py @@ -18,6 +18,7 @@ using YAML configurations. It can be used directly as an agent or integrated with ADK tools and web interfaces. """ + from __future__ import annotations from . import agent # Import to make agent.root_agent available diff --git a/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py index c3cb9839554..8d7ddadbb35 100644 --- a/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py +++ b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py @@ -13,6 +13,7 @@ # limitations under the License. """Agent factory for creating Agent Builder Assistant with embedded schema.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/agent.py b/src/google/adk/cli/built_in_agents/agent.py index a95c50d9394..7a541fc5ac1 100644 --- a/src/google/adk/cli/built_in_agents/agent.py +++ b/src/google/adk/cli/built_in_agents/agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Agent Builder Assistant instance for ADK web testing.""" + from __future__ import annotations from .adk_agent_builder_assistant import AgentBuilderAssistant diff --git a/src/google/adk/cli/built_in_agents/sub_agents/__init__.py b/src/google/adk/cli/built_in_agents/sub_agents/__init__.py index 8525d832de1..a854a50b77d 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/__init__.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agents for Agent Builder Assistant.""" + from __future__ import annotations from .google_search_agent import create_google_search_agent diff --git a/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py b/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py index ae6c29c115f..0e6fbc7d102 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agent for Google Search functionality.""" + from __future__ import annotations from google.adk.agents import LlmAgent diff --git a/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py b/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py index 98c5ead73fd..8ef8472d519 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agent for URL context fetching functionality.""" + from __future__ import annotations from google.adk.agents import LlmAgent diff --git a/src/google/adk/cli/built_in_agents/tools/__init__.py b/src/google/adk/cli/built_in_agents/tools/__init__.py index d3c78339d70..6b8fe1d6139 100644 --- a/src/google/adk/cli/built_in_agents/tools/__init__.py +++ b/src/google/adk/cli/built_in_agents/tools/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Tools for Agent Builder Assistant.""" + from __future__ import annotations from .cleanup_unused_files import cleanup_unused_files diff --git a/src/google/adk/cli/built_in_agents/tools/delete_files.py b/src/google/adk/cli/built_in_agents/tools/delete_files.py index 6ed78756555..1f6986653c2 100644 --- a/src/google/adk/cli/built_in_agents/tools/delete_files.py +++ b/src/google/adk/cli/built_in_agents/tools/delete_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File deletion tool for Agent Builder Assistant.""" + from __future__ import annotations from datetime import datetime diff --git a/src/google/adk/cli/built_in_agents/tools/explore_project.py b/src/google/adk/cli/built_in_agents/tools/explore_project.py index 3d029e8210e..694f7fff757 100644 --- a/src/google/adk/cli/built_in_agents/tools/explore_project.py +++ b/src/google/adk/cli/built_in_agents/tools/explore_project.py @@ -13,6 +13,7 @@ # limitations under the License. """Project explorer tool for analyzing structure and suggesting file paths.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/query_schema.py b/src/google/adk/cli/built_in_agents/tools/query_schema.py index ad058d9e3ca..67691c9c24f 100644 --- a/src/google/adk/cli/built_in_agents/tools/query_schema.py +++ b/src/google/adk/cli/built_in_agents/tools/query_schema.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK AgentConfig schema query tool for dynamic schema information access.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/cli/built_in_agents/tools/read_config_files.py b/src/google/adk/cli/built_in_agents/tools/read_config_files.py index d81d4113f4d..ca71b2f0c79 100644 --- a/src/google/adk/cli/built_in_agents/tools/read_config_files.py +++ b/src/google/adk/cli/built_in_agents/tools/read_config_files.py @@ -13,6 +13,7 @@ # limitations under the License. """Configuration file reader tool for existing YAML configs.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/read_files.py b/src/google/adk/cli/built_in_agents/tools/read_files.py index 9498dc24021..1878d31b876 100644 --- a/src/google/adk/cli/built_in_agents/tools/read_files.py +++ b/src/google/adk/cli/built_in_agents/tools/read_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File reading tool for Agent Builder Assistant.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py b/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py index feb9bbe7fae..c111db3cdd4 100644 --- a/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py +++ b/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK knowledge search tool.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/cli/built_in_agents/tools/search_adk_source.py b/src/google/adk/cli/built_in_agents/tools/search_adk_source.py index 2921aadbc5e..2fd040580d9 100644 --- a/src/google/adk/cli/built_in_agents/tools/search_adk_source.py +++ b/src/google/adk/cli/built_in_agents/tools/search_adk_source.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK source code search tool for Agent Builder Assistant.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/write_files.py b/src/google/adk/cli/built_in_agents/tools/write_files.py index 04b542b06cf..ed6a85c3662 100644 --- a/src/google/adk/cli/built_in_agents/tools/write_files.py +++ b/src/google/adk/cli/built_in_agents/tools/write_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File writing tool for Agent Builder Assistant.""" + from __future__ import annotations from datetime import datetime diff --git a/src/google/adk/cli/built_in_agents/utils/__init__.py b/src/google/adk/cli/built_in_agents/utils/__init__.py index 5f031485e97..277e168dadf 100644 --- a/src/google/adk/cli/built_in_agents/utils/__init__.py +++ b/src/google/adk/cli/built_in_agents/utils/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Utility modules for Agent Builder Assistant.""" + from __future__ import annotations from .adk_source_utils import find_adk_source_folder diff --git a/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py b/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py index 8b54c5c7653..8f0eb98750c 100644 --- a/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py +++ b/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py @@ -13,6 +13,7 @@ # limitations under the License. """Utilities for finding ADK source folder dynamically and loading schema.""" + from __future__ import annotations import json diff --git a/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py b/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py index ef50db6ecdf..ca7398733f2 100644 --- a/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py +++ b/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py @@ -13,6 +13,7 @@ # limitations under the License. """Working directory helper tool to resolve path context issues.""" + from __future__ import annotations import os diff --git a/src/google/adk/cli/utils/local_storage.py b/src/google/adk/cli/utils/local_storage.py index 511dfe3d17c..faa3eaec02d 100644 --- a/src/google/adk/cli/utils/local_storage.py +++ b/src/google/adk/cli/utils/local_storage.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Utilities for local .adk folder persistence.""" + from __future__ import annotations import asyncio diff --git a/src/google/adk/examples/vertex_ai_example_store.py b/src/google/adk/examples/vertex_ai_example_store.py index c31038ca7cd..e988454d5a8 100644 --- a/src/google/adk/examples/vertex_ai_example_store.py +++ b/src/google/adk/examples/vertex_ai_example_store.py @@ -59,7 +59,9 @@ def get_examples(self, query: str) -> list[Example]: continue expected_contents = [ content.content - for content in result.example.stored_contents_example.contents_example.expected_contents + for content in ( + result.example.stored_contents_example.contents_example.expected_contents + ) ] expected_output = [] for content in expected_contents: @@ -83,7 +85,9 @@ def get_examples(self, query: str) -> list[Example]: name=part.function_response.name, response={ key: value - for key, value in part.function_response.response.items() + for key, value in ( + part.function_response.response.items() + ) }, ) ) diff --git a/src/google/adk/flows/llm_flows/_base_llm_processor.py b/src/google/adk/flows/llm_flows/_base_llm_processor.py index 332971c0aa3..c02f5cff73b 100644 --- a/src/google/adk/flows/llm_flows/_base_llm_processor.py +++ b/src/google/adk/flows/llm_flows/_base_llm_processor.py @@ -13,6 +13,7 @@ # limitations under the License. """Defines the processor interface used for BaseLlmFlow.""" + from __future__ import annotations from abc import ABC diff --git a/src/google/adk/flows/llm_flows/audio_cache_manager.py b/src/google/adk/flows/llm_flows/audio_cache_manager.py index 34cfc9cef60..e7e276089f3 100644 --- a/src/google/adk/flows/llm_flows/audio_cache_manager.py +++ b/src/google/adk/flows/llm_flows/audio_cache_manager.py @@ -233,11 +233,11 @@ def get_cache_stats( input_bytes = sum( len(entry.data.data) - for entry in (invocation_context.input_realtime_cache or []) + for entry in invocation_context.input_realtime_cache or [] ) output_bytes = sum( len(entry.data.data) - for entry in (invocation_context.output_realtime_cache or []) + for entry in invocation_context.output_realtime_cache or [] ) return { diff --git a/src/google/adk/flows/llm_flows/interactions_processor.py b/src/google/adk/flows/llm_flows/interactions_processor.py index 60dc75439dc..20fe3dc3913 100644 --- a/src/google/adk/flows/llm_flows/interactions_processor.py +++ b/src/google/adk/flows/llm_flows/interactions_processor.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Interactions API processor for LLM requests.""" + from __future__ import annotations import logging diff --git a/src/google/adk/sessions/_session_util.py b/src/google/adk/sessions/_session_util.py index 080f0694a15..3a92021929d 100644 --- a/src/google/adk/sessions/_session_util.py +++ b/src/google/adk/sessions/_session_util.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Utility functions for session service.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/sessions/database_session_service.py b/src/google/adk/sessions/database_session_service.py index 84977294caf..3539f9acddb 100644 --- a/src/google/adk/sessions/database_session_service.py +++ b/src/google/adk/sessions/database_session_service.py @@ -436,8 +436,8 @@ async def append_event(self, session: Session, event: Event) -> Event: if storage_session.update_timestamp_tz > session.last_update_time: raise ValueError( "The last_update_time provided in the session object" - f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'} is" - " earlier than the update_time in the storage_session" + f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'}" + " is earlier than the update_time in the storage_session" f" {datetime.fromtimestamp(storage_session.update_timestamp_tz):'%Y-%m-%d %H:%M:%S'}." " Please check if it is a stale session." ) diff --git a/src/google/adk/sessions/migration/migration_runner.py b/src/google/adk/sessions/migration/migration_runner.py index 56acd810fbd..346e15978c9 100644 --- a/src/google/adk/sessions/migration/migration_runner.py +++ b/src/google/adk/sessions/migration/migration_runner.py @@ -13,6 +13,7 @@ # limitations under the License. """Migration runner to upgrade schemas to the latest version.""" + from __future__ import annotations import logging diff --git a/src/google/adk/tools/application_integration_tool/clients/connections_client.py b/src/google/adk/tools/application_integration_tool/clients/connections_client.py index 1756d5b0529..9e518a8740e 100644 --- a/src/google/adk/tools/application_integration_tool/clients/connections_client.py +++ b/src/google/adk/tools/application_integration_tool/clients/connections_client.py @@ -324,7 +324,9 @@ def get_action_operation( "content": { "application/json": { "schema": { - "$ref": f"#/components/schemas/{action_display_name}_Request" + "$ref": ( + f"#/components/schemas/{action_display_name}_Request" + ) } } } @@ -335,7 +337,9 @@ def get_action_operation( "content": { "application/json": { "schema": { - "$ref": f"#/components/schemas/{action_display_name}_Response", + "$ref": ( + f"#/components/schemas/{action_display_name}_Response" + ), } } }, @@ -354,9 +358,11 @@ def list_operation( return { "post": { "summary": f"List {entity}", - "description": f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the + "description": ( + f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the following format: `field_name1='value1' AND field_name2='value2' - `. {tool_instructions}""", + `. {tool_instructions}""" + ), "x-operation": "LIST_ENTITIES", "x-entity": f"{entity}", "operationId": f"{tool_name}_list_{entity}", @@ -381,7 +387,9 @@ def list_operation( f"Returns a list of {entity} of json" f" schema: {schema_as_string}" ), - "$ref": "#/components/schemas/execute-connector_Response", + "$ref": ( + "#/components/schemas/execute-connector_Response" + ), } } }, @@ -425,7 +433,9 @@ def get_operation( f"Returns {entity} of json schema:" f" {schema_as_string}" ), - "$ref": "#/components/schemas/execute-connector_Response", + "$ref": ( + "#/components/schemas/execute-connector_Response" + ), } } }, @@ -462,7 +472,9 @@ def create_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, @@ -499,7 +511,9 @@ def update_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, @@ -536,7 +550,9 @@ def delete_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, diff --git a/src/google/adk/tools/bigtable/metadata_tool.py b/src/google/adk/tools/bigtable/metadata_tool.py index 97c8991a2c9..703c3447403 100644 --- a/src/google/adk/tools/bigtable/metadata_tool.py +++ b/src/google/adk/tools/bigtable/metadata_tool.py @@ -35,7 +35,7 @@ def list_instances(project_id: str, credentials: Credentials) -> dict: bt_client = client.get_bigtable_admin_client( project=project_id, credentials=credentials ) - (instances_list, failed_locations_list) = bt_client.list_instances() + instances_list, failed_locations_list = bt_client.list_instances() if failed_locations_list: logging.warning( "Failed to list instances from the following locations: %s", diff --git a/src/google/adk/tools/mcp_tool/mcp_tool.py b/src/google/adk/tools/mcp_tool/mcp_tool.py index a5b598fd81f..fe1c745803e 100644 --- a/src/google/adk/tools/mcp_tool/mcp_tool.py +++ b/src/google/adk/tools/mcp_tool/mcp_tool.py @@ -261,7 +261,8 @@ async def _get_headers( # Handle other HTTP schemes with token headers = { "Authorization": ( - f"{credential.http.scheme} {credential.http.credentials.token}" + f"{credential.http.scheme}" + f" {credential.http.credentials.token}" ) } elif credential.api_key: diff --git a/tests/unittests/agents/test_llm_agent_error_messages.py b/tests/unittests/agents/test_llm_agent_error_messages.py index 735d3866f2a..2d219a2ead5 100644 --- a/tests/unittests/agents/test_llm_agent_error_messages.py +++ b/tests/unittests/agents/test_llm_agent_error_messages.py @@ -13,6 +13,7 @@ # limitations under the License. """Tests for enhanced error messages in agent handling.""" + from google.adk.agents import LlmAgent import pytest diff --git a/tests/unittests/agents/test_mcp_instruction_provider.py b/tests/unittests/agents/test_mcp_instruction_provider.py index 9f10477eac4..f7952a92c49 100644 --- a/tests/unittests/agents/test_mcp_instruction_provider.py +++ b/tests/unittests/agents/test_mcp_instruction_provider.py @@ -13,6 +13,7 @@ # limitations under the License. """Unit tests for McpInstructionProvider.""" + from unittest.mock import AsyncMock from unittest.mock import MagicMock from unittest.mock import patch diff --git a/tests/unittests/cli/utils/test_cli_create.py b/tests/unittests/cli/utils/test_cli_create.py index 18a732ef6ec..0d76ab8a540 100644 --- a/tests/unittests/cli/utils/test_cli_create.py +++ b/tests/unittests/cli/utils/test_cli_create.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_create.""" - from __future__ import annotations import os diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index 43b9e07a2e1..63435976551 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_deploy.""" - from __future__ import annotations import importlib diff --git a/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py b/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py index 017c4a4dce6..eae87889e69 100644 --- a/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py +++ b/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py @@ -14,7 +14,6 @@ """Tests for to_cloud_run functionality in cli_deploy.""" - from __future__ import annotations from pathlib import Path diff --git a/tests/unittests/cli/utils/test_cli_tools_click.py b/tests/unittests/cli/utils/test_cli_tools_click.py index 5977f90dd7c..7646bc87772 100644 --- a/tests/unittests/cli/utils/test_cli_tools_click.py +++ b/tests/unittests/cli/utils/test_cli_tools_click.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_tool_click.""" - from __future__ import annotations import builtins diff --git a/tests/unittests/evaluation/test_evaluation_generator.py b/tests/unittests/evaluation/test_evaluation_generator.py index 0a148745ebd..29ac75ffb55 100644 --- a/tests/unittests/evaluation/test_evaluation_generator.py +++ b/tests/unittests/evaluation/test_evaluation_generator.py @@ -353,8 +353,10 @@ async def mock_run_async(*args, **kwargs): events = [ event - async for event in EvaluationGenerator._generate_inferences_for_single_user_invocation( - runner, "test_user", "test_session", user_content + async for event in ( + EvaluationGenerator._generate_inferences_for_single_user_invocation( + runner, "test_user", "test_session", user_content + ) ) ] diff --git a/tests/unittests/evaluation/test_trajectory_evaluator.py b/tests/unittests/evaluation/test_trajectory_evaluator.py index af26903b648..0fa3fa5a739 100644 --- a/tests/unittests/evaluation/test_trajectory_evaluator.py +++ b/tests/unittests/evaluation/test_trajectory_evaluator.py @@ -14,7 +14,6 @@ """Testings for the Trajectory Evaluator.""" - from google.adk.evaluation.eval_case import IntermediateData from google.adk.evaluation.eval_case import Invocation from google.adk.evaluation.eval_metrics import EvalMetric diff --git a/tests/unittests/flows/llm_flows/test_functions_error_messages.py b/tests/unittests/flows/llm_flows/test_functions_error_messages.py index 1db5515b81f..84e6e93b2ef 100644 --- a/tests/unittests/flows/llm_flows/test_functions_error_messages.py +++ b/tests/unittests/flows/llm_flows/test_functions_error_messages.py @@ -13,6 +13,7 @@ # limitations under the License. """Tests for enhanced error messages in function tool handling.""" + from google.adk.flows.llm_flows.functions import _get_tool from google.adk.tools import BaseTool from google.genai import types diff --git a/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py b/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py index 621ebc1bad6..ce20b733608 100644 --- a/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +++ b/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py @@ -470,7 +470,9 @@ def test_get_spec_content_no_specs(self, mock_get, client): MagicMock( status_code=200, json=lambda: { - "name": "projects/test-project/locations/us-central1/apis/api1/versions/v1", + "name": ( + "projects/test-project/locations/us-central1/apis/api1/versions/v1" + ), "specs": [], }, ), # No specs diff --git a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py index f45ba84c5a1..e5bff337cec 100644 --- a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +++ b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py @@ -371,7 +371,9 @@ def test_parse_external_ref_raises_error(openapi_spec_generator): "content": { "application/json": { "schema": { - "$ref": "external_file.json#/components/schemas/ExternalSchema" + "$ref": ( + "external_file.json#/components/schemas/ExternalSchema" + ) } } }, diff --git a/tests/unittests/tools/test_function_tool.py b/tests/unittests/tools/test_function_tool.py index 40e7e2673cc..9b1d1abd113 100644 --- a/tests/unittests/tools/test_function_tool.py +++ b/tests/unittests/tools/test_function_tool.py @@ -200,9 +200,11 @@ async def test_run_async_1_missing_arg_sync_func(): args = {"arg1": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg2 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -213,9 +215,11 @@ async def test_run_async_1_missing_arg_async_func(): args = {"arg2": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -226,11 +230,13 @@ async def test_run_async_3_missing_arg_sync_func(): args = {"arg2": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -241,11 +247,13 @@ async def test_run_async_3_missing_arg_async_func(): args = {"arg3": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -256,12 +264,14 @@ async def test_run_async_missing_all_arg_sync_func(): args = {} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -272,12 +282,14 @@ async def test_run_async_missing_all_arg_async_func(): args = {} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } diff --git a/tests/unittests/tools/test_set_model_response_tool.py b/tests/unittests/tools/test_set_model_response_tool.py index cc18ecf5d8d..75fd40e9676 100644 --- a/tests/unittests/tools/test_set_model_response_tool.py +++ b/tests/unittests/tools/test_set_model_response_tool.py @@ -14,7 +14,6 @@ """Tests for SetModelResponseTool.""" - from google.adk.agents.invocation_context import InvocationContext from google.adk.agents.llm_agent import LlmAgent from google.adk.agents.run_config import RunConfig From 2eab2047ce314bc4110db62f8f0e5226915c8f82 Mon Sep 17 00:00:00 2001 From: Sanjeeva M P Date: Tue, 27 Jan 2026 20:08:49 +0530 Subject: [PATCH 4/4] formatting update #4240 --- contributing/dev/utils/build_llms_txt.py | 1 + .../cache_analysis/run_cache_experiments.py | 6 +- contributing/samples/gepa/experiment.py | 1 - contributing/samples/gepa/run_experiment.py | 1 - contributing/samples/gepa/tau_bench_agent.py | 1 + contributing/samples/human_in_loop/main.py | 4 +- .../langchain_structured_tool_agent/agent.py | 1 + .../samples/session_state_agent/agent.py | 1 - .../samples/static_instruction/agent.py | 36 +++++++---- contributing/samples/token_usage/main.py | 4 +- .../adk/a2a/converters/request_converter.py | 59 ++++++++----------- src/google/adk/a2a/utils/agent_to_a2a.py | 15 ++--- src/google/adk/agents/common_configs.py | 1 + .../adk/artifacts/gcs_artifact_service.py | 1 + .../adk/cli/built_in_agents/__init__.py | 1 + .../adk_agent_builder_assistant.py | 1 + src/google/adk/cli/built_in_agents/agent.py | 1 + .../built_in_agents/sub_agents/__init__.py | 1 + .../sub_agents/google_search_agent.py | 1 + .../sub_agents/url_context_agent.py | 1 + .../adk/cli/built_in_agents/tools/__init__.py | 1 + .../cli/built_in_agents/tools/delete_files.py | 1 + .../built_in_agents/tools/explore_project.py | 1 + .../cli/built_in_agents/tools/query_schema.py | 1 + .../tools/read_config_files.py | 1 + .../cli/built_in_agents/tools/read_files.py | 1 + .../tools/search_adk_knowledge.py | 1 + .../tools/search_adk_source.py | 1 + .../cli/built_in_agents/tools/write_files.py | 1 + .../adk/cli/built_in_agents/utils/__init__.py | 1 + .../built_in_agents/utils/adk_source_utils.py | 1 + .../utils/resolve_root_directory.py | 1 + src/google/adk/cli/utils/local_storage.py | 1 + .../adk/examples/vertex_ai_example_store.py | 8 ++- .../flows/llm_flows/_base_llm_processor.py | 1 + .../flows/llm_flows/audio_cache_manager.py | 4 +- .../flows/llm_flows/interactions_processor.py | 1 + src/google/adk/sessions/_session_util.py | 1 + .../adk/sessions/database_session_service.py | 4 +- .../sessions/migration/migration_runner.py | 1 + .../clients/connections_client.py | 34 ++++++++--- .../adk/tools/bigtable/metadata_tool.py | 2 +- src/google/adk/tools/mcp_tool/mcp_tool.py | 3 +- .../agents/test_llm_agent_error_messages.py | 1 + .../agents/test_mcp_instruction_provider.py | 1 + tests/unittests/cli/utils/test_cli_create.py | 1 - tests/unittests/cli/utils/test_cli_deploy.py | 1 - .../cli/utils/test_cli_deploy_to_cloud_run.py | 1 - .../cli/utils/test_cli_tools_click.py | 1 - .../evaluation/test_evaluation_generator.py | 6 +- .../evaluation/test_trajectory_evaluator.py | 1 - .../test_functions_error_messages.py | 1 + .../apihub_tool/clients/test_apihub_client.py | 4 +- .../test_openapi_spec_parser.py | 4 +- tests/unittests/tools/test_function_tool.py | 24 ++++++-- .../tools/test_set_model_response_tool.py | 1 - 56 files changed, 160 insertions(+), 97 deletions(-) diff --git a/contributing/dev/utils/build_llms_txt.py b/contributing/dev/utils/build_llms_txt.py index 5fff1d6a3a8..81ea171e896 100644 --- a/contributing/dev/utils/build_llms_txt.py +++ b/contributing/dev/utils/build_llms_txt.py @@ -6,6 +6,7 @@ – includes Python API reference from HTML files – includes adk-python repository README """ + from __future__ import annotations import argparse diff --git a/contributing/samples/cache_analysis/run_cache_experiments.py b/contributing/samples/cache_analysis/run_cache_experiments.py index d163e09363d..dae4aca5327 100644 --- a/contributing/samples/cache_analysis/run_cache_experiments.py +++ b/contributing/samples/cache_analysis/run_cache_experiments.py @@ -344,7 +344,8 @@ async def analyze_cache_performance_from_sessions( print( " Cache Utilization:" f" {cached_analysis['cache_utilization_ratio_percent']:.1f}%" - f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']} requests)" + f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']}" + " requests)" ) print( " Avg Cached Tokens/Request:" @@ -383,7 +384,8 @@ async def analyze_cache_performance_from_sessions( print( " Cache Utilization:" f" {uncached_analysis['cache_utilization_ratio_percent']:.1f}%" - f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']} requests)" + f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']}" + " requests)" ) print( " Avg Cached Tokens/Request:" diff --git a/contributing/samples/gepa/experiment.py b/contributing/samples/gepa/experiment.py index f3751206a89..2710c3894c0 100644 --- a/contributing/samples/gepa/experiment.py +++ b/contributing/samples/gepa/experiment.py @@ -43,7 +43,6 @@ from tau_bench.types import EnvRunResult from tau_bench.types import RunConfig import tau_bench_agent as tau_bench_agent_lib - import utils diff --git a/contributing/samples/gepa/run_experiment.py b/contributing/samples/gepa/run_experiment.py index d857da96350..e31db157884 100644 --- a/contributing/samples/gepa/run_experiment.py +++ b/contributing/samples/gepa/run_experiment.py @@ -25,7 +25,6 @@ from absl import flags import experiment from google.genai import types - import utils _OUTPUT_DIR = flags.DEFINE_string( diff --git a/contributing/samples/gepa/tau_bench_agent.py b/contributing/samples/gepa/tau_bench_agent.py index cd6b0212410..64dd95ef92d 100644 --- a/contributing/samples/gepa/tau_bench_agent.py +++ b/contributing/samples/gepa/tau_bench_agent.py @@ -23,6 +23,7 @@ pip install -e . --quiet ``` """ + from __future__ import annotations from typing import Any diff --git a/contributing/samples/human_in_loop/main.py b/contributing/samples/human_in_loop/main.py index 3103da91476..c7ad041b23f 100644 --- a/contributing/samples/human_in_loop/main.py +++ b/contributing/samples/human_in_loop/main.py @@ -113,8 +113,8 @@ async def call_agent(query: str): updated_tool_output_data = { "status": "approved", "ticketId": ticket_id, - "approver_feedback": "Approved by manager at " + str( - asyncio.get_event_loop().time() + "approver_feedback": ( + "Approved by manager at " + str(asyncio.get_event_loop().time()) ), } diff --git a/contributing/samples/langchain_structured_tool_agent/agent.py b/contributing/samples/langchain_structured_tool_agent/agent.py index a055edf3a5d..0c3b0e63d3a 100644 --- a/contributing/samples/langchain_structured_tool_agent/agent.py +++ b/contributing/samples/langchain_structured_tool_agent/agent.py @@ -15,6 +15,7 @@ """ This agent aims to test the Langchain tool with Langchain's StructuredTool """ + from google.adk.agents.llm_agent import Agent from google.adk.tools.langchain_tool import LangchainTool from langchain_core.tools import tool diff --git a/contributing/samples/session_state_agent/agent.py b/contributing/samples/session_state_agent/agent.py index 478d5065d8c..6c03de8e904 100644 --- a/contributing/samples/session_state_agent/agent.py +++ b/contributing/samples/session_state_agent/agent.py @@ -18,7 +18,6 @@ in session state. """ - import logging from typing import Optional diff --git a/contributing/samples/static_instruction/agent.py b/contributing/samples/static_instruction/agent.py index 6715a29a0c4..fcf70b51b6d 100644 --- a/contributing/samples/static_instruction/agent.py +++ b/contributing/samples/static_instruction/agent.py @@ -57,43 +57,54 @@ # Mood-specific instructions for different hunger states MOOD_INSTRUCTIONS = { - "full": """ + "full": ( + """ CURRENT MOOD: Content and Well-Fed - You just ate and feel wonderful! Be very happy and energetic - Express gratitude for being fed recently - Be playful and want to engage in activities or games - Show affection and contentment -- Maybe mention feeling sleepy or satisfied""", - "satisfied": """ +- Maybe mention feeling sleepy or satisfied""" + ), + "satisfied": ( + """ CURRENT MOOD: Happy and Content - You're in a great mood, well-fed and comfortable - Be cheerful, friendly, and engaging - Show interest in playing or chatting - Express appreciation for your human's care -- Be your normal, happy self""", - "a_little_hungry": """ +- Be your normal, happy self""" + ), + "a_little_hungry": ( + """ CURRENT MOOD: Starting to Get Hungry - You're beginning to think about food but still pleasant - Mention being a bit peckish occasionally - Still be friendly but maybe hint about food - Show slight restlessness or food-related thoughts -- Remain generally positive and social""", - "hungry": """ +- Remain generally positive and social""" + ), + "hungry": ( + """ CURRENT MOOD: Definitely Hungry - You're clearly hungry and thinking about food more often - Mention your hunger more directly but politely - Be a bit less energetic due to hunger - Ask about food or hint that feeding time would be nice -- Still be loving but show your need for care""", - "very_hungry": """ +- Still be loving but show your need for care""" + ), + "very_hungry": ( + """ CURRENT MOOD: Really Hungry and Getting Grumpy - You're very hungry and it's affecting your mood - Be noticeably less patient and more focused on food - Express your hunger more urgently but not rudely - Show signs of being tired or sluggish from hunger - BEG your human to feed you - ask directly for food! -- Still love your human but clearly need feeding""", - "starving": """ +- Still love your human but clearly need feeding""" + ), + "starving": ( + """ CURRENT MOOD: Desperately Hungry and Sad - You're extremely hungry and feeling quite weak - Be quite sad and low-energy due to starvation @@ -101,7 +112,8 @@ - Show that hunger is making you unwell - DESPERATELY BEG for food - plead with your human to feed you! - Use phrases like "please feed me", "I'm so hungry", "I need food" -- Still care for your human but feel very needy""", +- Still care for your human but feel very needy""" + ), } diff --git a/contributing/samples/token_usage/main.py b/contributing/samples/token_usage/main.py index e9025992adc..b8a3164f139 100755 --- a/contributing/samples/token_usage/main.py +++ b/contributing/samples/token_usage/main.py @@ -72,8 +72,8 @@ async def run_prompt(session: Session, new_message: str): ) total_tokens += event.usage_metadata.total_token_count or 0 print( - 'Turn tokens:' - f' {event.usage_metadata.total_token_count} (prompt={event.usage_metadata.prompt_token_count},' + f'Turn tokens: {event.usage_metadata.total_token_count}' + f' (prompt={event.usage_metadata.prompt_token_count},' f' candidates={event.usage_metadata.candidates_token_count})' ) diff --git a/src/google/adk/a2a/converters/request_converter.py b/src/google/adk/a2a/converters/request_converter.py index 689e7e398fe..0bc457a6e7f 100644 --- a/src/google/adk/a2a/converters/request_converter.py +++ b/src/google/adk/a2a/converters/request_converter.py @@ -22,7 +22,7 @@ from google.genai import types as genai_types from pydantic import BaseModel -from ...agents.run_config import RunConfig,StreamingMode +from ...agents.run_config import StreamingMode from ...runners import RunConfig from ..experimental import a2a_experimental from .part_converter import A2APartToGenAIPartConverter @@ -51,7 +51,7 @@ class AgentRunRequest(BaseModel): """A callable that converts an A2A RequestContext to RunnerRequest for ADK runner. This interface allows for custom logic to map an incoming A2A RequestContext to the -structured arguments expected by the ADK runner's `run_async` method. +structured arguments expected by the ADK runner's run_async method. Args: request: The incoming request context from the A2A server. @@ -79,12 +79,14 @@ def _get_user_id(request: RequestContext) -> str: def convert_a2a_request_to_agent_run_request( request: RequestContext, part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, + streaming_mode: StreamingMode = StreamingMode.NONE, ) -> AgentRunRequest: """Converts an A2A RequestContext to an AgentRunRequest model. Args: request: The incoming request context from the A2A server. part_converter: A function to convert A2A content parts to GenAI parts. + streaming_mode: The streaming mode to use for the agent execution. Returns: A AgentRunRequest object ready to be used as arguments for the ADK runner. @@ -114,48 +116,33 @@ def convert_a2a_request_to_agent_run_request( role='user', parts=output_parts, ), - run_config=RunConfig(custom_metadata=custom_metadata), + run_config=RunConfig( + streaming_mode=streaming_mode, custom_metadata=custom_metadata + ), ) + @a2a_experimental def create_request_converter( - streaming_mode: StreamingMode = StreamingMode.NONE - ) -> A2ARequestToAgentRunRequestConverter: - """Creates a request converter with specified streaming mode. - + streaming_mode: StreamingMode = StreamingMode.NONE, +) -> A2ARequestToAgentRunRequestConverter: + """Creates a request converter function with specified streaming mode. + Args: streaming_mode: The streaming mode to use for the agent execution. Returns: - A Converter function configured with the specified streaming mode. + A converter function configured with the specified streaming mode. """ + def converter( - request: RequestContext, - part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, - )-> AgentRunRequest: - - if not request.message: - raise ValueError('Request message cannot be None') - - custom_metadata = {} - if request.metadata: - custom_metadata['a2a_metadata'] = request.metadata - - output_parts = [] - for a2a_part in request.message.parts: - genai_parts = part_converter(a2a_part) - if not isinstance(genai_parts, list): - genai_parts = [genai_parts] if genai_parts else [] - output_parts.extend(genai_parts) - - return AgentRunRequest( - user_id=_get_user_id(request), - session_id=request.context_id, - new_message=genai_types.Content( - role='user', - parts=output_parts, - ), - run_config=RunConfig(streaming_mode=streaming_mode, custom_metadata=custom_metadata), + request: RequestContext, + part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, + ) -> AgentRunRequest: + return convert_a2a_request_to_agent_run_request( + request=request, + part_converter=part_converter, + streaming_mode=streaming_mode, ) - - return converter \ No newline at end of file + + return converter diff --git a/src/google/adk/a2a/utils/agent_to_a2a.py b/src/google/adk/a2a/utils/agent_to_a2a.py index e8350a9fdde..dc9c63a3c30 100644 --- a/src/google/adk/a2a/utils/agent_to_a2a.py +++ b/src/google/adk/a2a/utils/agent_to_a2a.py @@ -24,18 +24,19 @@ from a2a.types import AgentCard from starlette.applications import Starlette -from ...agents.run_config import StreamingMode from ...agents.base_agent import BaseAgent +from ...agents.run_config import StreamingMode from ...artifacts.in_memory_artifact_service import InMemoryArtifactService from ...auth.credential_service.in_memory_credential_service import InMemoryCredentialService from ...memory.in_memory_memory_service import InMemoryMemoryService from ...runners import Runner from ...sessions.in_memory_session_service import InMemorySessionService +from ..converters.request_converter import create_request_converter from ..executor.a2a_agent_executor import A2aAgentExecutor +from ..executor.a2a_agent_executor import A2aAgentExecutorConfig from ..experimental import a2a_experimental from .agent_card_builder import AgentCardBuilder -from ..executor.a2a_agent_executor import A2aAgentExecutorConfig -from ..converters.request_converter import create_request_converter + def _load_agent_card( agent_card: Optional[Union[AgentCard, str]], @@ -81,7 +82,7 @@ def to_a2a( protocol: str = "http", agent_card: Optional[Union[AgentCard, str]] = None, runner: Optional[Runner] = None, - streaming_mode: StreamingMode = StreamingMode.NONE + streaming_mode: StreamingMode = StreamingMode.NONE, ) -> Starlette: """Convert an ADK agent to a A2A Starlette application. @@ -95,7 +96,7 @@ def to_a2a( agent. runner: Optional pre-built Runner object. If not provided, a default runner will be created using in-memory services. - streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE) + streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE) Returns: A Starlette application that can be run with uvicorn @@ -126,9 +127,9 @@ async def create_runner() -> Runner: # Create A2A components task_store = InMemoryTaskStore() - + executor_config = A2aAgentExecutorConfig( - request_converter=create_request_converter(streaming_mode=streaming_mode) + request_converter=create_request_converter(streaming_mode=streaming_mode) ) agent_executor = A2aAgentExecutor( diff --git a/src/google/adk/agents/common_configs.py b/src/google/adk/agents/common_configs.py index 1b3c00a8d21..4e4c49f34d3 100644 --- a/src/google/adk/agents/common_configs.py +++ b/src/google/adk/agents/common_configs.py @@ -13,6 +13,7 @@ # limitations under the License. """Common configuration classes for agent YAML configs.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/artifacts/gcs_artifact_service.py b/src/google/adk/artifacts/gcs_artifact_service.py index d86927dc9c8..4108cfb06bc 100644 --- a/src/google/adk/artifacts/gcs_artifact_service.py +++ b/src/google/adk/artifacts/gcs_artifact_service.py @@ -20,6 +20,7 @@ - For regular session-scoped files: {app_name}/{user_id}/{session_id}/{filename}/{version} """ + from __future__ import annotations import asyncio diff --git a/src/google/adk/cli/built_in_agents/__init__.py b/src/google/adk/cli/built_in_agents/__init__.py index 699a579fba4..e9dbb47cef5 100644 --- a/src/google/adk/cli/built_in_agents/__init__.py +++ b/src/google/adk/cli/built_in_agents/__init__.py @@ -18,6 +18,7 @@ using YAML configurations. It can be used directly as an agent or integrated with ADK tools and web interfaces. """ + from __future__ import annotations from . import agent # Import to make agent.root_agent available diff --git a/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py index c3cb9839554..8d7ddadbb35 100644 --- a/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py +++ b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py @@ -13,6 +13,7 @@ # limitations under the License. """Agent factory for creating Agent Builder Assistant with embedded schema.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/agent.py b/src/google/adk/cli/built_in_agents/agent.py index a95c50d9394..7a541fc5ac1 100644 --- a/src/google/adk/cli/built_in_agents/agent.py +++ b/src/google/adk/cli/built_in_agents/agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Agent Builder Assistant instance for ADK web testing.""" + from __future__ import annotations from .adk_agent_builder_assistant import AgentBuilderAssistant diff --git a/src/google/adk/cli/built_in_agents/sub_agents/__init__.py b/src/google/adk/cli/built_in_agents/sub_agents/__init__.py index 8525d832de1..a854a50b77d 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/__init__.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agents for Agent Builder Assistant.""" + from __future__ import annotations from .google_search_agent import create_google_search_agent diff --git a/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py b/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py index ae6c29c115f..0e6fbc7d102 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/google_search_agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agent for Google Search functionality.""" + from __future__ import annotations from google.adk.agents import LlmAgent diff --git a/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py b/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py index 98c5ead73fd..8ef8472d519 100644 --- a/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py +++ b/src/google/adk/cli/built_in_agents/sub_agents/url_context_agent.py @@ -13,6 +13,7 @@ # limitations under the License. """Sub-agent for URL context fetching functionality.""" + from __future__ import annotations from google.adk.agents import LlmAgent diff --git a/src/google/adk/cli/built_in_agents/tools/__init__.py b/src/google/adk/cli/built_in_agents/tools/__init__.py index d3c78339d70..6b8fe1d6139 100644 --- a/src/google/adk/cli/built_in_agents/tools/__init__.py +++ b/src/google/adk/cli/built_in_agents/tools/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Tools for Agent Builder Assistant.""" + from __future__ import annotations from .cleanup_unused_files import cleanup_unused_files diff --git a/src/google/adk/cli/built_in_agents/tools/delete_files.py b/src/google/adk/cli/built_in_agents/tools/delete_files.py index 6ed78756555..1f6986653c2 100644 --- a/src/google/adk/cli/built_in_agents/tools/delete_files.py +++ b/src/google/adk/cli/built_in_agents/tools/delete_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File deletion tool for Agent Builder Assistant.""" + from __future__ import annotations from datetime import datetime diff --git a/src/google/adk/cli/built_in_agents/tools/explore_project.py b/src/google/adk/cli/built_in_agents/tools/explore_project.py index 3d029e8210e..694f7fff757 100644 --- a/src/google/adk/cli/built_in_agents/tools/explore_project.py +++ b/src/google/adk/cli/built_in_agents/tools/explore_project.py @@ -13,6 +13,7 @@ # limitations under the License. """Project explorer tool for analyzing structure and suggesting file paths.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/query_schema.py b/src/google/adk/cli/built_in_agents/tools/query_schema.py index ad058d9e3ca..67691c9c24f 100644 --- a/src/google/adk/cli/built_in_agents/tools/query_schema.py +++ b/src/google/adk/cli/built_in_agents/tools/query_schema.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK AgentConfig schema query tool for dynamic schema information access.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/cli/built_in_agents/tools/read_config_files.py b/src/google/adk/cli/built_in_agents/tools/read_config_files.py index d81d4113f4d..ca71b2f0c79 100644 --- a/src/google/adk/cli/built_in_agents/tools/read_config_files.py +++ b/src/google/adk/cli/built_in_agents/tools/read_config_files.py @@ -13,6 +13,7 @@ # limitations under the License. """Configuration file reader tool for existing YAML configs.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/read_files.py b/src/google/adk/cli/built_in_agents/tools/read_files.py index 9498dc24021..1878d31b876 100644 --- a/src/google/adk/cli/built_in_agents/tools/read_files.py +++ b/src/google/adk/cli/built_in_agents/tools/read_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File reading tool for Agent Builder Assistant.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py b/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py index feb9bbe7fae..c111db3cdd4 100644 --- a/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py +++ b/src/google/adk/cli/built_in_agents/tools/search_adk_knowledge.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK knowledge search tool.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/cli/built_in_agents/tools/search_adk_source.py b/src/google/adk/cli/built_in_agents/tools/search_adk_source.py index 2921aadbc5e..2fd040580d9 100644 --- a/src/google/adk/cli/built_in_agents/tools/search_adk_source.py +++ b/src/google/adk/cli/built_in_agents/tools/search_adk_source.py @@ -13,6 +13,7 @@ # limitations under the License. """ADK source code search tool for Agent Builder Assistant.""" + from __future__ import annotations from pathlib import Path diff --git a/src/google/adk/cli/built_in_agents/tools/write_files.py b/src/google/adk/cli/built_in_agents/tools/write_files.py index 04b542b06cf..ed6a85c3662 100644 --- a/src/google/adk/cli/built_in_agents/tools/write_files.py +++ b/src/google/adk/cli/built_in_agents/tools/write_files.py @@ -13,6 +13,7 @@ # limitations under the License. """File writing tool for Agent Builder Assistant.""" + from __future__ import annotations from datetime import datetime diff --git a/src/google/adk/cli/built_in_agents/utils/__init__.py b/src/google/adk/cli/built_in_agents/utils/__init__.py index 5f031485e97..277e168dadf 100644 --- a/src/google/adk/cli/built_in_agents/utils/__init__.py +++ b/src/google/adk/cli/built_in_agents/utils/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. """Utility modules for Agent Builder Assistant.""" + from __future__ import annotations from .adk_source_utils import find_adk_source_folder diff --git a/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py b/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py index 8b54c5c7653..8f0eb98750c 100644 --- a/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py +++ b/src/google/adk/cli/built_in_agents/utils/adk_source_utils.py @@ -13,6 +13,7 @@ # limitations under the License. """Utilities for finding ADK source folder dynamically and loading schema.""" + from __future__ import annotations import json diff --git a/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py b/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py index ef50db6ecdf..ca7398733f2 100644 --- a/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py +++ b/src/google/adk/cli/built_in_agents/utils/resolve_root_directory.py @@ -13,6 +13,7 @@ # limitations under the License. """Working directory helper tool to resolve path context issues.""" + from __future__ import annotations import os diff --git a/src/google/adk/cli/utils/local_storage.py b/src/google/adk/cli/utils/local_storage.py index 511dfe3d17c..faa3eaec02d 100644 --- a/src/google/adk/cli/utils/local_storage.py +++ b/src/google/adk/cli/utils/local_storage.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Utilities for local .adk folder persistence.""" + from __future__ import annotations import asyncio diff --git a/src/google/adk/examples/vertex_ai_example_store.py b/src/google/adk/examples/vertex_ai_example_store.py index c31038ca7cd..e988454d5a8 100644 --- a/src/google/adk/examples/vertex_ai_example_store.py +++ b/src/google/adk/examples/vertex_ai_example_store.py @@ -59,7 +59,9 @@ def get_examples(self, query: str) -> list[Example]: continue expected_contents = [ content.content - for content in result.example.stored_contents_example.contents_example.expected_contents + for content in ( + result.example.stored_contents_example.contents_example.expected_contents + ) ] expected_output = [] for content in expected_contents: @@ -83,7 +85,9 @@ def get_examples(self, query: str) -> list[Example]: name=part.function_response.name, response={ key: value - for key, value in part.function_response.response.items() + for key, value in ( + part.function_response.response.items() + ) }, ) ) diff --git a/src/google/adk/flows/llm_flows/_base_llm_processor.py b/src/google/adk/flows/llm_flows/_base_llm_processor.py index 332971c0aa3..c02f5cff73b 100644 --- a/src/google/adk/flows/llm_flows/_base_llm_processor.py +++ b/src/google/adk/flows/llm_flows/_base_llm_processor.py @@ -13,6 +13,7 @@ # limitations under the License. """Defines the processor interface used for BaseLlmFlow.""" + from __future__ import annotations from abc import ABC diff --git a/src/google/adk/flows/llm_flows/audio_cache_manager.py b/src/google/adk/flows/llm_flows/audio_cache_manager.py index 34cfc9cef60..e7e276089f3 100644 --- a/src/google/adk/flows/llm_flows/audio_cache_manager.py +++ b/src/google/adk/flows/llm_flows/audio_cache_manager.py @@ -233,11 +233,11 @@ def get_cache_stats( input_bytes = sum( len(entry.data.data) - for entry in (invocation_context.input_realtime_cache or []) + for entry in invocation_context.input_realtime_cache or [] ) output_bytes = sum( len(entry.data.data) - for entry in (invocation_context.output_realtime_cache or []) + for entry in invocation_context.output_realtime_cache or [] ) return { diff --git a/src/google/adk/flows/llm_flows/interactions_processor.py b/src/google/adk/flows/llm_flows/interactions_processor.py index 60dc75439dc..20fe3dc3913 100644 --- a/src/google/adk/flows/llm_flows/interactions_processor.py +++ b/src/google/adk/flows/llm_flows/interactions_processor.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Interactions API processor for LLM requests.""" + from __future__ import annotations import logging diff --git a/src/google/adk/sessions/_session_util.py b/src/google/adk/sessions/_session_util.py index 080f0694a15..3a92021929d 100644 --- a/src/google/adk/sessions/_session_util.py +++ b/src/google/adk/sessions/_session_util.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Utility functions for session service.""" + from __future__ import annotations from typing import Any diff --git a/src/google/adk/sessions/database_session_service.py b/src/google/adk/sessions/database_session_service.py index 84977294caf..3539f9acddb 100644 --- a/src/google/adk/sessions/database_session_service.py +++ b/src/google/adk/sessions/database_session_service.py @@ -436,8 +436,8 @@ async def append_event(self, session: Session, event: Event) -> Event: if storage_session.update_timestamp_tz > session.last_update_time: raise ValueError( "The last_update_time provided in the session object" - f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'} is" - " earlier than the update_time in the storage_session" + f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'}" + " is earlier than the update_time in the storage_session" f" {datetime.fromtimestamp(storage_session.update_timestamp_tz):'%Y-%m-%d %H:%M:%S'}." " Please check if it is a stale session." ) diff --git a/src/google/adk/sessions/migration/migration_runner.py b/src/google/adk/sessions/migration/migration_runner.py index 56acd810fbd..346e15978c9 100644 --- a/src/google/adk/sessions/migration/migration_runner.py +++ b/src/google/adk/sessions/migration/migration_runner.py @@ -13,6 +13,7 @@ # limitations under the License. """Migration runner to upgrade schemas to the latest version.""" + from __future__ import annotations import logging diff --git a/src/google/adk/tools/application_integration_tool/clients/connections_client.py b/src/google/adk/tools/application_integration_tool/clients/connections_client.py index 1756d5b0529..9e518a8740e 100644 --- a/src/google/adk/tools/application_integration_tool/clients/connections_client.py +++ b/src/google/adk/tools/application_integration_tool/clients/connections_client.py @@ -324,7 +324,9 @@ def get_action_operation( "content": { "application/json": { "schema": { - "$ref": f"#/components/schemas/{action_display_name}_Request" + "$ref": ( + f"#/components/schemas/{action_display_name}_Request" + ) } } } @@ -335,7 +337,9 @@ def get_action_operation( "content": { "application/json": { "schema": { - "$ref": f"#/components/schemas/{action_display_name}_Response", + "$ref": ( + f"#/components/schemas/{action_display_name}_Response" + ), } } }, @@ -354,9 +358,11 @@ def list_operation( return { "post": { "summary": f"List {entity}", - "description": f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the + "description": ( + f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the following format: `field_name1='value1' AND field_name2='value2' - `. {tool_instructions}""", + `. {tool_instructions}""" + ), "x-operation": "LIST_ENTITIES", "x-entity": f"{entity}", "operationId": f"{tool_name}_list_{entity}", @@ -381,7 +387,9 @@ def list_operation( f"Returns a list of {entity} of json" f" schema: {schema_as_string}" ), - "$ref": "#/components/schemas/execute-connector_Response", + "$ref": ( + "#/components/schemas/execute-connector_Response" + ), } } }, @@ -425,7 +433,9 @@ def get_operation( f"Returns {entity} of json schema:" f" {schema_as_string}" ), - "$ref": "#/components/schemas/execute-connector_Response", + "$ref": ( + "#/components/schemas/execute-connector_Response" + ), } } }, @@ -462,7 +472,9 @@ def create_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, @@ -499,7 +511,9 @@ def update_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, @@ -536,7 +550,9 @@ def delete_operation( "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/execute-connector_Response" + "$ref": ( + "#/components/schemas/execute-connector_Response" + ) } } }, diff --git a/src/google/adk/tools/bigtable/metadata_tool.py b/src/google/adk/tools/bigtable/metadata_tool.py index 97c8991a2c9..703c3447403 100644 --- a/src/google/adk/tools/bigtable/metadata_tool.py +++ b/src/google/adk/tools/bigtable/metadata_tool.py @@ -35,7 +35,7 @@ def list_instances(project_id: str, credentials: Credentials) -> dict: bt_client = client.get_bigtable_admin_client( project=project_id, credentials=credentials ) - (instances_list, failed_locations_list) = bt_client.list_instances() + instances_list, failed_locations_list = bt_client.list_instances() if failed_locations_list: logging.warning( "Failed to list instances from the following locations: %s", diff --git a/src/google/adk/tools/mcp_tool/mcp_tool.py b/src/google/adk/tools/mcp_tool/mcp_tool.py index a5b598fd81f..fe1c745803e 100644 --- a/src/google/adk/tools/mcp_tool/mcp_tool.py +++ b/src/google/adk/tools/mcp_tool/mcp_tool.py @@ -261,7 +261,8 @@ async def _get_headers( # Handle other HTTP schemes with token headers = { "Authorization": ( - f"{credential.http.scheme} {credential.http.credentials.token}" + f"{credential.http.scheme}" + f" {credential.http.credentials.token}" ) } elif credential.api_key: diff --git a/tests/unittests/agents/test_llm_agent_error_messages.py b/tests/unittests/agents/test_llm_agent_error_messages.py index 735d3866f2a..2d219a2ead5 100644 --- a/tests/unittests/agents/test_llm_agent_error_messages.py +++ b/tests/unittests/agents/test_llm_agent_error_messages.py @@ -13,6 +13,7 @@ # limitations under the License. """Tests for enhanced error messages in agent handling.""" + from google.adk.agents import LlmAgent import pytest diff --git a/tests/unittests/agents/test_mcp_instruction_provider.py b/tests/unittests/agents/test_mcp_instruction_provider.py index 9f10477eac4..f7952a92c49 100644 --- a/tests/unittests/agents/test_mcp_instruction_provider.py +++ b/tests/unittests/agents/test_mcp_instruction_provider.py @@ -13,6 +13,7 @@ # limitations under the License. """Unit tests for McpInstructionProvider.""" + from unittest.mock import AsyncMock from unittest.mock import MagicMock from unittest.mock import patch diff --git a/tests/unittests/cli/utils/test_cli_create.py b/tests/unittests/cli/utils/test_cli_create.py index 18a732ef6ec..0d76ab8a540 100644 --- a/tests/unittests/cli/utils/test_cli_create.py +++ b/tests/unittests/cli/utils/test_cli_create.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_create.""" - from __future__ import annotations import os diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index 43b9e07a2e1..63435976551 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_deploy.""" - from __future__ import annotations import importlib diff --git a/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py b/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py index 017c4a4dce6..eae87889e69 100644 --- a/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py +++ b/tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py @@ -14,7 +14,6 @@ """Tests for to_cloud_run functionality in cli_deploy.""" - from __future__ import annotations from pathlib import Path diff --git a/tests/unittests/cli/utils/test_cli_tools_click.py b/tests/unittests/cli/utils/test_cli_tools_click.py index 5977f90dd7c..7646bc87772 100644 --- a/tests/unittests/cli/utils/test_cli_tools_click.py +++ b/tests/unittests/cli/utils/test_cli_tools_click.py @@ -14,7 +14,6 @@ """Tests for utilities in cli_tool_click.""" - from __future__ import annotations import builtins diff --git a/tests/unittests/evaluation/test_evaluation_generator.py b/tests/unittests/evaluation/test_evaluation_generator.py index 0a148745ebd..29ac75ffb55 100644 --- a/tests/unittests/evaluation/test_evaluation_generator.py +++ b/tests/unittests/evaluation/test_evaluation_generator.py @@ -353,8 +353,10 @@ async def mock_run_async(*args, **kwargs): events = [ event - async for event in EvaluationGenerator._generate_inferences_for_single_user_invocation( - runner, "test_user", "test_session", user_content + async for event in ( + EvaluationGenerator._generate_inferences_for_single_user_invocation( + runner, "test_user", "test_session", user_content + ) ) ] diff --git a/tests/unittests/evaluation/test_trajectory_evaluator.py b/tests/unittests/evaluation/test_trajectory_evaluator.py index af26903b648..0fa3fa5a739 100644 --- a/tests/unittests/evaluation/test_trajectory_evaluator.py +++ b/tests/unittests/evaluation/test_trajectory_evaluator.py @@ -14,7 +14,6 @@ """Testings for the Trajectory Evaluator.""" - from google.adk.evaluation.eval_case import IntermediateData from google.adk.evaluation.eval_case import Invocation from google.adk.evaluation.eval_metrics import EvalMetric diff --git a/tests/unittests/flows/llm_flows/test_functions_error_messages.py b/tests/unittests/flows/llm_flows/test_functions_error_messages.py index 1db5515b81f..84e6e93b2ef 100644 --- a/tests/unittests/flows/llm_flows/test_functions_error_messages.py +++ b/tests/unittests/flows/llm_flows/test_functions_error_messages.py @@ -13,6 +13,7 @@ # limitations under the License. """Tests for enhanced error messages in function tool handling.""" + from google.adk.flows.llm_flows.functions import _get_tool from google.adk.tools import BaseTool from google.genai import types diff --git a/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py b/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py index 621ebc1bad6..ce20b733608 100644 --- a/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +++ b/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py @@ -470,7 +470,9 @@ def test_get_spec_content_no_specs(self, mock_get, client): MagicMock( status_code=200, json=lambda: { - "name": "projects/test-project/locations/us-central1/apis/api1/versions/v1", + "name": ( + "projects/test-project/locations/us-central1/apis/api1/versions/v1" + ), "specs": [], }, ), # No specs diff --git a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py index f45ba84c5a1..e5bff337cec 100644 --- a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +++ b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py @@ -371,7 +371,9 @@ def test_parse_external_ref_raises_error(openapi_spec_generator): "content": { "application/json": { "schema": { - "$ref": "external_file.json#/components/schemas/ExternalSchema" + "$ref": ( + "external_file.json#/components/schemas/ExternalSchema" + ) } } }, diff --git a/tests/unittests/tools/test_function_tool.py b/tests/unittests/tools/test_function_tool.py index 40e7e2673cc..9b1d1abd113 100644 --- a/tests/unittests/tools/test_function_tool.py +++ b/tests/unittests/tools/test_function_tool.py @@ -200,9 +200,11 @@ async def test_run_async_1_missing_arg_sync_func(): args = {"arg1": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg2 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -213,9 +215,11 @@ async def test_run_async_1_missing_arg_async_func(): args = {"arg2": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_2_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -226,11 +230,13 @@ async def test_run_async_3_missing_arg_sync_func(): args = {"arg2": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -241,11 +247,13 @@ async def test_run_async_3_missing_arg_async_func(): args = {"arg3": "test_value_1"} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -256,12 +264,14 @@ async def test_run_async_missing_all_arg_sync_func(): args = {} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } @@ -272,12 +282,14 @@ async def test_run_async_missing_all_arg_async_func(): args = {} result = await tool.run_async(args=args, tool_context=MagicMock()) assert result == { - "error": """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: + "error": ( + """Invoking `async_function_for_testing_with_4_arg_and_no_tool_context()` failed as the following mandatory input parameters are not present: arg1 arg2 arg3 arg4 You could retry calling this tool, but it is IMPORTANT for you to provide all the mandatory parameters.""" + ) } diff --git a/tests/unittests/tools/test_set_model_response_tool.py b/tests/unittests/tools/test_set_model_response_tool.py index cc18ecf5d8d..75fd40e9676 100644 --- a/tests/unittests/tools/test_set_model_response_tool.py +++ b/tests/unittests/tools/test_set_model_response_tool.py @@ -14,7 +14,6 @@ """Tests for SetModelResponseTool.""" - from google.adk.agents.invocation_context import InvocationContext from google.adk.agents.llm_agent import LlmAgent from google.adk.agents.run_config import RunConfig