Skip to content

Commit dd36289

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: GenAI Client(evals): Update SDK class to implement multi-turn agent scraping in evals.run_inference function
PiperOrigin-RevId: 864104059
1 parent 1bbfb61 commit dd36289

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

vertexai/_genai/types/common.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ class EvaluationPrompt(_common.BaseModel):
501501
prompt_template_data: Optional[PromptTemplateData] = Field(
502502
default=None, description="""Prompt template data."""
503503
)
504+
user_scenario: Optional[evals_types.UserScenario] = Field(
505+
default=None,
506+
description="""User scenario to help simulate multi-turn agent run results.""",
507+
)
504508

505509

506510
class EvaluationPromptDict(TypedDict, total=False):
@@ -515,6 +519,9 @@ class EvaluationPromptDict(TypedDict, total=False):
515519
prompt_template_data: Optional[PromptTemplateDataDict]
516520
"""Prompt template data."""
517521

522+
user_scenario: Optional[evals_types.UserScenario]
523+
"""User scenario to help simulate multi-turn agent run results."""
524+
518525

519526
EvaluationPromptOrDict = Union[EvaluationPrompt, EvaluationPromptDict]
520527

@@ -1843,6 +1850,12 @@ class EvaluationRunInferenceConfig(_common.BaseModel):
18431850
default=None,
18441851
description="""The fully qualified name of the publisher model or endpoint to use for inference.""",
18451852
)
1853+
user_simulator_config: Optional[evals_types.UserSimulatorConfig] = Field(
1854+
default=None,
1855+
description="""Used for multi-turn agent run.
1856+
Contains configuration for a user simulator that
1857+
uses an LLM to generate messages on behalf of the user.""",
1858+
)
18461859

18471860

18481861
class EvaluationRunInferenceConfigDict(TypedDict, total=False):
@@ -1857,6 +1870,11 @@ class EvaluationRunInferenceConfigDict(TypedDict, total=False):
18571870
model: Optional[str]
18581871
"""The fully qualified name of the publisher model or endpoint to use for inference."""
18591872

1873+
user_simulator_config: Optional[evals_types.UserSimulatorConfig]
1874+
"""Used for multi-turn agent run.
1875+
Contains configuration for a user simulator that
1876+
uses an LLM to generate messages on behalf of the user."""
1877+
18601878

18611879
EvaluationRunInferenceConfigOrDict = Union[
18621880
EvaluationRunInferenceConfig, EvaluationRunInferenceConfigDict
@@ -13546,6 +13564,11 @@ class EvalRunInferenceConfig(_common.BaseModel):
1354613564
generate_content_config: Optional[genai_types.GenerateContentConfig] = Field(
1354713565
default=None, description="""The config for the generate content call."""
1354813566
)
13567+
user_simulator_config: Optional[evals_types.UserSimulatorConfig] = Field(
13568+
default=None,
13569+
description="""Configuration for user simulation in multi-turn agent scraping. If provided, and the dataset contains
13570+
conversation plans, user simulation will be triggered.""",
13571+
)
1354913572

1355013573

1355113574
class EvalRunInferenceConfigDict(TypedDict, total=False):
@@ -13560,6 +13583,10 @@ class EvalRunInferenceConfigDict(TypedDict, total=False):
1356013583
generate_content_config: Optional[genai_types.GenerateContentConfigDict]
1356113584
"""The config for the generate content call."""
1356213585

13586+
user_simulator_config: Optional[evals_types.UserSimulatorConfig]
13587+
"""Configuration for user simulation in multi-turn agent scraping. If provided, and the dataset contains
13588+
conversation plans, user simulation will be triggered."""
13589+
1356313590

1356413591
EvalRunInferenceConfigOrDict = Union[EvalRunInferenceConfig, EvalRunInferenceConfigDict]
1356513592

vertexai/_genai/types/evals.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,67 @@ class SessionInputDict(TypedDict, total=False):
768768

769769

770770
SessionInputOrDict = Union[SessionInput, SessionInputDict]
771+
772+
773+
class UserScenario(_common.BaseModel):
774+
"""User scenario to help simulate multi-turn agent run results."""
775+
776+
starting_prompt: Optional[str] = Field(
777+
default=None,
778+
description="""The prompt that starts the conversation between the simulated user and the agent under test.""",
779+
)
780+
conversation_plan: Optional[str] = Field(
781+
default=None,
782+
description="""The plan for the conversation, used to drive the multi-turn agent run and generate the simulated agent evaluation dataset.""",
783+
)
784+
785+
786+
class UserScenarioDict(TypedDict, total=False):
787+
"""User scenario to help simulate multi-turn agent run results."""
788+
789+
starting_prompt: Optional[str]
790+
"""The prompt that starts the conversation between the simulated user and the agent under test."""
791+
792+
conversation_plan: Optional[str]
793+
"""The plan for the conversation, used to drive the multi-turn agent run and generate the simulated agent evaluation dataset."""
794+
795+
796+
UserScenarioOrDict = Union[UserScenario, UserScenarioDict]
797+
798+
799+
class UserSimulatorConfig(_common.BaseModel):
800+
"""Configuration for a user simulator that uses an LLM to generate messages."""
801+
802+
model_name: Optional[str] = Field(
803+
default=None,
804+
description="""The model name to get next user message for multi-turn agent run.""",
805+
)
806+
model_configuration: Optional[genai_types.GenerateContentConfig] = Field(
807+
default=None, description="""The configuration for the model."""
808+
)
809+
max_turn: Optional[int] = Field(
810+
default=None,
811+
description="""Maximum number of invocations allowed by the multi-turn agent
812+
running. This property allows us to stop a run-off conversation
813+
where the agent and the user simulator get into a never ending loop.
814+
The initial fixed prompt is also counted as an invocation.""",
815+
)
816+
817+
818+
class UserSimulatorConfigDict(TypedDict, total=False):
819+
"""Configuration for a user simulator that uses an LLM to generate messages."""
820+
821+
model_name: Optional[str]
822+
"""The model name to get next user message for multi-turn agent run."""
823+
824+
model_configuration: Optional[genai_types.GenerateContentConfigDict]
825+
"""The configuration for the model."""
826+
827+
max_turn: Optional[int]
828+
"""Maximum number of invocations allowed by the multi-turn agent
829+
running. This property allows us to stop a run-off conversation
830+
where the agent and the user simulator get into a never ending loop.
831+
The initial fixed prompt is also counted as an invocation."""
832+
833+
834+
UserSimulatorConfigOrDict = Union[UserSimulatorConfig, UserSimulatorConfigDict]

0 commit comments

Comments
 (0)