@@ -10779,6 +10779,10 @@ def test_create_evaluation_run_builds_gemini_agent_config(self):
1077910779 == _TEST_GEMINI_AGENT
1078010780 )
1078110781 assert "agent_engine" not in agent_run_config
10782+ # agent_info.name overrides the default candidate name.
10783+ inference_configs = request_body ["inferenceConfigs" ]
10784+ assert "gemini-agent" in inference_configs
10785+ assert _evals_common ._DEFAULT_CANDIDATE_NAME not in inference_configs
1078210786
1078310787 def test_create_evaluation_run_agent_engine_does_not_set_gemini (self ):
1078410788 evals_module = evals .Evals (api_client_ = self .mock_api_client )
@@ -10806,6 +10810,140 @@ def test_create_evaluation_run_agent_engine_does_not_set_gemini(self):
1080610810 agent_run_config = self ._agent_run_config (request_body )
1080710811 assert "gemini_agent_config" not in agent_run_config
1080810812 assert agent_run_config ["agent_engine" ] == _TEST_AGENT_ENGINE
10813+ # agent_info.name overrides the default candidate name.
10814+ inference_configs = request_body ["inferenceConfigs" ]
10815+ assert "ae-agent" in inference_configs
10816+ assert _evals_common ._DEFAULT_CANDIDATE_NAME not in inference_configs
10817+
10818+ def test_create_evaluation_run_gemini_agent_without_agent_info (self ):
10819+ """Gemini agent resource alone triggers inference_configs auto-construction."""
10820+ evals_module = evals .Evals (api_client_ = self .mock_api_client )
10821+
10822+ evals_module .create_evaluation_run (
10823+ dataset = agentplatform_genai_types .EvaluationRunDataSource (
10824+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10825+ ),
10826+ metrics = [
10827+ agentplatform_genai_types .EvaluationRunMetric (
10828+ metric = "multi_turn_task_success_v1" ,
10829+ metric_config = agentplatform_genai_types .UnifiedMetric (
10830+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
10831+ metric_spec_name = "multi_turn_task_success_v1" ,
10832+ )
10833+ ),
10834+ )
10835+ ],
10836+ dest = "gs://test-bucket/output" ,
10837+ agent = _TEST_GEMINI_AGENT ,
10838+ # No agent_info provided.
10839+ )
10840+
10841+ request_body = self ._get_create_run_body ()
10842+ agent_run_config = self ._agent_run_config (request_body )
10843+ assert (
10844+ agent_run_config ["gemini_agent_config" ]["gemini_agent" ]
10845+ == _TEST_GEMINI_AGENT
10846+ )
10847+ assert "agent_engine" not in agent_run_config
10848+ # Default candidate name should match the constant.
10849+ inference_configs = request_body ["inferenceConfigs" ]
10850+ assert _evals_common ._DEFAULT_CANDIDATE_NAME in inference_configs
10851+
10852+ def test_create_evaluation_run_no_agent_no_agent_info_no_inference (self ):
10853+ """Without agent or agent_info, no inference_configs are auto-constructed."""
10854+ evals_module = evals .Evals (api_client_ = self .mock_api_client )
10855+
10856+ evals_module .create_evaluation_run (
10857+ dataset = agentplatform_genai_types .EvaluationRunDataSource (
10858+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10859+ ),
10860+ metrics = [
10861+ agentplatform_genai_types .EvaluationRunMetric (
10862+ metric = "multi_turn_task_success_v1" ,
10863+ metric_config = agentplatform_genai_types .UnifiedMetric (
10864+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
10865+ metric_spec_name = "multi_turn_task_success_v1" ,
10866+ )
10867+ ),
10868+ )
10869+ ],
10870+ dest = "gs://test-bucket/output" ,
10871+ # No agent, no agent_info.
10872+ )
10873+
10874+ request_body = self ._get_create_run_body ()
10875+ assert "inferenceConfigs" not in request_body or not request_body .get (
10876+ "inferenceConfigs"
10877+ )
10878+
10879+ def test_create_evaluation_run_agent_engine_without_agent_info (self ):
10880+ """Agent Engine resource alone triggers inference_configs auto-construction."""
10881+ evals_module = evals .Evals (api_client_ = self .mock_api_client )
10882+
10883+ evals_module .create_evaluation_run (
10884+ dataset = agentplatform_genai_types .EvaluationRunDataSource (
10885+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10886+ ),
10887+ metrics = [
10888+ agentplatform_genai_types .EvaluationRunMetric (
10889+ metric = "multi_turn_task_success_v1" ,
10890+ metric_config = agentplatform_genai_types .UnifiedMetric (
10891+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
10892+ metric_spec_name = "multi_turn_task_success_v1" ,
10893+ )
10894+ ),
10895+ )
10896+ ],
10897+ dest = "gs://test-bucket/output" ,
10898+ agent = _TEST_AGENT_ENGINE ,
10899+ # No agent_info provided.
10900+ )
10901+
10902+ request_body = self ._get_create_run_body ()
10903+ agent_run_config = self ._agent_run_config (request_body )
10904+ assert agent_run_config ["agent_engine" ] == _TEST_AGENT_ENGINE
10905+ assert "gemini_agent_config" not in agent_run_config
10906+ # Default candidate name should match the constant.
10907+ inference_configs = request_body ["inferenceConfigs" ]
10908+ assert _evals_common ._DEFAULT_CANDIDATE_NAME in inference_configs
10909+
10910+ @mock .patch .object (_evals_common , "_resolve_dataset" )
10911+ def test_create_evaluation_run_uses_dataset_candidate_name (
10912+ self , mock_resolve_dataset
10913+ ):
10914+ """When dataset.candidate_name is set (e.g. from run_inference), the
10915+ inference_configs key should match it instead of using the default."""
10916+ mock_resolve_dataset .return_value = (
10917+ agentplatform_genai_types .EvaluationRunDataSource (
10918+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10919+ )
10920+ )
10921+ evals_module = evals .Evals (api_client_ = self .mock_api_client )
10922+
10923+ evals_module .create_evaluation_run (
10924+ dataset = agentplatform_genai_types .EvaluationDataset (
10925+ eval_dataset_df = pd .DataFrame ({"prompt" : ["hello" ]}),
10926+ candidate_name = "my-agent-v2" ,
10927+ ),
10928+ metrics = [
10929+ agentplatform_genai_types .EvaluationRunMetric (
10930+ metric = "multi_turn_task_success_v1" ,
10931+ metric_config = agentplatform_genai_types .UnifiedMetric (
10932+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
10933+ metric_spec_name = "multi_turn_task_success_v1" ,
10934+ )
10935+ ),
10936+ )
10937+ ],
10938+ dest = "gs://test-bucket/output" ,
10939+ agent = _TEST_GEMINI_AGENT ,
10940+ # No agent_info -- candidate name should come from dataset.
10941+ )
10942+
10943+ request_body = self ._get_create_run_body ()
10944+ inference_configs = request_body ["inferenceConfigs" ]
10945+ assert "my-agent-v2" in inference_configs
10946+ assert _evals_common ._DEFAULT_CANDIDATE_NAME not in inference_configs
1080910947
1081010948
1081110949class TestResolveInteractionsForDisplay :
0 commit comments