Skip to content

Commit 5094533

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

129 files changed

Lines changed: 22818 additions & 23110 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/_datasets_utils.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -280,63 +280,6 @@ async def save_dataframe_to_bigquery_async(
280280
await asyncio.to_thread(bq_client.delete_table, temp_table_id)
281281

282282

283-
def load_dataframe_from_bigquery(
284-
*,
285-
bigquery_uri: str,
286-
project: str,
287-
location: str,
288-
credentials: google.auth.credentials.Credentials,
289-
) -> "bigframes.pandas.DataFrame": # type: ignore # noqa: F821
290-
"""Loads a BigQuery table into a BigFrames DataFrame.
291-
292-
Args:
293-
bigquery_uri: The URI of the BigQuery table, with or without the `bq://`
294-
prefix.
295-
project: The project to use for the BigFrames session.
296-
location: The location to use for the BigFrames session.
297-
credentials: The credentials to use for the BigFrames session.
298-
299-
Returns:
300-
A BigFrames DataFrame backed by the BigQuery table.
301-
"""
302-
bigframes = _try_import_bigframes()
303-
session_options = bigframes.BigQueryOptions(
304-
credentials=credentials,
305-
project=project,
306-
location=location,
307-
)
308-
with bigframes.connect(session_options) as session:
309-
return session.read_gbq(bigquery_uri.removeprefix("bq://"))
310-
311-
312-
async def load_dataframe_from_bigquery_async(
313-
*,
314-
bigquery_uri: str,
315-
project: str,
316-
location: str,
317-
credentials: google.auth.credentials.Credentials,
318-
) -> "bigframes.pandas.DataFrame": # type: ignore # noqa: F821
319-
"""Loads a BigQuery table into a BigFrames DataFrame.
320-
321-
Args:
322-
bigquery_uri: The URI of the BigQuery table, with or without the `bq://`
323-
prefix.
324-
project: The project to use for the BigFrames session.
325-
location: The location to use for the BigFrames session.
326-
credentials: The credentials to use for the BigFrames session.
327-
328-
Returns:
329-
A BigFrames DataFrame backed by the BigQuery table.
330-
"""
331-
return await asyncio.to_thread(
332-
load_dataframe_from_bigquery,
333-
bigquery_uri=bigquery_uri,
334-
project=project,
335-
location=location,
336-
credentials=credentials,
337-
)
338-
339-
340283
def resolve_dataset_name(resource_name_or_id: str, project: str, location: str) -> str:
341284
"""Resolves a dataset name or ID to a full resource name."""
342285
if "/" not in resource_name_or_id:

agentplatform/_genai/_evals_common.py

Lines changed: 11 additions & 30 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 = {}
@@ -556,31 +556,12 @@ def _resolve_inference_configs(
556556
return inference_configs
557557

558558

559-
def _is_gemini_agent_resource(agent: str) -> bool:
560-
"""Returns True if `agent` is a Gemini Agent resource name.
561-
562-
A Gemini Agent resource name has the format
563-
`projects/{project}/locations/{location}/agents/{agent}`, as opposed to an
564-
Agent Engine resource name which uses `.../reasoningEngines/{id}`.
565-
"""
566-
parts = agent.split("/")
567-
return (
568-
len(parts) == 6
569-
and parts[0] == "projects"
570-
and parts[2] == "locations"
571-
and parts[4] == "agents"
572-
and bool(parts[1])
573-
and bool(parts[3])
574-
and bool(parts[5])
575-
)
576-
577-
578559
def _add_evaluation_run_labels(
579560
labels: Optional[dict[str, str]] = None,
580561
agent: Optional[str] = None,
581562
) -> Optional[dict[str, str]]:
582563
"""Adds labels to the evaluation run."""
583-
if agent and "reasoningEngines/" in agent and not _is_gemini_agent_resource(agent):
564+
if agent:
584565
labels = labels or {}
585566
labels["vertex-ai-evaluation-agent-engine-id"] = agent.split(
586567
"reasoningEngines/"
@@ -614,7 +595,7 @@ def _execute_inference_concurrently(
614595
model_or_fn: Optional[Union[str, Callable[[Any], Any]]] = None,
615596
gemini_config: Optional[genai_types.GenerateContentConfig] = None,
616597
inference_fn: Optional[Callable[..., Any]] = None,
617-
agent_engine: Optional[Union[str, types.AgentEngine]] = None,
598+
agent_engine: Optional[Union[str, types.Runtime]] = None,
618599
agent: Optional["LlmAgent"] = None, # type: ignore # noqa: F821
619600
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
620601
) -> list[
@@ -1404,7 +1385,7 @@ def _execute_inference(
14041385
api_client: BaseApiClient,
14051386
src: Union[str, pd.DataFrame],
14061387
model: Optional[Union[Callable[[Any], Any], str]] = None,
1407-
agent_engine: Optional[Union[str, types.AgentEngine]] = None,
1388+
agent_engine: Optional[Union[str, types.Runtime]] = None,
14081389
agent: Optional["LlmAgent"] = None, # type: ignore # noqa: F821
14091390
dest: Optional[str] = None,
14101391
config: Optional[genai_types.GenerateContentConfig] = None,
@@ -1499,7 +1480,7 @@ def _execute_inference(
14991480
f"Unsupported agent_engine type: {type(agent_engine)}. Expecting a"
15001481
" string (agent engine resource name in"
15011482
" 'projects/{project_id}/locations/{location_id}/reasoningEngines/{reasoning_engine_id}'"
1502-
" format) or a types.AgentEngine instance."
1483+
" format) or a types.Runtime instance."
15031484
)
15041485
if (
15051486
_evals_constant.INTERMEDIATE_EVENTS in prompt_dataset.columns
@@ -2102,7 +2083,7 @@ def _create_agent_results_dataframe(
21022083

21032084
def _run_agent_internal(
21042085
api_client: BaseApiClient,
2105-
agent_engine: Optional[Union[str, types.AgentEngine]],
2086+
agent_engine: Optional[Union[str, types.Runtime]],
21062087
agent: Optional["LlmAgent"], # type: ignore # noqa: F821
21072088
prompt_dataset: pd.DataFrame,
21082089
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
@@ -2153,7 +2134,7 @@ def _run_agent_internal(
21532134

21542135
def _run_agent(
21552136
api_client: BaseApiClient,
2156-
agent_engine: Optional[Union[str, types.AgentEngine]],
2137+
agent_engine: Optional[Union[str, types.Runtime]],
21572138
agent: Optional["LlmAgent"], # type: ignore # noqa: F821
21582139
prompt_dataset: pd.DataFrame,
21592140
user_simulator_config: Optional[types.evals.UserSimulatorConfig] = None,
@@ -2224,7 +2205,7 @@ def _run_agent(
22242205

22252206
def _create_agent_engine_session(
22262207
*,
2227-
agent_engine: types.AgentEngine,
2208+
agent_engine: types.Runtime,
22282209
user_id: str,
22292210
session_state: Optional[dict[str, Any]] = None,
22302211
) -> Any:
@@ -2271,7 +2252,7 @@ def _create_agent_engine_session(
22712252
operation = agent_engine.api_client.sessions.create(
22722253
name=agent_engine.api_resource.name,
22732254
user_id=user_id,
2274-
config=types.CreateAgentEngineSessionConfig(
2255+
config=types.CreateRuntimeSessionConfig(
22752256
session_state=session_state,
22762257
),
22772258
)
@@ -2293,7 +2274,7 @@ def _create_agent_engine_session(
22932274
def _execute_agent_run_with_retry(
22942275
row: pd.Series,
22952276
contents: Union[genai_types.ContentListUnion, genai_types.ContentListUnionDict],
2296-
agent_engine: types.AgentEngine,
2277+
agent_engine: types.Runtime,
22972278
max_retries: int = 3,
22982279
) -> Union[list[dict[str, Any]], dict[str, Any]]:
22992280
"""Executes agent run over agent engine for a single prompt."""
@@ -2340,7 +2321,7 @@ def _execute_agent_run_with_retry(
23402321
author=ag_event.author or "user",
23412322
invocation_id="history",
23422323
timestamp=base_ts + datetime.timedelta(seconds=i),
2343-
config=types.AppendAgentEngineSessionEventConfig(
2324+
config=types.AppendRuntimeSessionEventConfig(
23442325
content=ag_event.content,
23452326
),
23462327
)

agentplatform/_genai/_evals_metric_handlers.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -703,16 +703,6 @@ def _build_evaluation_instance(
703703
)
704704
)
705705

706-
# An interactions data source is mutually exclusive with agent_data: when
707-
# set, the backend fetches the interaction + Gemini Agent config and parses
708-
# them into agent data server-side, so we must not also send agent_data.
709-
interactions_data_source = getattr(eval_case, "interactions_data_source", None)
710-
agent_data = (
711-
None
712-
if interactions_data_source is not None
713-
else _eval_case_to_agent_data(eval_case, extracted_prompt, response_content)
714-
)
715-
716706
return types.EvaluationInstance(
717707
prompt=prompt_instance_data,
718708
response=_content_to_instance_data(response_content),
@@ -725,8 +715,9 @@ def _build_evaluation_instance(
725715
other_data=(
726716
types.MapInstance(map_instance=other_data_map) if other_data_map else None
727717
),
728-
agent_data=agent_data,
729-
interactions_data_source=interactions_data_source,
718+
agent_data=_eval_case_to_agent_data(
719+
eval_case, extracted_prompt, response_content
720+
),
730721
)
731722

732723

@@ -1001,11 +992,7 @@ def _build_request_payload(
1001992
eval_case, response_index, self.metric.name
1002993
)
1003994

1004-
if (
1005-
not response_content
1006-
and not getattr(eval_case, "agent_data", None)
1007-
and not getattr(eval_case, "interactions_data_source", None)
1008-
):
995+
if not response_content and not getattr(eval_case, "agent_data", None):
1009996
raise ValueError(
1010997
f"Response content missing for candidate {response_index}."
1011998
)
@@ -1604,10 +1591,7 @@ def compute_metrics_and_aggregate(
16041591
num_responses = (
16051592
len(eval_case.responses) if eval_case.responses else 0
16061593
)
1607-
if num_responses == 0 and (
1608-
getattr(eval_case, "agent_data", None)
1609-
or getattr(eval_case, "interactions_data_source", None)
1610-
):
1594+
if num_responses == 0 and getattr(eval_case, "agent_data", None):
16111595
num_responses = 1
16121596

16131597
actual_num_candidates_for_case = min(

0 commit comments

Comments
 (0)