From 1e6c85e837ca2dc407ba1a87868d13c0ea9954b1 Mon Sep 17 00:00:00 2001 From: Yingying Gu Date: Sat, 17 Jan 2026 23:39:58 -0500 Subject: [PATCH 1/4] feat: add state_delta - optional state changes to apply to the session --- src/google/adk/runners.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index 64343302fe0..508c00d73d2 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -926,6 +926,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). @@ -966,6 +967,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. @@ -1009,6 +1011,16 @@ 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) From f2b99acad719209e9f4e65d92a2101930e5046cc Mon Sep 17 00:00:00 2001 From: Yingying Gu Date: Sun, 18 Jan 2026 00:53:21 -0500 Subject: [PATCH 2/4] add unit tests for state_delta in run_live --- tests/unittests/test_runners.py | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/unittests/test_runners.py b/tests/unittests/test_runners.py index c876bff53a0..a5f5833d748 100644 --- a/tests/unittests/test_runners.py +++ b/tests/unittests/test_runners.py @@ -442,6 +442,50 @@ 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" From a892e4345c8f7d089022d00daa0bf65dd8de5b12 Mon Sep 17 00:00:00 2001 From: Yingying Gu Date: Thu, 22 Jan 2026 18:34:35 -0500 Subject: [PATCH 3/4] autoformat update --- 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 +-- 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/runners.py | 4 ++- 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 +- .../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 + tests/unittests/test_runners.py | 3 +- .../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 - 55 files changed, 131 insertions(+), 56 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 c65df3cf1d2..32a5d19ed07 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 2f5d03a7728..f68b349d9c6 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 cfd850b3a30..1bc4ee58c8d 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 beb78b96434..f531f2d15b7 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 2e664b73df7..6c9ddf8156a 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 e83bc40b2fe..f71afa8e130 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 a4ed704e964..099fb65372c 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 efe17d409c2..01ad10d60fa 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 2845498946a..780830be888 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 f1f9c57f741..4150d515c41 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 2bf713a5e8f..724bbd1aa17 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 80b07a8096a..05f75876b6b 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 810f838f3e7..92acce142a0 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 51a6bbf73ed..afa7eed1092 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 c0e2aaf9208..047f8cdd90b 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 845d8a5a582..205fabd0efd 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 86005cd6258..41b070e8c5c 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 d68046ba514..7a419dbba63 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 0df5c6308a2..a3736e030e2 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 d1b71e07aab..991386eac04 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 8c077877b1b..be1a5a9670e 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 c36277537dd..9c71bbe7235 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 6719712260b..b18cca364ed 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 a63b7d11084..ea160ff683f 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 a787689a966..111e606df49 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 8ade17c5361..9e20320dcdd 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 ea4e35fe3da..5b0f86797db 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 bf3a75ae0f6..73e4916ab74 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 6d151eda882..498e2c0c8fd 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 12207e8070f..5e21e658403 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 75a7b789876..59ead8a347b 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 488d9944fa9..3e367f35150 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 f5d74c899c0..994e76adec8 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 7e8a51bdced..31159cb80b4 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 508c00d73d2..9a41866f35d 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -1019,7 +1019,9 @@ async def run_live( 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) + 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 0b2f99eef2f..0e817581fa8 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 863bbfa8614..8b7bda6d2a6 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 0a3a45f676e..56e05457417 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 2bf3982a2a5..57022af7181 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 e89c0b8d602..3a0f8d33e93 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/tests/unittests/agents/test_llm_agent_error_messages.py b/tests/unittests/agents/test_llm_agent_error_messages.py index 1b6f135e128..1502d13faee 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 256d8126306..04a92552487 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 f6e82745558..b710f887843 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 dad93583dfe..d4a8237eeae 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 51367d2b844..4cf39392596 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 316ffbb6af3..4f9d483381e 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 873239e7f46..013303ee719 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 47854ca6a52..476535bb94a 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 44b563b6c78..9d9d70ca83c 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 a5f5833d748..a76b336bc00 100644 --- a/tests/unittests/test_runners.py +++ b/tests/unittests/test_runners.py @@ -479,8 +479,7 @@ async def test_run_live_state_delta_applied_to_session(): # 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" + 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 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 7d00e3d0a5c..a4683628f87 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 3f60d0ba665..495ea266c5a 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 78610d330d0..ad060fc636d 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 ca768a9e7ff..406c1276d93 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 bbf6378beb6a48129c89a1a11f1ff5209303a26f Mon Sep 17 00:00:00 2001 From: yingyinggu-dev Date: Thu, 22 Jan 2026 19:32:53 -0500 Subject: [PATCH 4/4] updates --- src/google/adk/tools/mcp_tool/mcp_tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: