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/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/runners.py b/src/google/adk/runners.py index 3aaa54e257..0de8fc17c8 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -927,6 +927,7 @@ async def run_live( session_id: Optional[str] = None, live_request_queue: LiveRequestQueue, run_config: Optional[RunConfig] = None, + state_delta: Optional[dict[str, Any]] = None, session: Optional[Session] = None, ) -> AsyncGenerator[Event, None]: """Runs the agent in live mode (experimental feature). @@ -967,6 +968,7 @@ async def run_live( None. live_request_queue: The queue for live requests. run_config: The run config for the agent. + state_delta: Optional state changes to apply to the session. session: The session to use. This parameter is deprecated, please use `user_id` and `session_id` instead. @@ -1010,6 +1012,18 @@ async def run_live( run_config=run_config, ) + # Apply state_delta if provided + if state_delta: + state_event = Event( + invocation_id=invocation_context.invocation_id, + author='user', + actions=EventActions(state_delta=state_delta), + ) + _apply_run_config_custom_metadata(state_event, run_config) + await self.session_service.append_event( + session=session, event=state_event + ) + root_agent = self.agent invocation_context.agent = self._find_agent_to_run(session, root_agent) 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/database_session_service.py b/src/google/adk/sessions/database_session_service.py index 84977294ca..3539f9acdd 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 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 43b9e07a2e..6343597655 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/test_runners.py b/tests/unittests/test_runners.py index 62b8d7334b..2bbe0d44c8 100644 --- a/tests/unittests/test_runners.py +++ b/tests/unittests/test_runners.py @@ -442,6 +442,49 @@ async def _run_live_impl( assert "non_streaming_tool" not in active_tools +@pytest.mark.asyncio +async def test_run_live_state_delta_applied_to_session(): + """run_live should apply state_delta to the session at the start.""" + session_service = InMemorySessionService() + artifact_service = InMemoryArtifactService() + runner = Runner( + app_name="run_live_app", + agent=MockLiveAgent("live_agent"), + session_service=session_service, + artifact_service=artifact_service, + auto_create_session=True, + ) + + live_queue = LiveRequestQueue() + state_delta = {"useCase": "voice_assistant"} + + agen = runner.run_live( + user_id="user", + session_id="test_session", + live_request_queue=live_queue, + state_delta=state_delta, + ) + + event = await agen.__anext__() + await agen.aclose() + + assert event.author == "live_agent" + + # Verify state_delta was applied to the session + session = await session_service.get_session( + app_name="run_live_app", user_id="user", session_id="test_session" + ) + assert session is not None + assert session.state.get("useCase") == "voice_assistant" + + # Verify the state_delta event was appended to the session + state_delta_events = [ + e for e in session.events if e.actions.state_delta and e.author == "user" + ] + assert len(state_delta_events) == 1 + assert state_delta_events[0].actions.state_delta == state_delta + + @pytest.mark.asyncio async def test_runner_allows_nested_agent_directories(tmp_path, monkeypatch): project_root = tmp_path / "workspace" 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