6464 _BUILTIN_MODULE_NAMES : Sequence [str ] = [] # type: ignore[no-redef]
6565
6666try :
67- _PACKAGE_DISTRIBUTIONS : Mapping [
68- str , Sequence [ str ]
69- ] = importlib_metadata . packages_distributions () # type: ignore[attr-defined]
67+ _PACKAGE_DISTRIBUTIONS : Mapping [str , Sequence [ str ]] = (
68+ importlib_metadata . packages_distributions ()
69+ )
7070except AttributeError :
7171 _PACKAGE_DISTRIBUTIONS : Mapping [str , Sequence [str ]] = {} # type: ignore[no-redef]
7272
7373try :
7474 # sys.stdlib_module_names is available from Python 3.10 onwards.
75- _STDLIB_MODULE_NAMES : frozenset [str ] = sys .stdlib_module_names # type: ignore[attr-defined]
75+ _STDLIB_MODULE_NAMES : frozenset [str ] = sys .stdlib_module_names
7676except AttributeError :
7777 _STDLIB_MODULE_NAMES : frozenset [str ] = frozenset () # type: ignore[no-redef]
7878
7979
8080try :
81- from google .cloud import storage # type: ignore[attr-defined]
81+ from google .cloud import storage
8282
83- _StorageBucket : type [Any ] = storage .Bucket
83+ _StorageBucket : type [Any ] = storage .Bucket # type: ignore[attr-defined]
8484except (ImportError , AttributeError ):
8585 _StorageBucket : type [Any ] = Any # type: ignore[no-redef]
8686
9090
9191 _SpecifierSet : type [Any ] = packaging .specifiers .SpecifierSet
9292except (ImportError , AttributeError ):
93- _SpecifierSet : type [Any ] = Any
93+ _SpecifierSet : type [Any ] = Any # type: ignore[no-redef]
9494
9595
9696try :
125125_ASYNC_API_MODE = "async"
126126_ASYNC_STREAM_API_MODE = "async_stream"
127127_BIDI_STREAM_API_MODE = "bidi_stream"
128- _BASE_MODULES = set (_BUILTIN_MODULE_NAMES + tuple (_STDLIB_MODULE_NAMES ) )
128+ _BASE_MODULES = set (_BUILTIN_MODULE_NAMES ). union (_STDLIB_MODULE_NAMES )
129129_BLOB_FILENAME = "agent_engine.pkl"
130130_DEFAULT_AGENT_FRAMEWORK = "custom"
131131_SUPPORTED_AGENT_FRAMEWORKS = frozenset (
@@ -237,7 +237,9 @@ class BidiStreamQueryable(Protocol):
237237 """Protocol for Agent Engines that can stream requests and responses."""
238238
239239 @abc .abstractmethod
240- async def bidi_stream_query (self , input_queue : asyncio .Queue ) -> AsyncIterator [Any ]:
240+ async def bidi_stream_query (
241+ self , input_queue : asyncio .Queue [Any ]
242+ ) -> AsyncIterator [Any ]:
241243 """Stream requests and responses to serve the user queries."""
242244
243245
@@ -255,7 +257,7 @@ class OperationRegistrable(Protocol):
255257 """Protocol for agents that have registered operations."""
256258
257259 @abc .abstractmethod
258- def register_operations (self , ** kwargs ) -> Dict [str , Sequence [str ]]:
260+ def register_operations (self , ** kwargs ) -> Dict [str , Sequence [str ]]: # type: ignore[no-untyped-def]
259261 """Register the user provided operations (modes and methods)."""
260262
261263
@@ -264,7 +266,7 @@ def register_operations(self, **kwargs) -> Dict[str, Sequence[str]]:
264266
265267 ADKAgent : type [Any ] = BaseAgent
266268except (ImportError , AttributeError ):
267- ADKAgent : type [Any ] = Any
269+ ADKAgent : type [Any ] = Any # type: ignore[no-redef]
268270
269271_AgentEngineInterface = Union [
270272 ADKAgent ,
@@ -399,13 +401,15 @@ class _RequirementsValidationResult(TypedDict):
399401
400402
401403class GetOperationFunction (Protocol ):
402- def __call__ (self , * , operation_name : str , ** kwargs ) -> AgentEngineOperationUnion :
404+ def __call__ (
405+ self , * , operation_name : str , ** kwargs : Any
406+ ) -> AgentEngineOperationUnion :
403407 pass
404408
405409
406410class GetAsyncOperationFunction (Protocol ):
407411 async def __call__ (
408- self , * , operation_name : str , ** kwargs
412+ self , * , operation_name : str , ** kwargs : Any
409413 ) -> Awaitable [AgentEngineOperationUnion ]:
410414 pass
411415
@@ -727,7 +731,7 @@ def _get_agent_framework(
727731 * ,
728732 agent_framework : Optional [str ],
729733 agent : _AgentEngineInterface ,
730- ) -> str :
734+ ) -> Union [ str , Any ] :
731735 """Gets the agent framework to use.
732736
733737 The agent framework is determined in the following order of priority:
@@ -820,13 +824,13 @@ def _import_cloudpickle_or_raise() -> types.ModuleType:
820824def _import_cloud_storage_or_raise () -> types .ModuleType :
821825 """Tries to import the Cloud Storage module."""
822826 try :
823- from google .cloud import storage # type: ignore[attr-defined]
827+ from google .cloud import storage
824828 except ImportError as e :
825829 raise ImportError (
826830 "Cloud Storage is not installed. Please call "
827831 "'pip install google-cloud-aiplatform[agent_engines]'."
828832 ) from e
829- return storage # type: ignore[no-any-return]
833+ return storage
830834
831835
832836def _import_packaging_requirements_or_raise () -> types .ModuleType :
@@ -838,7 +842,7 @@ def _import_packaging_requirements_or_raise() -> types.ModuleType:
838842 "packaging.requirements is not installed. Please call "
839843 "'pip install google-cloud-aiplatform[agent_engines]'."
840844 ) from e
841- return requirements # type: ignore[no-any-return]
845+ return requirements
842846
843847
844848def _import_packaging_version_or_raise () -> types .ModuleType :
@@ -850,7 +854,7 @@ def _import_packaging_version_or_raise() -> types.ModuleType:
850854 "packaging.version is not installed. Please call "
851855 "'pip install google-cloud-aiplatform[agent_engines]'."
852856 ) from e
853- return version # type: ignore[no-any-return]
857+ return version
854858
855859
856860def _import_pydantic_or_raise () -> types .ModuleType :
@@ -866,7 +870,7 @@ def _import_pydantic_or_raise() -> types.ModuleType:
866870 "pydantic is not installed. Please call "
867871 "'pip install google-cloud-aiplatform[agent_engines]'."
868872 ) from e
869- return pydantic # type: ignore[no-any-return]
873+ return pydantic
870874
871875
872876def _parse_constraints (
@@ -1022,7 +1026,7 @@ def _register_api_methods_or_raise(
10221026 }
10231027 if isinstance (wrap_operation_fn , dict ) and api_mode in wrap_operation_fn :
10241028 # Override the default function with user-specified function if it exists.
1025- _wrap_operation = wrap_operation_fn [api_mode ] # type: ignore[assignment]
1029+ _wrap_operation = wrap_operation_fn [api_mode ]
10261030 elif api_mode in _wrap_operation_map :
10271031 _wrap_operation = _wrap_operation_map [api_mode ] # type: ignore[assignment]
10281032 else :
@@ -1531,7 +1535,7 @@ def _method(self, **kwargs) -> Any: # type: ignore[no-untyped-def]
15311535
15321536class GetOperationFunction (Protocol ):
15331537 def __call__ ( # noqa: E704
1534- self , * , operation_name : str , ** kwargs
1538+ self , * , operation_name : str , ** kwargs : Any
15351539 ) -> AgentEngineOperationUnion : ...
15361540
15371541
@@ -1588,8 +1592,8 @@ def _wrap_async_query_operation(
15881592 """
15891593
15901594 async def _method (
1591- self : genai_types .AgentEngine , ** kwargs
1592- ) -> Coroutine [Any , Any , Any ]: # type: ignore[no-untyped-def]
1595+ self : genai_types .AgentEngine , ** kwargs : Any
1596+ ) -> Union [ Coroutine [Any , Any , Any ], Any ]:
15931597 if not self .api_async_client :
15941598 raise ValueError ("api_async_client is not initialized." )
15951599 if not self .api_resource :
@@ -1681,7 +1685,7 @@ async def _method(self: genai_types.AgentEngine, **kwargs) -> AsyncIterator[Any]
16811685 return _method
16821686
16831687
1684- def _wrap_a2a_operation (method_name : str , agent_card : str ) -> Callable [..., list ]:
1688+ def _wrap_a2a_operation (method_name : str , agent_card : str ) -> Callable [..., list [ Any ] ]:
16851689 """Wraps an Agent Engine method, creating a callable for A2A API.
16861690
16871691 Args:
@@ -1727,7 +1731,7 @@ def _wrap_a2a_operation(method_name: str, agent_card: str) -> Callable[..., list
17271731 the A2A API.
17281732 """
17291733
1730- async def _method (self , ** kwargs ) -> Any :
1734+ async def _method (self , ** kwargs ) -> Any : # type: ignore[no-untyped-def]
17311735 """Wraps an Agent Engine method, creating a callable for A2A API."""
17321736 if not self .api_client :
17331737 raise ValueError ("api_client is not initialized." )
0 commit comments