diff --git a/contributing/dev/utils/build_llms_txt.py b/contributing/dev/utils/build_llms_txt.py index 5fff1d6a3a..81ea171e89 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 d163e09363..dae4aca532 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 f3751206a8..2710c3894c 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 d857da9635..e31db15788 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 cd6b021241..64dd95ef92 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 3103da9147..c7ad041b23 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 a055edf3a5..0c3b0e63d3 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 478d5065d8..6c03de8e90 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 6715a29a0c..fcf70b51b6 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 e9025992ad..b8a3164f13 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 17989374d6..0bc457a6e7 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 StreamingMode from ...runners import RunConfig from ..experimental import a2a_experimental from .part_converter import A2APartToGenAIPartConverter @@ -50,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. @@ -78,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. @@ -113,5 +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 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. + """ + + def converter( + 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 diff --git a/src/google/adk/a2a/utils/agent_to_a2a.py b/src/google/adk/a2a/utils/agent_to_a2a.py index 155888bcab..dc9c63a3c3 100644 --- a/src/google/adk/a2a/utils/agent_to_a2a.py +++ b/src/google/adk/a2a/utils/agent_to_a2a.py @@ -25,12 +25,15 @@ from starlette.applications import Starlette 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 @@ -79,6 +82,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 +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) Returns: A Starlette application that can be run with uvicorn @@ -123,8 +128,13 @@ async def create_runner() -> Runner: # Create A2A components task_store = InMemoryTaskStore() + executor_config = A2aAgentExecutorConfig( + request_converter=create_request_converter(streaming_mode=streaming_mode) + ) + agent_executor = A2aAgentExecutor( runner=runner or create_runner, + config=executor_config, ) request_handler = DefaultRequestHandler( diff --git a/src/google/adk/agents/common_configs.py b/src/google/adk/agents/common_configs.py index 1b3c00a8d2..4e4c49f34d 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 d86927dc9c..4108cfb06b 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 699a579fba..e9dbb47cef 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 c3cb983955..8d7ddadbb3 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 a95c50d939..7a541fc5ac 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 8525d832de..a854a50b77 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 ae6c29c115..0e6fbc7d10 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 98c5ead73f..8ef8472d51 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 d3c78339d7..6b8fe1d613 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 6ed7875655..1f6986653c 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 3d029e8210..694f7fff75 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 ad058d9e3c..67691c9c24 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 d81d4113f4..ca71b2f0c7 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 9498dc2402..1878d31b87 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 feb9bbe7fa..c111db3cdd 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 2921aadbc5..2fd040580d 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 04b542b06c..ed6a85c366 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 5f031485e9..277e168dad 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 8b54c5c765..8f0eb98750 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 ef50db6ecd..ca7398733f 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 511dfe3d17..faa3eaec02 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 c31038ca7c..e988454d5a 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 332971c0aa..c02f5cff73 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 34cfc9cef6..e7e276089f 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 60dc75439d..20fe3dc391 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 080f0694a1..3a92021929 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/migration/migration_runner.py b/src/google/adk/sessions/migration/migration_runner.py index edb5c83bcb..c46bab2179 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 1756d5b052..9e518a8740 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 97c8991a2c..703c344740 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 a5b598fd81..fe1c745803 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 735d3866f2..2d219a2ead 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 9f10477eac..f7952a92c4 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 18a732ef6e..0d76ab8a54 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 36484da149..30bf1b5a9d 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 017c4a4dce..eae87889e6 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 5977f90dd7..7646bc8777 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 0a148745eb..29ac75ffb5 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 af26903b64..0fa3fa5a73 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 1db5515b81..84e6e93b2e 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 621ebc1bad..ce20b73360 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 f45ba84c5a..e5bff337ce 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 40e7e2673c..9b1d1abd11 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 cc18ecf5d8..75fd40e967 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