3636try :
3737 from google .adk .agents import LlmAgent
3838except ImportError :
39- LlmAgent = None # type: ignore[assignment]
39+ LlmAgent = None
4040
4141
4242logger = logging .getLogger ("vertexai_genai.evals" )
@@ -1216,10 +1216,10 @@ def evaluate(
12161216 types .EvaluationDatasetOrDict ,
12171217 list [types .EvaluationDatasetOrDict ],
12181218 ],
1219- metrics : list [types .MetricOrDict ] = None ,
1219+ metrics : Optional [ list [types .MetricOrDict ] ] = None ,
12201220 location : Optional [str ] = None ,
12211221 config : Optional [types .EvaluateMethodConfigOrDict ] = None ,
1222- ** kwargs ,
1222+ ** kwargs : Any ,
12231223 ) -> types .EvaluationResult :
12241224 """Evaluates candidate responses in the provided dataset(s) using the specified metrics.
12251225
@@ -1625,24 +1625,28 @@ def create_evaluation_run(
16251625 raise ValueError (
16261626 "At most one of agent_info or inference_configs can be provided."
16271627 )
1628- if agent_info and isinstance (agent_info , dict ):
1629- agent_info = types .evals .AgentInfo .model_validate (agent_info )
1630- if type (dataset ).__name__ == "EvaluationDataset" :
1628+ agent_info_pydantic : types .evals .AgentInfo = types .evals .AgentInfo ()
1629+ if agent_info :
1630+ if isinstance (agent_info , dict ):
1631+ agent_info_pydantic = types .evals .AgentInfo .model_validate (agent_info )
1632+ else :
1633+ agent_info_pydantic = agent_info
1634+ if isinstance (dataset , types .EvaluationDataset ):
16311635 if dataset .eval_dataset_df is None :
16321636 raise ValueError (
16331637 "EvaluationDataset must have eval_dataset_df populated."
16341638 )
1635- if (
1639+ if agent_info_pydantic is not None and (
16361640 dataset .candidate_name
1637- and agent_info
1638- and agent_info .name
1639- and dataset .candidate_name != agent_info .name
1641+ and agent_info_pydantic
1642+ and agent_info_pydantic .name
1643+ and dataset .candidate_name != agent_info_pydantic .name
16401644 ):
16411645 logger .warning (
16421646 "Evaluation dataset candidate_name and agent_info.name are different. Please make sure this is intended."
16431647 )
1644- elif dataset .candidate_name is None and agent_info :
1645- dataset .candidate_name = agent_info .name
1648+ elif dataset .candidate_name is None and agent_info_pydantic :
1649+ dataset .candidate_name = agent_info_pydantic .name
16461650 eval_set = _evals_common ._create_evaluation_set_from_dataframe (
16471651 self ._api_client , dest , dataset .eval_dataset_df , dataset .candidate_name
16481652 )
@@ -1656,20 +1660,26 @@ def create_evaluation_run(
16561660 evaluation_config = types .EvaluationRunConfig (
16571661 output_config = output_config , metrics = resolved_metrics
16581662 )
1659- if agent_info :
1663+ if agent_info_pydantic and agent_info_pydantic . name is not None :
16601664 inference_configs = {}
1661- inference_configs [agent_info .name ] = types .EvaluationRunInferenceConfig (
1662- agent_config = types .EvaluationRunAgentConfig (
1663- developer_instruction = genai_types .Content (
1664- parts = [genai_types .Part (text = agent_info .instruction )]
1665- ),
1666- tools = agent_info .tool_declarations ,
1665+ inference_configs [agent_info_pydantic .name ] = (
1666+ types .EvaluationRunInferenceConfig (
1667+ agent_config = types .EvaluationRunAgentConfig (
1668+ developer_instruction = genai_types .Content (
1669+ parts = [
1670+ genai_types .Part (text = agent_info_pydantic .instruction )
1671+ ]
1672+ ),
1673+ tools = agent_info_pydantic .tool_declarations ,
1674+ )
16671675 )
16681676 )
1669- if agent_info .agent_resource_name :
1677+ if agent_info_pydantic .agent_resource_name :
16701678 labels = labels or {}
16711679 labels ["vertex-ai-evaluation-agent-engine-id" ] = (
1672- agent_info .agent_resource_name .split ("reasoningEngines/" )[- 1 ]
1680+ agent_info_pydantic .agent_resource_name .split ("reasoningEngines/" )[
1681+ - 1
1682+ ]
16731683 )
16741684 if not name :
16751685 name = f"evaluation_run_{ uuid .uuid4 ()} "
@@ -2487,12 +2497,12 @@ async def create_evaluation_run(
24872497 )
24882498 if agent_info and isinstance (agent_info , dict ):
24892499 agent_info = types .evals .AgentInfo .model_validate (agent_info )
2490- if type (dataset ). __name__ == " EvaluationDataset" :
2500+ if isinstance (dataset , types . EvaluationDataset ) :
24912501 if dataset .eval_dataset_df is None :
24922502 raise ValueError (
24932503 "EvaluationDataset must have eval_dataset_df populated."
24942504 )
2495- if (
2505+ if agent_info is not None and (
24962506 dataset .candidate_name
24972507 and agent_info .name
24982508 and dataset .candidate_name != agent_info .name
@@ -2515,7 +2525,7 @@ async def create_evaluation_run(
25152525 evaluation_config = types .EvaluationRunConfig (
25162526 output_config = output_config , metrics = resolved_metrics
25172527 )
2518- if agent_info :
2528+ if agent_info and agent_info . name is not None :
25192529 inference_configs = {}
25202530 inference_configs [agent_info .name ] = types .EvaluationRunInferenceConfig (
25212531 agent_config = types .EvaluationRunAgentConfig (
@@ -2533,7 +2543,7 @@ async def create_evaluation_run(
25332543 if not name :
25342544 name = f"evaluation_run_{ uuid .uuid4 ()} "
25352545
2536- result = await self ._create_evaluation_run ( # type: ignore[no-any-return]
2546+ result = await self ._create_evaluation_run (
25372547 name = name ,
25382548 display_name = display_name or name ,
25392549 data_source = dataset ,
@@ -2645,7 +2655,7 @@ async def create_evaluation_item(
26452655 Returns:
26462656 The evaluation item.
26472657 """
2648- result = await self ._create_evaluation_item ( # type: ignore[no-any-return]
2658+ result = await self ._create_evaluation_item (
26492659 evaluation_item_type = evaluation_item_type ,
26502660 gcs_uri = gcs_uri ,
26512661 display_name = display_name ,
@@ -2676,7 +2686,7 @@ async def create_evaluation_set(
26762686 Returns:
26772687 The evaluation set.
26782688 """
2679- result = await self ._create_evaluation_set ( # type: ignore[no-any-return]
2689+ result = await self ._create_evaluation_set (
26802690 evaluation_items = evaluation_items ,
26812691 display_name = display_name ,
26822692 config = config ,
0 commit comments