@@ -2956,28 +2956,54 @@ def create_evaluation_set(
29562956 def generate_conversation_scenarios (
29572957 self ,
29582958 * ,
2959- agent_info : evals_types .AgentInfoOrDict ,
2959+ agent_info : Optional [evals_types .AgentInfoOrDict ] = None ,
2960+ agent : Optional [str ] = None ,
29602961 config : evals_types .UserScenarioGenerationConfigOrDict ,
29612962 allow_cross_region_model : Optional [bool ] = None ,
29622963 ) -> types .EvaluationDataset :
29632964 """Generates an evaluation dataset with user scenarios,
29642965 which helps to generate conversations between a simulated user
29652966 and the agent under test.
29662967
2968+ Exactly one of `agent_info` or `agent` must be provided. When `agent` is
2969+ a Gemini Agents API agent resource name, the agent is fetched and an
2970+ `AgentInfo` is derived from it.
2971+
29672972 Args:
2968- agent_info: The agent info to generate user scenarios for.
2973+ agent_info: The agent info to generate user scenarios for. Mutually
2974+ exclusive with `agent`.
2975+ agent: A Gemini Agents API agent resource name
2976+ (`projects/{p}/locations/{l}/agents/{name}`). When provided, the
2977+ agent is fetched and its configuration is used to build the agent
2978+ info. Mutually exclusive with `agent_info`.
29692979 config: Configuration for generating user scenarios.
29702980 allow_cross_region_model: Opt-in flag to authorize cross-region
29712981 routing for model inference.
29722982
29732983 Returns:
29742984 An EvaluationDataset containing the generated user scenarios.
29752985 """
2976- parsed_agent_info = (
2977- evals_types .AgentInfo .model_validate (agent_info )
2978- if isinstance (agent_info , dict )
2979- else agent_info
2980- )
2986+ if agent is not None and agent_info is not None :
2987+ raise ValueError (
2988+ "Only one of `agent` or `agent_info` may be provided, not both."
2989+ )
2990+ if agent is None and agent_info is None :
2991+ raise ValueError ("One of `agent` or `agent_info` must be provided." )
2992+ if agent is not None :
2993+ if not _evals_common ._is_gemini_agent_resource (agent ):
2994+ raise ValueError (
2995+ "`agent` must be a Gemini Agents API agent resource name of the"
2996+ " form projects/{project}/locations/{location}/agents/{agent}."
2997+ )
2998+ parsed_agent_info = _evals_common ._agent_resource_to_agent_info (
2999+ agent , self ._api_client
3000+ )
3001+ else :
3002+ parsed_agent_info = (
3003+ evals_types .AgentInfo .model_validate (agent_info )
3004+ if isinstance (agent_info , dict )
3005+ else agent_info
3006+ )
29813007 response = self ._generate_user_scenarios (
29823008 agents = parsed_agent_info .agents ,
29833009 root_agent_id = parsed_agent_info .root_agent_id ,
@@ -4769,28 +4795,54 @@ async def create_evaluation_set(
47694795 async def generate_conversation_scenarios (
47704796 self ,
47714797 * ,
4772- agent_info : evals_types .AgentInfoOrDict ,
4798+ agent_info : Optional [evals_types .AgentInfoOrDict ] = None ,
4799+ agent : Optional [str ] = None ,
47734800 config : evals_types .UserScenarioGenerationConfigOrDict ,
47744801 allow_cross_region_model : Optional [bool ] = None ,
47754802 ) -> types .EvaluationDataset :
47764803 """Generates an evaluation dataset with user scenarios,
47774804 which helps to generate conversations between a simulated user
47784805 and the agent under test.
47794806
4807+ Exactly one of `agent_info` or `agent` must be provided. When `agent` is
4808+ a Gemini Agents API agent resource name, the agent is fetched and an
4809+ `AgentInfo` is derived from it.
4810+
47804811 Args:
4781- agent_info: The agent info to generate user scenarios for.
4812+ agent_info: The agent info to generate user scenarios for. Mutually
4813+ exclusive with `agent`.
4814+ agent: A Gemini Agents API agent resource name
4815+ (`projects/{p}/locations/{l}/agents/{name}`). When provided, the
4816+ agent is fetched and its configuration is used to build the agent
4817+ info. Mutually exclusive with `agent_info`.
47824818 config: Configuration for generating user scenarios.
47834819 allow_cross_region_model: Opt-in flag to authorize cross-region
47844820 routing for model inference.
47854821
47864822 Returns:
47874823 An EvaluationDataset containing the generated user scenarios.
47884824 """
4789- parsed_agent_info = (
4790- evals_types .AgentInfo .model_validate (agent_info )
4791- if isinstance (agent_info , dict )
4792- else agent_info
4793- )
4825+ if agent is not None and agent_info is not None :
4826+ raise ValueError (
4827+ "Only one of `agent` or `agent_info` may be provided, not both."
4828+ )
4829+ if agent is None and agent_info is None :
4830+ raise ValueError ("One of `agent` or `agent_info` must be provided." )
4831+ if agent is not None :
4832+ if not _evals_common ._is_gemini_agent_resource (agent ):
4833+ raise ValueError (
4834+ "`agent` must be a Gemini Agents API agent resource name of the"
4835+ " form projects/{project}/locations/{location}/agents/{agent}."
4836+ )
4837+ parsed_agent_info = _evals_common ._agent_resource_to_agent_info (
4838+ agent , self ._api_client
4839+ )
4840+ else :
4841+ parsed_agent_info = (
4842+ evals_types .AgentInfo .model_validate (agent_info )
4843+ if isinstance (agent_info , dict )
4844+ else agent_info
4845+ )
47944846 response = await self ._generate_user_scenarios (
47954847 agents = parsed_agent_info .agents ,
47964848 root_agent_id = parsed_agent_info .root_agent_id ,
0 commit comments