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,25 @@ def create_evaluation_run(
16251625 raise ValueError (
16261626 "At most one of agent_info or inference_configs can be provided."
16271627 )
1628+ agent_info_pydantic : types .evals .AgentInfo = types .evals .AgentInfo ()
16281629 if agent_info and isinstance (agent_info , dict ):
1629- agent_info = types .evals .AgentInfo .model_validate (agent_info )
1630- if type (dataset ). __name__ == " EvaluationDataset" :
1630+ agent_info_pydantic = types .evals .AgentInfo .model_validate (agent_info )
1631+ if isinstance (dataset , types . EvaluationDataset ) :
16311632 if dataset .eval_dataset_df is None :
16321633 raise ValueError (
16331634 "EvaluationDataset must have eval_dataset_df populated."
16341635 )
1635- if (
1636+ if agent_info_pydantic is not None and (
16361637 dataset .candidate_name
1637- and agent_info
1638- and agent_info .name
1639- and dataset .candidate_name != agent_info .name
1638+ and agent_info_pydantic
1639+ and agent_info_pydantic .name
1640+ and dataset .candidate_name != agent_info_pydantic .name
16401641 ):
16411642 logger .warning (
16421643 "Evaluation dataset candidate_name and agent_info.name are different. Please make sure this is intended."
16431644 )
1644- elif dataset .candidate_name is None and agent_info :
1645- dataset .candidate_name = agent_info .name
1645+ elif dataset .candidate_name is None and agent_info_pydantic :
1646+ dataset .candidate_name = agent_info_pydantic .name
16461647 eval_set = _evals_common ._create_evaluation_set_from_dataframe (
16471648 self ._api_client , dest , dataset .eval_dataset_df , dataset .candidate_name
16481649 )
@@ -1656,20 +1657,26 @@ def create_evaluation_run(
16561657 evaluation_config = types .EvaluationRunConfig (
16571658 output_config = output_config , metrics = resolved_metrics
16581659 )
1659- if agent_info :
1660+ if agent_info_pydantic and agent_info_pydantic . name is not None :
16601661 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 ,
1662+ inference_configs [agent_info_pydantic .name ] = (
1663+ types .EvaluationRunInferenceConfig (
1664+ agent_config = types .EvaluationRunAgentConfig (
1665+ developer_instruction = genai_types .Content (
1666+ parts = [
1667+ genai_types .Part (text = agent_info_pydantic .instruction )
1668+ ]
1669+ ),
1670+ tools = agent_info_pydantic .tool_declarations ,
1671+ )
16671672 )
16681673 )
1669- if agent_info .agent_resource_name :
1674+ if agent_info_pydantic .agent_resource_name :
16701675 labels = labels or {}
16711676 labels ["vertex-ai-evaluation-agent-engine-id" ] = (
1672- agent_info .agent_resource_name .split ("reasoningEngines/" )[- 1 ]
1677+ agent_info_pydantic .agent_resource_name .split ("reasoningEngines/" )[
1678+ - 1
1679+ ]
16731680 )
16741681 if not name :
16751682 name = f"evaluation_run_{ uuid .uuid4 ()} "
@@ -2487,12 +2494,12 @@ async def create_evaluation_run(
24872494 )
24882495 if agent_info and isinstance (agent_info , dict ):
24892496 agent_info = types .evals .AgentInfo .model_validate (agent_info )
2490- if type (dataset ). __name__ == " EvaluationDataset" :
2497+ if isinstance (dataset , types . EvaluationDataset ) :
24912498 if dataset .eval_dataset_df is None :
24922499 raise ValueError (
24932500 "EvaluationDataset must have eval_dataset_df populated."
24942501 )
2495- if (
2502+ if agent_info is not None and (
24962503 dataset .candidate_name
24972504 and agent_info .name
24982505 and dataset .candidate_name != agent_info .name
@@ -2515,7 +2522,7 @@ async def create_evaluation_run(
25152522 evaluation_config = types .EvaluationRunConfig (
25162523 output_config = output_config , metrics = resolved_metrics
25172524 )
2518- if agent_info :
2525+ if agent_info and agent_info . name is not None :
25192526 inference_configs = {}
25202527 inference_configs [agent_info .name ] = types .EvaluationRunInferenceConfig (
25212528 agent_config = types .EvaluationRunAgentConfig (
@@ -2533,7 +2540,7 @@ async def create_evaluation_run(
25332540 if not name :
25342541 name = f"evaluation_run_{ uuid .uuid4 ()} "
25352542
2536- result = await self ._create_evaluation_run ( # type: ignore[no-any-return]
2543+ result = await self ._create_evaluation_run (
25372544 name = name ,
25382545 display_name = display_name or name ,
25392546 data_source = dataset ,
@@ -2645,7 +2652,7 @@ async def create_evaluation_item(
26452652 Returns:
26462653 The evaluation item.
26472654 """
2648- result = await self ._create_evaluation_item ( # type: ignore[no-any-return]
2655+ result = await self ._create_evaluation_item (
26492656 evaluation_item_type = evaluation_item_type ,
26502657 gcs_uri = gcs_uri ,
26512658 display_name = display_name ,
@@ -2676,7 +2683,7 @@ async def create_evaluation_set(
26762683 Returns:
26772684 The evaluation set.
26782685 """
2679- result = await self ._create_evaluation_set ( # type: ignore[no-any-return]
2686+ result = await self ._create_evaluation_set (
26802687 evaluation_items = evaluation_items ,
26812688 display_name = display_name ,
26822689 config = config ,
0 commit comments