1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414#
15- """Utility functions for agent engines ."""
15+ """Utility functions for runtimes ."""
1616
1717import abc
1818import asyncio
5353
5454from google .api_core import exceptions
5555from google .genai import types as google_genai_types
56- from google .api import httpbody_pb2
5756from google .protobuf import struct_pb2
5857from google .protobuf import json_format
5958
@@ -312,7 +311,7 @@ def register_operations(self, **kwargs: Any) -> dict[str, list[str]]:
312311 except (ImportError , AttributeError ):
313312 ADKAgent = None # type: ignore[no-redef]
314313
315- _AgentEngineInterface = Union [
314+ _RuntimeInterface = Union [
316315 ADKAgent ,
317316 AsyncQueryable ,
318317 AsyncStreamQueryable ,
@@ -328,7 +327,7 @@ class _ModuleAgentAttributes(TypedDict, total=False):
328327 agent_name : str
329328 register_operations : Dict [str , list [str ]]
330329 sys_paths : Optional [Sequence [str ]]
331- agent : _AgentEngineInterface
330+ agent : _RuntimeInterface
332331
333332
334333class ModuleAgent (Cloneable , OperationRegistrable ):
@@ -441,24 +440,24 @@ class _RequirementsValidationResult(TypedDict):
441440 actions : _RequirementsValidationActions
442441
443442
444- AgentEngineOperationUnion = Union [
445- genai_types .AgentEngineOperation ,
446- genai_types .AgentEngineMemoryOperation ,
447- genai_types .AgentEngineGenerateMemoriesOperation ,
443+ RuntimeOperationUnion = Union [
444+ genai_types .RuntimeOperation ,
445+ genai_types .RuntimeMemoryOperation ,
446+ genai_types .RuntimeGenerateMemoriesOperation ,
448447]
449448
450449
451450class GetOperationFunction (Protocol ):
452451 def __call__ (
453452 self , * , operation_name : str , ** kwargs : Any
454- ) -> AgentEngineOperationUnion :
453+ ) -> RuntimeOperationUnion :
455454 pass
456455
457456
458457class GetAsyncOperationFunction (Protocol ):
459458 async def __call__ (
460459 self , * , operation_name : str , ** kwargs : Any
461- ) -> AgentEngineOperationUnion :
460+ ) -> RuntimeOperationUnion :
462461 pass
463462
464463
@@ -611,7 +610,7 @@ def _compare_requirements(
611610
612611def _generate_class_methods_spec_or_raise (
613612 * ,
614- agent : _AgentEngineInterface ,
613+ agent : _RuntimeInterface ,
615614 operations : Dict [str , List [str ]],
616615) -> List [proto .Message ]:
617616 """Generates a ReasoningEngineSpec based on the registered operations.
@@ -811,7 +810,7 @@ def _generate_schema(
811810def _get_agent_framework (
812811 * ,
813812 agent_framework : Optional [str ],
814- agent : _AgentEngineInterface ,
813+ agent : _RuntimeInterface ,
815814) -> Union [str , Any ]:
816815 """Gets the agent framework to use.
817816
@@ -823,7 +822,7 @@ def _get_agent_framework(
823822 Args:
824823 agent_framework (str):
825824 The agent framework provided by the user.
826- agent (_AgentEngineInterface ):
825+ agent (_RuntimeInterface ):
827826 The agent engine instance.
828827
829828 Returns:
@@ -871,7 +870,7 @@ def _get_gcs_bucket(
871870
872871def _get_registered_operations (
873872 * ,
874- agent : _AgentEngineInterface ,
873+ agent : _RuntimeInterface ,
875874) -> dict [str , list [str ]]:
876875 """Retrieves registered operations for a AgentEngine."""
877876 if isinstance (agent , OperationRegistrable ):
@@ -985,7 +984,7 @@ def _parse_constraints(
985984
986985def _prepare (
987986 * ,
988- agent : Optional [_AgentEngineInterface ],
987+ agent : Optional [_RuntimeInterface ],
989988 requirements : Optional [Sequence [str ]],
990989 extra_packages : Optional [Sequence [str ]],
991990 project : str ,
@@ -1042,7 +1041,7 @@ def _prepare(
10421041
10431042def _register_api_methods_or_raise (
10441043 * ,
1045- agent_engine : genai_types .AgentEngine | genai_types .AgentEngineRuntimeRevision ,
1044+ agent_engine : genai_types .Runtime | genai_types .RuntimeRevision ,
10461045 wrap_operation_fn : Optional [
10471046 dict [str , Callable [[str , str ], Callable [..., Any ]]]
10481047 ] = None ,
@@ -1243,7 +1242,7 @@ def _to_proto(
12431242
12441243def _upload_agent_engine (
12451244 * ,
1246- agent : _AgentEngineInterface ,
1245+ agent : _RuntimeInterface ,
12471246 gcs_bucket : _StorageBucket ,
12481247 gcs_dir_name : str ,
12491248) -> None :
@@ -1412,7 +1411,7 @@ def _validate_staging_bucket_or_raise(*, staging_bucket: str) -> str:
14121411 """Tries to validate the staging bucket."""
14131412 if not staging_bucket :
14141413 raise ValueError (
1415- "Please provide a `staging_bucket` in `client.agent_engines .create(...)`."
1414+ "Please provide a `staging_bucket` in `client.runtimes .create(...)`."
14161415 )
14171416 if not staging_bucket .startswith ("gs://" ):
14181417 raise ValueError (f"{ staging_bucket = } must start with `gs://`" )
@@ -1475,8 +1474,8 @@ def _validate_requirements_or_raise(
14751474
14761475def _validate_agent_or_raise (
14771476 * ,
1478- agent : _AgentEngineInterface ,
1479- ) -> _AgentEngineInterface :
1477+ agent : _RuntimeInterface ,
1478+ ) -> _RuntimeInterface :
14801479 """Tries to validate the agent engine.
14811480
14821481 The agent engine must have one of the following:
@@ -1503,9 +1502,9 @@ def _validate_agent_or_raise(
15031502
15041503 if isinstance (agent , BaseAgent ):
15051504 logger .info ("Deploying google.adk.agents.Agent as an application." )
1506- from agentplatform import agent_engines
1505+ from agentplatform import frameworks
15071506
1508- agent = agent_engines .AdkApp (agent = agent )
1507+ agent = frameworks .AdkApp (agent = agent )
15091508 except Exception :
15101509 pass
15111510 is_queryable = isinstance (agent , Queryable ) and callable (agent .query )
@@ -1640,7 +1639,7 @@ def _wrap_query_operation(*, method_name: str) -> Callable[..., Any]:
16401639 the `query` API.
16411640 """
16421641
1643- def _method (self : genai_types .AgentEngine , ** kwargs ) -> Any : # type: ignore[no-untyped-def]
1642+ def _method (self : genai_types .Runtime , ** kwargs ) -> Any : # type: ignore[no-untyped-def]
16441643 if not self .api_client :
16451644 raise ValueError ("api_client is not initialized." )
16461645 if not self .api_resource :
@@ -1683,7 +1682,7 @@ def _wrap_async_query_operation(
16831682 """
16841683
16851684 async def _method (
1686- self : genai_types .AgentEngine , ** kwargs : Any
1685+ self : genai_types .Runtime , ** kwargs : Any
16871686 ) -> Union [Coroutine [Any , Any , Any ], Any ]:
16881687 if not self .api_async_client :
16891688 raise ValueError ("api_async_client is not initialized." )
@@ -1724,7 +1723,7 @@ def _wrap_stream_query_operation(*, method_name: str) -> Callable[..., Iterator[
17241723 the `stream_query` API.
17251724 """
17261725
1727- def _method (self : genai_types .AgentEngine , ** kwargs ) -> Iterator [Any ]: # type: ignore[no-untyped-def]
1726+ def _method (self : genai_types .Runtime , ** kwargs ) -> Iterator [Any ]: # type: ignore[no-untyped-def]
17281727 if not self .api_client :
17291728 raise ValueError ("api_client is not initialized." )
17301729 if not self .api_resource :
@@ -1768,7 +1767,7 @@ def _wrap_async_stream_query_operation(
17681767 the `stream_query` API.
17691768 """
17701769
1771- async def _method (self : genai_types .AgentEngine , ** kwargs ) -> AsyncIterator [Any ]: # type: ignore[no-untyped-def]
1770+ async def _method (self : genai_types .Runtime , ** kwargs ) -> AsyncIterator [Any ]: # type: ignore[no-untyped-def]
17721771 if not self .api_client :
17731772 raise ValueError ("api_client is not initialized." )
17741773 if not self .api_resource :
@@ -1916,50 +1915,6 @@ def _yield_parsed_json(http_response: google_genai_types.HttpResponse) -> Iterat
19161915 yield line
19171916
19181917
1919- def _yield_parsed_json_from_httpbody (body : httpbody_pb2 .HttpBody ) -> Iterator [Any ]:
1920- """Converts the contents of an `HttpBody` proto message to JSON format.
1921-
1922- Unlike `_yield_parsed_json`, which parses a `google.genai.types.HttpResponse`
1923- (with a `body` attribute), this helper parses the gRPC `httpbody_pb2.HttpBody`
1924- protos yielded by `stream_query_reasoning_engine`, which expose
1925- `content_type` and `data` instead.
1926-
1927- Args:
1928- body (httpbody_pb2.HttpBody):
1929- Required. The httpbody proto to be converted to JSON object(s).
1930-
1931- Yields:
1932- Any: A JSON object, a line of the original body, or the original body if
1933- it is not JSON, or None.
1934- """
1935- content_type = getattr (body , "content_type" , None )
1936- data = getattr (body , "data" , None )
1937-
1938- if content_type is None or data is None or "application/json" not in content_type :
1939- yield body
1940- return
1941-
1942- try :
1943- utf8_data = data .decode ("utf-8" )
1944- except Exception as e :
1945- logger .warning (f"Failed to decode data: { data !r} . Exception: { e } " )
1946- yield body
1947- return
1948-
1949- if not utf8_data :
1950- yield None
1951- return
1952-
1953- # Handle the case of multiple dictionaries delimited by newlines.
1954- for line in utf8_data .split ("\n " ):
1955- if line :
1956- try :
1957- line = json .loads (line )
1958- except Exception as e :
1959- logger .warning (f"failed to parse json: { line } . Exception: { e } " )
1960- yield line
1961-
1962-
19631918def _validate_resource_limits_or_raise (resource_limits : dict [str , str ]) -> None :
19641919 """Validates the resource limits.
19651920
@@ -2031,7 +1986,7 @@ def _validate_resource_limits_or_raise(resource_limits: dict[str, str]) -> None:
20311986 )
20321987
20331988
2034- def _is_adk_agent (agent_engine : _AgentEngineInterface ) -> bool :
1989+ def _is_adk_agent (agent_engine : _RuntimeInterface ) -> bool :
20351990 """Checks if the agent engine is an ADK agent.
20361991
20371992 Args:
@@ -2041,9 +1996,9 @@ def _is_adk_agent(agent_engine: _AgentEngineInterface) -> bool:
20411996 True if the agent engine is an ADK agent, False otherwise.
20421997 """
20431998
2044- from agentplatform .agent_engines . templates import adk
1999+ from agentplatform .frameworks import AdkApp
20452000
2046- return isinstance (agent_engine , adk . AdkApp )
2001+ return isinstance (agent_engine , AdkApp )
20472002
20482003
20492004def _add_telemetry_enablement_env (
0 commit comments