Skip to content

Commit 669f5d4

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Renaming.
PiperOrigin-RevId: 945668576
1 parent f6ecd67 commit 669f5d4

124 files changed

Lines changed: 7402 additions & 9934 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agentplatform/_genai/_evals_common.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _get_api_client_with_location(
100100

101101
def _get_agent_engine_instance(
102102
agent_name: str, api_client: BaseApiClient
103-
) -> Union[types.AgentEngine, Any]:
103+
) -> Union[types.Runtime, Any]:
104104
"""Gets or creates an agent engine instance for the current thread."""
105105
if not hasattr(_thread_local_data, "agent_engine_instances"):
106106
_thread_local_data.agent_engine_instances = {}
@@ -614,7 +614,7 @@ def _execute_inference_concurrently(
614614
model_or_fn: Optional[Union[str, Callable[[Any], Any]]] = None,
615615
gemini_config: Optional[genai_types.GenerateContentConfig] = None,
616616
inference_fn: Optional[Callable[..., Any]] = None,
617-
agent_engine: Optional[Union[str, types.AgentEngine]] = None,
617+
agent_engine: Optional[Union[str, types.Runtime]] = None,
618618
agent: Optional["LlmAgent"] = None, # type: ignore # noqa: F821
619619
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
620620
) -> list[
@@ -1404,7 +1404,7 @@ def _execute_inference(
14041404
api_client: BaseApiClient,
14051405
src: Union[str, pd.DataFrame],
14061406
model: Optional[Union[Callable[[Any], Any], str]] = None,
1407-
agent_engine: Optional[Union[str, types.AgentEngine]] = None,
1407+
agent_engine: Optional[Union[str, types.Runtime]] = None,
14081408
agent: Optional["LlmAgent"] = None, # type: ignore # noqa: F821
14091409
dest: Optional[str] = None,
14101410
config: Optional[genai_types.GenerateContentConfig] = None,
@@ -1499,7 +1499,7 @@ def _execute_inference(
14991499
f"Unsupported agent_engine type: {type(agent_engine)}. Expecting a"
15001500
" string (agent engine resource name in"
15011501
" 'projects/{project_id}/locations/{location_id}/reasoningEngines/{reasoning_engine_id}'"
1502-
" format) or a types.AgentEngine instance."
1502+
" format) or a types.Runtime instance."
15031503
)
15041504
if (
15051505
_evals_constant.INTERMEDIATE_EVENTS in prompt_dataset.columns
@@ -2102,7 +2102,7 @@ def _create_agent_results_dataframe(
21022102

21032103
def _run_agent_internal(
21042104
api_client: BaseApiClient,
2105-
agent_engine: Optional[Union[str, types.AgentEngine]],
2105+
agent_engine: Optional[Union[str, types.Runtime]],
21062106
agent: Optional["LlmAgent"], # type: ignore # noqa: F821
21072107
prompt_dataset: pd.DataFrame,
21082108
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
@@ -2153,7 +2153,7 @@ def _run_agent_internal(
21532153

21542154
def _run_agent(
21552155
api_client: BaseApiClient,
2156-
agent_engine: Optional[Union[str, types.AgentEngine]],
2156+
agent_engine: Optional[Union[str, types.Runtime]],
21572157
agent: Optional["LlmAgent"], # type: ignore # noqa: F821
21582158
prompt_dataset: pd.DataFrame,
21592159
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
@@ -2224,7 +2224,7 @@ def _run_agent(
22242224

22252225
def _create_agent_engine_session(
22262226
*,
2227-
agent_engine: types.AgentEngine,
2227+
agent_engine: types.Runtime,
22282228
user_id: str,
22292229
session_state: Optional[dict[str, Any]] = None,
22302230
) -> Any:
@@ -2271,7 +2271,7 @@ def _create_agent_engine_session(
22712271
operation = agent_engine.api_client.sessions.create(
22722272
name=agent_engine.api_resource.name,
22732273
user_id=user_id,
2274-
config=types.CreateAgentEngineSessionConfig(
2274+
config=types.CreateRuntimeSessionConfig(
22752275
session_state=session_state,
22762276
),
22772277
)
@@ -2293,7 +2293,7 @@ def _create_agent_engine_session(
22932293
def _execute_agent_run_with_retry(
22942294
row: pd.Series,
22952295
contents: Union[genai_types.ContentListUnion, genai_types.ContentListUnionDict],
2296-
agent_engine: types.AgentEngine,
2296+
agent_engine: types.Runtime,
22972297
max_retries: int = 3,
22982298
) -> Union[list[dict[str, Any]], dict[str, Any]]:
22992299
"""Executes agent run over agent engine for a single prompt."""
@@ -2340,7 +2340,7 @@ def _execute_agent_run_with_retry(
23402340
author=ag_event.author or "user",
23412341
invocation_id="history",
23422342
timestamp=base_ts + datetime.timedelta(seconds=i),
2343-
config=types.AppendAgentEngineSessionEventConfig(
2343+
config=types.AppendRuntimeSessionEventConfig(
23442344
content=ag_event.content,
23452345
),
23462346
)

agentplatform/_genai/_agent_engines_utils.py renamed to agentplatform/_genai/_runtimes_utils.py

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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

1717
import abc
1818
import asyncio
@@ -53,7 +53,6 @@
5353

5454
from google.api_core import exceptions
5555
from google.genai import types as google_genai_types
56-
from google.api import httpbody_pb2
5756
from google.protobuf import struct_pb2
5857
from 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

334333
class 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

451450
class GetOperationFunction(Protocol):
452451
def __call__(
453452
self, *, operation_name: str, **kwargs: Any
454-
) -> AgentEngineOperationUnion:
453+
) -> RuntimeOperationUnion:
455454
pass
456455

457456

458457
class 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

612611
def _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(
811810
def _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

872871
def _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

986985
def _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

10431042
def _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

12441243
def _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

14761475
def _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-
19631918
def _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

20492004
def _add_telemetry_enablement_env(

0 commit comments

Comments
 (0)