google-cloud-agentplatform 1.165.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentplatform/__init__.py +72 -0
- agentplatform/_genai/__init__.py +43 -0
- agentplatform/_genai/_agent_engines_utils.py +2341 -0
- agentplatform/_genai/_bigquery_utils.py +49 -0
- agentplatform/_genai/_datasets_utils.py +344 -0
- agentplatform/_genai/_evals_builtin_tools.py +209 -0
- agentplatform/_genai/_evals_common.py +4268 -0
- agentplatform/_genai/_evals_constant.py +122 -0
- agentplatform/_genai/_evals_data_converters.py +926 -0
- agentplatform/_genai/_evals_metric_handlers.py +1783 -0
- agentplatform/_genai/_evals_metric_loaders.py +401 -0
- agentplatform/_genai/_evals_utils.py +1043 -0
- agentplatform/_genai/_evals_visualization.py +2070 -0
- agentplatform/_genai/_gcs_utils.py +262 -0
- agentplatform/_genai/_logging_utils.py +47 -0
- agentplatform/_genai/_memory_bank_utils.py +206 -0
- agentplatform/_genai/_observability_data_converter.py +186 -0
- agentplatform/_genai/_operations_utils.py +94 -0
- agentplatform/_genai/_prompt_management_utils.py +147 -0
- agentplatform/_genai/_prompt_optimizer_utils.py +215 -0
- agentplatform/_genai/_skills_utils.py +69 -0
- agentplatform/_genai/_transformers.py +628 -0
- agentplatform/_genai/a2a_task_events.py +509 -0
- agentplatform/_genai/a2a_tasks.py +861 -0
- agentplatform/_genai/agent_engines.py +3931 -0
- agentplatform/_genai/client.py +519 -0
- agentplatform/_genai/datasets.py +3045 -0
- agentplatform/_genai/endpoints.py +1149 -0
- agentplatform/_genai/evals.py +6883 -0
- agentplatform/_genai/example_stores.py +1445 -0
- agentplatform/_genai/feedback_contexts.py +700 -0
- agentplatform/_genai/feedback_entries.py +1644 -0
- agentplatform/_genai/live.py +64 -0
- agentplatform/_genai/live_agent_engines.py +179 -0
- agentplatform/_genai/memories.py +2962 -0
- agentplatform/_genai/memory_banks.py +1927 -0
- agentplatform/_genai/memory_revisions.py +465 -0
- agentplatform/_genai/model_garden.py +2638 -0
- agentplatform/_genai/prompt_optimizer.py +995 -0
- agentplatform/_genai/prompts.py +4515 -0
- agentplatform/_genai/rag.py +4961 -0
- agentplatform/_genai/runtime_revisions.py +1257 -0
- agentplatform/_genai/runtimes.py +78 -0
- agentplatform/_genai/sandbox_snapshots.py +1015 -0
- agentplatform/_genai/sandbox_templates.py +1088 -0
- agentplatform/_genai/sandboxes.py +1604 -0
- agentplatform/_genai/session_events.py +543 -0
- agentplatform/_genai/sessions.py +1449 -0
- agentplatform/_genai/skill_revisions.py +377 -0
- agentplatform/_genai/skills.py +1708 -0
- agentplatform/_genai/types/__init__.py +4695 -0
- agentplatform/_genai/types/agent_engines.py +16 -0
- agentplatform/_genai/types/common.py +32784 -0
- agentplatform/_genai/types/evals.py +1031 -0
- agentplatform/_genai/types/prompt_optimizer.py +107 -0
- agentplatform/_genai/types/prompts.py +107 -0
- agentplatform/version.py +17 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/METADATA +79 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/RECORD +62 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/WHEEL +5 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/licenses/LICENSE +202 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
|
+
|
|
18
|
+
import datetime
|
|
19
|
+
from typing import Any, Optional, Union
|
|
20
|
+
from google.genai import _common
|
|
21
|
+
from google.genai import types as genai_types
|
|
22
|
+
from pydantic import Field
|
|
23
|
+
from typing_extensions import TypedDict
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Importance(_common.CaseInSensitiveEnum):
|
|
27
|
+
"""Importance level of the rubric."""
|
|
28
|
+
|
|
29
|
+
IMPORTANCE_UNSPECIFIED = "IMPORTANCE_UNSPECIFIED"
|
|
30
|
+
"""Importance is not specified."""
|
|
31
|
+
HIGH = "HIGH"
|
|
32
|
+
"""High importance."""
|
|
33
|
+
MEDIUM = "MEDIUM"
|
|
34
|
+
"""Medium importance."""
|
|
35
|
+
LOW = "LOW"
|
|
36
|
+
"""Low importance."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AgentConfig(_common.BaseModel):
|
|
40
|
+
"""Represents configuration for an Agent."""
|
|
41
|
+
|
|
42
|
+
agent_id: Optional[str] = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
description="""Unique identifier of the agent.
|
|
45
|
+
This ID is used to refer to this agent, e.g., in AgentEvent.author, or in
|
|
46
|
+
the `sub_agents` field. It must be unique within the `agents` map.""",
|
|
47
|
+
)
|
|
48
|
+
agent_type: Optional[str] = Field(
|
|
49
|
+
default=None,
|
|
50
|
+
description="""The type or class of the agent (e.g., "LlmAgent", "RouterAgent",
|
|
51
|
+
"ToolUseAgent"). Useful for the autorater to understand the expected
|
|
52
|
+
behavior of the agent.""",
|
|
53
|
+
)
|
|
54
|
+
description: Optional[str] = Field(
|
|
55
|
+
default=None,
|
|
56
|
+
description="""A high-level description of the agent's role and responsibilities.
|
|
57
|
+
Critical for evaluating if the agent is routing tasks correctly.""",
|
|
58
|
+
)
|
|
59
|
+
instruction: Optional[str] = Field(
|
|
60
|
+
default=None,
|
|
61
|
+
description="""The instructions for the LLM model, guiding the agent's behavior.
|
|
62
|
+
Can be static or dynamic. Dynamic instructions can contain placeholders
|
|
63
|
+
like {variable_name} that will be resolved at runtime using the
|
|
64
|
+
`AgentEvent.state_delta` field.""",
|
|
65
|
+
)
|
|
66
|
+
tools: Optional[list[genai_types.Tool]] = Field(
|
|
67
|
+
default=None, description="""The list of tools available to this agent."""
|
|
68
|
+
)
|
|
69
|
+
sub_agents: Optional[list[str]] = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
description="""The list of valid agent IDs that this agent can delegate to.
|
|
72
|
+
This defines the directed edges in the multi-agent system graph topology.""",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def _get_tool_declarations_from_agent(agent: Any) -> genai_types.ToolListUnion:
|
|
77
|
+
"""Gets tool declarations from an agent.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
agent: The agent to get the tool declarations from. Data type is google.adk.agents.LLMAgent type.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
The tool declarations of the agent.
|
|
84
|
+
"""
|
|
85
|
+
tool_declarations: genai_types.ToolListUnion = []
|
|
86
|
+
for tool in getattr(agent, "tools", None) or []:
|
|
87
|
+
# ADK tools (e.g. AgentTool, VertexAiSearchTool) own their declaration
|
|
88
|
+
# via _get_declaration(). A None result means the tool has no function
|
|
89
|
+
# declaration (e.g. built-in retrieval tools). In both cases, skip the
|
|
90
|
+
# plain-callable path, which calls typing.get_type_hints() on the
|
|
91
|
+
# instance and raises NameError for classes using
|
|
92
|
+
# `from __future__ import annotations`.
|
|
93
|
+
if hasattr(tool, "_get_declaration") and callable(tool._get_declaration):
|
|
94
|
+
declaration = tool._get_declaration()
|
|
95
|
+
if declaration is not None:
|
|
96
|
+
tool_declarations.append({"function_declarations": [declaration]})
|
|
97
|
+
continue
|
|
98
|
+
|
|
99
|
+
declaration = AgentConfig._get_declaration_from_callable(tool)
|
|
100
|
+
if declaration is not None:
|
|
101
|
+
tool_declarations.append({"function_declarations": [declaration]})
|
|
102
|
+
return tool_declarations
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def _get_declaration_from_callable(
|
|
106
|
+
tool: Any,
|
|
107
|
+
) -> Optional[genai_types.FunctionDeclaration]:
|
|
108
|
+
"""Builds a function declaration for a plain callable tool.
|
|
109
|
+
|
|
110
|
+
ADK agents store plain Python functions in `agent.tools` and only wrap
|
|
111
|
+
them in `FunctionTool` lazily at runtime. Such functions often take
|
|
112
|
+
ADK-injected parameters (e.g. `tool_context: ToolContext`) that the
|
|
113
|
+
generic `google-genai` schema generator rejects. When google-adk is
|
|
114
|
+
available, wrap the callable in ADK's `FunctionTool` so its declaration
|
|
115
|
+
logic strips those injected parameters. Otherwise, fall back to the
|
|
116
|
+
generic generator.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
tool: A plain callable tool from an agent's `tools` list.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The function declaration for the tool, or None if the tool has no
|
|
123
|
+
declaration.
|
|
124
|
+
"""
|
|
125
|
+
# pylint: disable=g-import-not-at-top,protected-access
|
|
126
|
+
# The returned FunctionDeclaration may populate either `parameters` or
|
|
127
|
+
# `parameters_json_schema` depending on the installed google-adk version
|
|
128
|
+
# and the JSON_SCHEMA_FOR_FUNC_DECL feature flag (default-on in adk>=2.2).
|
|
129
|
+
# A future adk major version will drop `parameters`, so downstream
|
|
130
|
+
# consumers must handle both fields.
|
|
131
|
+
try:
|
|
132
|
+
from google.adk.tools.function_tool import FunctionTool
|
|
133
|
+
|
|
134
|
+
return FunctionTool(func=tool)._get_declaration() # type: ignore[no-any-return]
|
|
135
|
+
except ImportError:
|
|
136
|
+
pass
|
|
137
|
+
return genai_types.FunctionDeclaration.from_callable_with_api_option(
|
|
138
|
+
callable=tool
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def from_agent(cls, agent: Any) -> "AgentConfig":
|
|
143
|
+
"""Creates an AgentConfig from an ADK agent.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
agent: The agent to get the agent info from, data type is google.adk.agents.LLMAgent type.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
An AgentConfig populated with the agent's metadata for evaluation.
|
|
150
|
+
"""
|
|
151
|
+
agent_id = getattr(agent, "name", None)
|
|
152
|
+
if not agent_id:
|
|
153
|
+
raise ValueError(f"Agent {agent} must have a name.")
|
|
154
|
+
return cls( # pytype: disable=missing-parameter
|
|
155
|
+
agent_id=agent_id,
|
|
156
|
+
agent_type=agent.__class__.__name__,
|
|
157
|
+
description=getattr(agent, "description", None),
|
|
158
|
+
instruction=getattr(agent, "instruction", None),
|
|
159
|
+
tools=AgentConfig._get_tool_declarations_from_agent(agent),
|
|
160
|
+
sub_agents=[
|
|
161
|
+
str(getattr(sub_agent, "name"))
|
|
162
|
+
for sub_agent in getattr(agent, "sub_agents", [])
|
|
163
|
+
if getattr(sub_agent, "name", None) is not None
|
|
164
|
+
],
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class AgentConfigDict(TypedDict, total=False):
|
|
169
|
+
"""Represents configuration for an Agent."""
|
|
170
|
+
|
|
171
|
+
agent_id: Optional[str]
|
|
172
|
+
"""Unique identifier of the agent.
|
|
173
|
+
This ID is used to refer to this agent, e.g., in AgentEvent.author, or in
|
|
174
|
+
the `sub_agents` field. It must be unique within the `agents` map."""
|
|
175
|
+
|
|
176
|
+
agent_type: Optional[str]
|
|
177
|
+
"""The type or class of the agent (e.g., "LlmAgent", "RouterAgent",
|
|
178
|
+
"ToolUseAgent"). Useful for the autorater to understand the expected
|
|
179
|
+
behavior of the agent."""
|
|
180
|
+
|
|
181
|
+
description: Optional[str]
|
|
182
|
+
"""A high-level description of the agent's role and responsibilities.
|
|
183
|
+
Critical for evaluating if the agent is routing tasks correctly."""
|
|
184
|
+
|
|
185
|
+
instruction: Optional[str]
|
|
186
|
+
"""The instructions for the LLM model, guiding the agent's behavior.
|
|
187
|
+
Can be static or dynamic. Dynamic instructions can contain placeholders
|
|
188
|
+
like {variable_name} that will be resolved at runtime using the
|
|
189
|
+
`AgentEvent.state_delta` field."""
|
|
190
|
+
|
|
191
|
+
tools: Optional[list[genai_types.Tool]]
|
|
192
|
+
"""The list of tools available to this agent."""
|
|
193
|
+
|
|
194
|
+
sub_agents: Optional[list[str]]
|
|
195
|
+
"""The list of valid agent IDs that this agent can delegate to.
|
|
196
|
+
This defines the directed edges in the multi-agent system graph topology."""
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
AgentConfigOrDict = Union[AgentConfig, AgentConfigDict]
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class AgentEvent(_common.BaseModel):
|
|
203
|
+
"""A single event in the execution trace."""
|
|
204
|
+
|
|
205
|
+
author: Optional[str] = Field(
|
|
206
|
+
default=None,
|
|
207
|
+
description="""The ID of the agent or entity that generated this event.
|
|
208
|
+
Use "user" to denote events generated by the end-user.""",
|
|
209
|
+
)
|
|
210
|
+
content: Optional[genai_types.Content] = Field(
|
|
211
|
+
default=None, description="""The content of the event."""
|
|
212
|
+
)
|
|
213
|
+
event_time: Optional[datetime.datetime] = Field(
|
|
214
|
+
default=None, description="""The timestamp when the event occurred."""
|
|
215
|
+
)
|
|
216
|
+
state_delta: Optional[dict[str, Any]] = Field(
|
|
217
|
+
default=None,
|
|
218
|
+
description="""The change in the session state caused by this event.
|
|
219
|
+
This is a key-value map of fields that were modified or added by the event.""",
|
|
220
|
+
)
|
|
221
|
+
active_tools: Optional[list[genai_types.Tool]] = Field(
|
|
222
|
+
default=None,
|
|
223
|
+
description="""The list of tools that were active/available to the agent at the
|
|
224
|
+
time of this event. This overrides the `AgentConfig.tools` if set.""",
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class AgentEventDict(TypedDict, total=False):
|
|
229
|
+
"""A single event in the execution trace."""
|
|
230
|
+
|
|
231
|
+
author: Optional[str]
|
|
232
|
+
"""The ID of the agent or entity that generated this event.
|
|
233
|
+
Use "user" to denote events generated by the end-user."""
|
|
234
|
+
|
|
235
|
+
content: Optional[genai_types.Content]
|
|
236
|
+
"""The content of the event."""
|
|
237
|
+
|
|
238
|
+
event_time: Optional[datetime.datetime]
|
|
239
|
+
"""The timestamp when the event occurred."""
|
|
240
|
+
|
|
241
|
+
state_delta: Optional[dict[str, Any]]
|
|
242
|
+
"""The change in the session state caused by this event.
|
|
243
|
+
This is a key-value map of fields that were modified or added by the event."""
|
|
244
|
+
|
|
245
|
+
active_tools: Optional[list[genai_types.Tool]]
|
|
246
|
+
"""The list of tools that were active/available to the agent at the
|
|
247
|
+
time of this event. This overrides the `AgentConfig.tools` if set."""
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
AgentEventOrDict = Union[AgentEvent, AgentEventDict]
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class ConversationTurn(_common.BaseModel):
|
|
254
|
+
"""Represents a single turn/invocation in the conversation."""
|
|
255
|
+
|
|
256
|
+
turn_index: Optional[int] = Field(
|
|
257
|
+
default=None,
|
|
258
|
+
description="""The 0-based index of the turn in the conversation sequence.""",
|
|
259
|
+
)
|
|
260
|
+
turn_id: Optional[str] = Field(
|
|
261
|
+
default=None, description="""A unique identifier for the turn."""
|
|
262
|
+
)
|
|
263
|
+
events: Optional[list[AgentEvent]] = Field(
|
|
264
|
+
default=None,
|
|
265
|
+
description="""The list of events that occurred during this turn.""",
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class ConversationTurnDict(TypedDict, total=False):
|
|
270
|
+
"""Represents a single turn/invocation in the conversation."""
|
|
271
|
+
|
|
272
|
+
turn_index: Optional[int]
|
|
273
|
+
"""The 0-based index of the turn in the conversation sequence."""
|
|
274
|
+
|
|
275
|
+
turn_id: Optional[str]
|
|
276
|
+
"""A unique identifier for the turn."""
|
|
277
|
+
|
|
278
|
+
events: Optional[list[AgentEventDict]]
|
|
279
|
+
"""The list of events that occurred during this turn."""
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
ConversationTurnOrDict = Union[ConversationTurn, ConversationTurnDict]
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
class AgentData(_common.BaseModel):
|
|
286
|
+
"""Represents data specific to multi-turn agent evaluations."""
|
|
287
|
+
|
|
288
|
+
agents: Optional[dict[str, AgentConfig]] = Field(
|
|
289
|
+
default=None,
|
|
290
|
+
description="""A map containing the static configurations for each agent in the system.
|
|
291
|
+
Key: agent_id (matches the `author` field in events).
|
|
292
|
+
Value: The static configuration of the agent.""",
|
|
293
|
+
)
|
|
294
|
+
turns: Optional[list[ConversationTurn]] = Field(
|
|
295
|
+
default=None,
|
|
296
|
+
description="""A chronological list of conversation turns.
|
|
297
|
+
Each turn represents a logical execution cycle (e.g., User Input -> Agent
|
|
298
|
+
Response).""",
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
@classmethod
|
|
302
|
+
def get_agents_map(cls, agent: Any) -> dict[str, AgentConfig]:
|
|
303
|
+
"""Recursively gets all agent configs from an agent and its sub-agents.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
agent: The agent to get the agent info from, data type is google.adk.agents.LLMAgent type.
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
A dict mapping agent_id to AgentConfig.
|
|
310
|
+
"""
|
|
311
|
+
agent_config = AgentConfig.from_agent(agent)
|
|
312
|
+
agent_id = agent_config.agent_id
|
|
313
|
+
if not agent_id:
|
|
314
|
+
raise ValueError(f"Agent {agent} must have a name.")
|
|
315
|
+
agents_map = {agent_id: agent_config}
|
|
316
|
+
|
|
317
|
+
for sub_agent in getattr(agent, "sub_agents", []):
|
|
318
|
+
agents_map.update(cls.get_agents_map(sub_agent))
|
|
319
|
+
|
|
320
|
+
return agents_map
|
|
321
|
+
|
|
322
|
+
@classmethod
|
|
323
|
+
def from_session(cls, agent: Any, session_history: list[Any]) -> "AgentData":
|
|
324
|
+
"""Creates an AgentData object from a session history.
|
|
325
|
+
|
|
326
|
+
Segments the flat list of session events into ConversationTurns. A new turn
|
|
327
|
+
is initiated by a User message.
|
|
328
|
+
|
|
329
|
+
Args:
|
|
330
|
+
agent: The agent instance used in the session.
|
|
331
|
+
session_history: A list of raw events/messages from the session.
|
|
332
|
+
|
|
333
|
+
Returns:
|
|
334
|
+
An AgentData object containing the segmented history and agent config.
|
|
335
|
+
"""
|
|
336
|
+
agents_map = cls.get_agents_map(agent)
|
|
337
|
+
agent_id = agent.name
|
|
338
|
+
|
|
339
|
+
turns: list[ConversationTurn] = []
|
|
340
|
+
current_turn_events: list[AgentEvent] = []
|
|
341
|
+
|
|
342
|
+
for event in session_history:
|
|
343
|
+
is_user = False
|
|
344
|
+
if isinstance(event, dict):
|
|
345
|
+
if event.get("role") == "user":
|
|
346
|
+
is_user = True
|
|
347
|
+
elif (
|
|
348
|
+
isinstance(event.get("content"), dict)
|
|
349
|
+
and event["content"].get("role") == "user"
|
|
350
|
+
):
|
|
351
|
+
is_user = True
|
|
352
|
+
elif hasattr(event, "role") and event.role == "user":
|
|
353
|
+
is_user = True
|
|
354
|
+
|
|
355
|
+
if is_user and current_turn_events:
|
|
356
|
+
turns.append(
|
|
357
|
+
ConversationTurn( # pytype: disable=missing-parameter
|
|
358
|
+
turn_index=len(turns),
|
|
359
|
+
turn_id=f"turn_{len(turns)}",
|
|
360
|
+
events=current_turn_events,
|
|
361
|
+
)
|
|
362
|
+
)
|
|
363
|
+
current_turn_events = []
|
|
364
|
+
|
|
365
|
+
author = "user" if is_user else agent_id
|
|
366
|
+
|
|
367
|
+
content = None
|
|
368
|
+
if isinstance(event, dict):
|
|
369
|
+
if "content" in event:
|
|
370
|
+
raw_content = event["content"]
|
|
371
|
+
if isinstance(raw_content, genai_types.Content):
|
|
372
|
+
content = raw_content
|
|
373
|
+
elif isinstance(raw_content, dict):
|
|
374
|
+
try:
|
|
375
|
+
content = genai_types.Content.model_validate(raw_content)
|
|
376
|
+
except Exception as e:
|
|
377
|
+
raise ValueError(
|
|
378
|
+
f"Failed to validate Content from dictionary in session history: {raw_content}"
|
|
379
|
+
) from e
|
|
380
|
+
elif isinstance(raw_content, str):
|
|
381
|
+
content = genai_types.Content(
|
|
382
|
+
parts=[genai_types.Part(text=raw_content)]
|
|
383
|
+
)
|
|
384
|
+
elif "parts" in event:
|
|
385
|
+
try:
|
|
386
|
+
content = genai_types.Content.model_validate(event)
|
|
387
|
+
except Exception as e:
|
|
388
|
+
raise ValueError(
|
|
389
|
+
f"Failed to validate Content from event with 'parts': {event}"
|
|
390
|
+
) from e
|
|
391
|
+
elif hasattr(event, "content") and isinstance(
|
|
392
|
+
event.content, genai_types.Content
|
|
393
|
+
):
|
|
394
|
+
content = event.content
|
|
395
|
+
|
|
396
|
+
agent_event = AgentEvent( # pytype: disable=missing-parameter
|
|
397
|
+
author=author,
|
|
398
|
+
content=content,
|
|
399
|
+
)
|
|
400
|
+
current_turn_events.append(agent_event)
|
|
401
|
+
|
|
402
|
+
if current_turn_events:
|
|
403
|
+
turns.append(
|
|
404
|
+
ConversationTurn( # pytype: disable=missing-parameter
|
|
405
|
+
turn_index=len(turns),
|
|
406
|
+
turn_id=f"turn_{len(turns)}",
|
|
407
|
+
events=current_turn_events,
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
return cls(agents=agents_map, turns=turns) # pytype: disable=missing-parameter
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
class AgentDataDict(TypedDict, total=False):
|
|
415
|
+
"""Represents data specific to multi-turn agent evaluations."""
|
|
416
|
+
|
|
417
|
+
agents: Optional[dict[str, AgentConfigDict]]
|
|
418
|
+
"""A map containing the static configurations for each agent in the system.
|
|
419
|
+
Key: agent_id (matches the `author` field in events).
|
|
420
|
+
Value: The static configuration of the agent."""
|
|
421
|
+
|
|
422
|
+
turns: Optional[list[ConversationTurnDict]]
|
|
423
|
+
"""A chronological list of conversation turns.
|
|
424
|
+
Each turn represents a logical execution cycle (e.g., User Input -> Agent
|
|
425
|
+
Response)."""
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
AgentDataOrDict = Union[AgentData, AgentDataDict]
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
class AgentInfo(_common.BaseModel):
|
|
432
|
+
"""The agent info of an agent system, used for agent evaluation."""
|
|
433
|
+
|
|
434
|
+
name: Optional[str] = Field(
|
|
435
|
+
default=None, description="""Agent candidate name, used as an identifier."""
|
|
436
|
+
)
|
|
437
|
+
agents: Optional[dict[str, AgentConfig]] = Field(
|
|
438
|
+
default=None,
|
|
439
|
+
description="""A map containing the static configurations for each agent in the system.
|
|
440
|
+
Key: agent_id (matches the `author` field in events).
|
|
441
|
+
Value: The static configuration of the agent.""",
|
|
442
|
+
)
|
|
443
|
+
root_agent_id: Optional[str] = Field(
|
|
444
|
+
default=None, description="""The agent ID of the root agent."""
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
@classmethod
|
|
448
|
+
def load_from_agent(cls, agent: Any) -> "AgentInfo":
|
|
449
|
+
"""Loads agent info from an ADK agent.
|
|
450
|
+
|
|
451
|
+
Args:
|
|
452
|
+
agent: The root agent to get the agent info from, data type is google.adk.agents.LLMAgent type.
|
|
453
|
+
|
|
454
|
+
Returns:
|
|
455
|
+
The agent info of the agent system.
|
|
456
|
+
|
|
457
|
+
Example:
|
|
458
|
+
```
|
|
459
|
+
from agentplatform._genai import types
|
|
460
|
+
|
|
461
|
+
agent_info = types.evals.AgentInfo.load_from_agent(agent=my_agent)
|
|
462
|
+
```
|
|
463
|
+
"""
|
|
464
|
+
agent_name = getattr(agent, "name", None)
|
|
465
|
+
if not agent_name:
|
|
466
|
+
raise ValueError(f"Agent {agent} must have a name.")
|
|
467
|
+
return cls( # pytype: disable=missing-parameter
|
|
468
|
+
name=agent_name,
|
|
469
|
+
agents=AgentData.get_agents_map(agent),
|
|
470
|
+
root_agent_id=agent_name,
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
class AgentInfoDict(TypedDict, total=False):
|
|
475
|
+
"""The agent info of an agent system, used for agent evaluation."""
|
|
476
|
+
|
|
477
|
+
name: Optional[str]
|
|
478
|
+
"""Agent candidate name, used as an identifier."""
|
|
479
|
+
|
|
480
|
+
agents: Optional[dict[str, AgentConfigDict]]
|
|
481
|
+
"""A map containing the static configurations for each agent in the system.
|
|
482
|
+
Key: agent_id (matches the `author` field in events).
|
|
483
|
+
Value: The static configuration of the agent."""
|
|
484
|
+
|
|
485
|
+
root_agent_id: Optional[str]
|
|
486
|
+
"""The agent ID of the root agent."""
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
AgentInfoOrDict = Union[AgentInfo, AgentInfoDict]
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
class SessionInput(_common.BaseModel):
|
|
493
|
+
"""Input to initialize a session and run an agent, used for agent evaluation."""
|
|
494
|
+
|
|
495
|
+
user_id: Optional[str] = Field(default=None, description="""The user id.""")
|
|
496
|
+
state: Optional[dict[str, str]] = Field(
|
|
497
|
+
default=None, description="""The state of the session."""
|
|
498
|
+
)
|
|
499
|
+
app_name: Optional[str] = Field(
|
|
500
|
+
default=None,
|
|
501
|
+
description="""The name of the app, used for local ADK agent run Runner and Session.""",
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
class SessionInputDict(TypedDict, total=False):
|
|
506
|
+
"""Input to initialize a session and run an agent, used for agent evaluation."""
|
|
507
|
+
|
|
508
|
+
user_id: Optional[str]
|
|
509
|
+
"""The user id."""
|
|
510
|
+
|
|
511
|
+
state: Optional[dict[str, str]]
|
|
512
|
+
"""The state of the session."""
|
|
513
|
+
|
|
514
|
+
app_name: Optional[str]
|
|
515
|
+
"""The name of the app, used for local ADK agent run Runner and Session."""
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
SessionInputOrDict = Union[SessionInput, SessionInputDict]
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
class UserScenario(_common.BaseModel):
|
|
522
|
+
"""User scenario to help simulate multi-turn agent run results."""
|
|
523
|
+
|
|
524
|
+
starting_prompt: Optional[str] = Field(
|
|
525
|
+
default=None,
|
|
526
|
+
description="""Starting prompt for the conversation between simulated user and agent under the test.""",
|
|
527
|
+
)
|
|
528
|
+
conversation_plan: Optional[str] = Field(
|
|
529
|
+
default=None,
|
|
530
|
+
description="""Conversation plan to drive multi-turn agent run and get simulated agent eval dataset.""",
|
|
531
|
+
)
|
|
532
|
+
test_case_title: Optional[str] = Field(
|
|
533
|
+
default=None,
|
|
534
|
+
description="""Represents a short 3-5 word title for eval test case.""",
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
class UserScenarioDict(TypedDict, total=False):
|
|
539
|
+
"""User scenario to help simulate multi-turn agent run results."""
|
|
540
|
+
|
|
541
|
+
starting_prompt: Optional[str]
|
|
542
|
+
"""Starting prompt for the conversation between simulated user and agent under the test."""
|
|
543
|
+
|
|
544
|
+
conversation_plan: Optional[str]
|
|
545
|
+
"""Conversation plan to drive multi-turn agent run and get simulated agent eval dataset."""
|
|
546
|
+
|
|
547
|
+
test_case_title: Optional[str]
|
|
548
|
+
"""Represents a short 3-5 word title for eval test case."""
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
UserScenarioOrDict = Union[UserScenario, UserScenarioDict]
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
class UserScenarioGenerationConfig(_common.BaseModel):
|
|
555
|
+
"""User scenario generation configuration."""
|
|
556
|
+
|
|
557
|
+
model_name: Optional[str] = Field(
|
|
558
|
+
default=None,
|
|
559
|
+
description="""Optional. The model name to use for generation. It can be model name, e.g. "gemini-3-pro-preview". or the fully qualified name of the publisher model or endpoint. Publisher model format: `projects/{project}/locations/{location}/publishers/*/models/*` Endpoint format: `projects/{project}/locations/{location}/endpoints/{endpoint}`""",
|
|
560
|
+
)
|
|
561
|
+
count: Optional[int] = Field(
|
|
562
|
+
default=None,
|
|
563
|
+
description="""The number of user scenarios to generate. The maximum number of scenarios that can be generated is 100.""",
|
|
564
|
+
)
|
|
565
|
+
generation_instruction: Optional[str] = Field(
|
|
566
|
+
default=None,
|
|
567
|
+
description="""Instruction to guide the conversation scenario generation.""",
|
|
568
|
+
)
|
|
569
|
+
environment_context: Optional[str] = Field(
|
|
570
|
+
default=None,
|
|
571
|
+
description="""Environment context to drive simulation. For example, for a QA agent, this could be the docs queried by the tools.""",
|
|
572
|
+
)
|
|
573
|
+
environment_data: Optional[str] = Field(
|
|
574
|
+
default=None, description="""Optional. Environment data in string type."""
|
|
575
|
+
)
|
|
576
|
+
simulation_instruction: Optional[str] = Field(
|
|
577
|
+
default=None,
|
|
578
|
+
description="""Optional. Simulation instruction to guide the user scenario generation.""",
|
|
579
|
+
)
|
|
580
|
+
user_scenario_count: Optional[int] = Field(
|
|
581
|
+
default=None,
|
|
582
|
+
description="""Required. The number of user scenarios to generate. The maximum number of scenarios that can be generated is 100.""",
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
class UserScenarioGenerationConfigDict(TypedDict, total=False):
|
|
587
|
+
"""User scenario generation configuration."""
|
|
588
|
+
|
|
589
|
+
model_name: Optional[str]
|
|
590
|
+
"""Optional. The model name to use for generation. It can be model name, e.g. "gemini-3-pro-preview". or the fully qualified name of the publisher model or endpoint. Publisher model format: `projects/{project}/locations/{location}/publishers/*/models/*` Endpoint format: `projects/{project}/locations/{location}/endpoints/{endpoint}`"""
|
|
591
|
+
|
|
592
|
+
count: Optional[int]
|
|
593
|
+
"""The number of user scenarios to generate. The maximum number of scenarios that can be generated is 100."""
|
|
594
|
+
|
|
595
|
+
generation_instruction: Optional[str]
|
|
596
|
+
"""Instruction to guide the conversation scenario generation."""
|
|
597
|
+
|
|
598
|
+
environment_context: Optional[str]
|
|
599
|
+
"""Environment context to drive simulation. For example, for a QA agent, this could be the docs queried by the tools."""
|
|
600
|
+
|
|
601
|
+
environment_data: Optional[str]
|
|
602
|
+
"""Optional. Environment data in string type."""
|
|
603
|
+
|
|
604
|
+
simulation_instruction: Optional[str]
|
|
605
|
+
"""Optional. Simulation instruction to guide the user scenario generation."""
|
|
606
|
+
|
|
607
|
+
user_scenario_count: Optional[int]
|
|
608
|
+
"""Required. The number of user scenarios to generate. The maximum number of scenarios that can be generated is 100."""
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
UserScenarioGenerationConfigOrDict = Union[
|
|
612
|
+
UserScenarioGenerationConfig, UserScenarioGenerationConfigDict
|
|
613
|
+
]
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
class UserSimulatorConfig(_common.BaseModel):
|
|
617
|
+
"""Configuration for a user simulator.
|
|
618
|
+
|
|
619
|
+
Uses an LLM to generate multi-turn messages that simulate a user.
|
|
620
|
+
"""
|
|
621
|
+
|
|
622
|
+
model_name: Optional[str] = Field(
|
|
623
|
+
default=None,
|
|
624
|
+
description="""The model name to get next user message for multi-turn agent run.""",
|
|
625
|
+
)
|
|
626
|
+
model_configuration: Optional[genai_types.GenerateContentConfig] = Field(
|
|
627
|
+
default=None, description="""The configuration for the model."""
|
|
628
|
+
)
|
|
629
|
+
max_turn: Optional[int] = Field(
|
|
630
|
+
default=None,
|
|
631
|
+
description="""Maximum number of invocations allowed by the multi-turn agent
|
|
632
|
+
running. This property allows us to stop a run-off conversation
|
|
633
|
+
where the agent and the user simulator get into a never ending loop.
|
|
634
|
+
The initial fixed prompt is also counted as an invocation.""",
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
class UserSimulatorConfigDict(TypedDict, total=False):
|
|
639
|
+
"""Configuration for a user simulator.
|
|
640
|
+
|
|
641
|
+
Uses an LLM to generate multi-turn messages that simulate a user.
|
|
642
|
+
"""
|
|
643
|
+
|
|
644
|
+
model_name: Optional[str]
|
|
645
|
+
"""The model name to get next user message for multi-turn agent run."""
|
|
646
|
+
|
|
647
|
+
model_configuration: Optional[genai_types.GenerateContentConfig]
|
|
648
|
+
"""The configuration for the model."""
|
|
649
|
+
|
|
650
|
+
max_turn: Optional[int]
|
|
651
|
+
"""Maximum number of invocations allowed by the multi-turn agent
|
|
652
|
+
running. This property allows us to stop a run-off conversation
|
|
653
|
+
where the agent and the user simulator get into a never ending loop.
|
|
654
|
+
The initial fixed prompt is also counted as an invocation."""
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
UserSimulatorConfigOrDict = Union[UserSimulatorConfig, UserSimulatorConfigDict]
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
class Event(_common.BaseModel):
|
|
661
|
+
"""Represents an event in a conversation between agents and users.
|
|
662
|
+
|
|
663
|
+
It is used to store the content of the conversation, as well as the actions
|
|
664
|
+
taken by the agents like function calls, function responses, intermediate NL
|
|
665
|
+
responses etc.
|
|
666
|
+
"""
|
|
667
|
+
|
|
668
|
+
event_id: Optional[str] = Field(
|
|
669
|
+
default=None, description="""Unique identifier for the agent event."""
|
|
670
|
+
)
|
|
671
|
+
content: Optional[genai_types.Content] = Field(
|
|
672
|
+
default=None, description="""Content of the event."""
|
|
673
|
+
)
|
|
674
|
+
creation_timestamp: Optional[datetime.datetime] = Field(
|
|
675
|
+
default=None, description="""The creation timestamp of the event."""
|
|
676
|
+
)
|
|
677
|
+
author: Optional[str] = Field(
|
|
678
|
+
default=None, description="""Name of the entity that produced the event."""
|
|
679
|
+
)
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
class EventDict(TypedDict, total=False):
|
|
683
|
+
"""Represents an event in a conversation between agents and users.
|
|
684
|
+
|
|
685
|
+
It is used to store the content of the conversation, as well as the actions
|
|
686
|
+
taken by the agents like function calls, function responses, intermediate NL
|
|
687
|
+
responses etc.
|
|
688
|
+
"""
|
|
689
|
+
|
|
690
|
+
event_id: Optional[str]
|
|
691
|
+
"""Unique identifier for the agent event."""
|
|
692
|
+
|
|
693
|
+
content: Optional[genai_types.Content]
|
|
694
|
+
"""Content of the event."""
|
|
695
|
+
|
|
696
|
+
creation_timestamp: Optional[datetime.datetime]
|
|
697
|
+
"""The creation timestamp of the event."""
|
|
698
|
+
|
|
699
|
+
author: Optional[str]
|
|
700
|
+
"""Name of the entity that produced the event."""
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
EventOrDict = Union[Event, EventDict]
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
class Message(_common.BaseModel):
|
|
707
|
+
"""Represents a single message turn in a conversation."""
|
|
708
|
+
|
|
709
|
+
turn_id: Optional[str] = Field(
|
|
710
|
+
default=None, description="""Unique identifier for the message turn."""
|
|
711
|
+
)
|
|
712
|
+
content: Optional[genai_types.Content] = Field(
|
|
713
|
+
default=None, description="""Content of the message, including function call."""
|
|
714
|
+
)
|
|
715
|
+
creation_timestamp: Optional[datetime.datetime] = Field(
|
|
716
|
+
default=None,
|
|
717
|
+
description="""Timestamp indicating when the message was created.""",
|
|
718
|
+
)
|
|
719
|
+
author: Optional[str] = Field(
|
|
720
|
+
default=None, description="""Name of the entity that produced the message."""
|
|
721
|
+
)
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
class MessageDict(TypedDict, total=False):
|
|
725
|
+
"""Represents a single message turn in a conversation."""
|
|
726
|
+
|
|
727
|
+
turn_id: Optional[str]
|
|
728
|
+
"""Unique identifier for the message turn."""
|
|
729
|
+
|
|
730
|
+
content: Optional[genai_types.Content]
|
|
731
|
+
"""Content of the message, including function call."""
|
|
732
|
+
|
|
733
|
+
creation_timestamp: Optional[datetime.datetime]
|
|
734
|
+
"""Timestamp indicating when the message was created."""
|
|
735
|
+
|
|
736
|
+
author: Optional[str]
|
|
737
|
+
"""Name of the entity that produced the message."""
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
MessageOrDict = Union[Message, MessageDict]
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
class Events(_common.BaseModel):
|
|
744
|
+
"""This field is experimental and will be removed in future versions.
|
|
745
|
+
|
|
746
|
+
Represents a list of events for an agent.
|
|
747
|
+
"""
|
|
748
|
+
|
|
749
|
+
event: Optional[list[genai_types.Content]] = Field(
|
|
750
|
+
default=None, description="""A list of events."""
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
class EventsDict(TypedDict, total=False):
|
|
755
|
+
"""This field is experimental and will be removed in future versions.
|
|
756
|
+
|
|
757
|
+
Represents a list of events for an agent.
|
|
758
|
+
"""
|
|
759
|
+
|
|
760
|
+
event: Optional[list[genai_types.Content]]
|
|
761
|
+
"""A list of events."""
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
EventsOrDict = Union[Events, EventsDict]
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
class InstanceDataContents(_common.BaseModel):
|
|
768
|
+
"""This field is experimental and will be removed in future versions.
|
|
769
|
+
|
|
770
|
+
List of standard Content messages from Gemini API.
|
|
771
|
+
"""
|
|
772
|
+
|
|
773
|
+
contents: Optional[list[genai_types.Content]] = Field(
|
|
774
|
+
default=None, description="""Repeated contents."""
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
class InstanceDataContentsDict(TypedDict, total=False):
|
|
779
|
+
"""This field is experimental and will be removed in future versions.
|
|
780
|
+
|
|
781
|
+
List of standard Content messages from Gemini API.
|
|
782
|
+
"""
|
|
783
|
+
|
|
784
|
+
contents: Optional[list[genai_types.Content]]
|
|
785
|
+
"""Repeated contents."""
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
InstanceDataContentsOrDict = Union[InstanceDataContents, InstanceDataContentsDict]
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
class InstanceData(_common.BaseModel):
|
|
792
|
+
"""This field is experimental and will be removed in future versions.
|
|
793
|
+
|
|
794
|
+
Instance data used to populate placeholders in a metric prompt template.
|
|
795
|
+
"""
|
|
796
|
+
|
|
797
|
+
text: Optional[str] = Field(default=None, description="""Text data.""")
|
|
798
|
+
contents: Optional[InstanceDataContents] = Field(
|
|
799
|
+
default=None, description="""List of Gemini content data."""
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
class InstanceDataDict(TypedDict, total=False):
|
|
804
|
+
"""This field is experimental and will be removed in future versions.
|
|
805
|
+
|
|
806
|
+
Instance data used to populate placeholders in a metric prompt template.
|
|
807
|
+
"""
|
|
808
|
+
|
|
809
|
+
text: Optional[str]
|
|
810
|
+
"""Text data."""
|
|
811
|
+
|
|
812
|
+
contents: Optional[InstanceDataContentsDict]
|
|
813
|
+
"""List of Gemini content data."""
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
InstanceDataOrDict = Union[InstanceData, InstanceDataDict]
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
class Tools(_common.BaseModel):
|
|
820
|
+
"""This field is experimental and will be removed in future versions.
|
|
821
|
+
|
|
822
|
+
Represents a list of tools for an agent.
|
|
823
|
+
"""
|
|
824
|
+
|
|
825
|
+
tool: Optional[list[genai_types.Tool]] = Field(
|
|
826
|
+
default=None,
|
|
827
|
+
description="""List of tools: each tool can have multiple function declarations.""",
|
|
828
|
+
)
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
class ToolsDict(TypedDict, total=False):
|
|
832
|
+
"""This field is experimental and will be removed in future versions.
|
|
833
|
+
|
|
834
|
+
Represents a list of tools for an agent.
|
|
835
|
+
"""
|
|
836
|
+
|
|
837
|
+
tool: Optional[list[genai_types.Tool]]
|
|
838
|
+
"""List of tools: each tool can have multiple function declarations."""
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
ToolsOrDict = Union[Tools, ToolsDict]
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
class RubricContentProperty(_common.BaseModel):
|
|
845
|
+
"""Defines criteria based on a specific property."""
|
|
846
|
+
|
|
847
|
+
description: Optional[str] = Field(
|
|
848
|
+
default=None,
|
|
849
|
+
description="""Description of the property being evaluated.
|
|
850
|
+
Example: "The model's response is grammatically correct." """,
|
|
851
|
+
)
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
class RubricContentPropertyDict(TypedDict, total=False):
|
|
855
|
+
"""Defines criteria based on a specific property."""
|
|
856
|
+
|
|
857
|
+
description: Optional[str]
|
|
858
|
+
"""Description of the property being evaluated.
|
|
859
|
+
Example: "The model's response is grammatically correct." """
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
RubricContentPropertyOrDict = Union[RubricContentProperty, RubricContentPropertyDict]
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
class RubricContent(_common.BaseModel):
|
|
866
|
+
"""Content of the rubric, defining the testable criteria."""
|
|
867
|
+
|
|
868
|
+
property: Optional[RubricContentProperty] = Field(
|
|
869
|
+
default=None,
|
|
870
|
+
description="""Evaluation criteria based on a specific property.""",
|
|
871
|
+
)
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
class RubricContentDict(TypedDict, total=False):
|
|
875
|
+
"""Content of the rubric, defining the testable criteria."""
|
|
876
|
+
|
|
877
|
+
property: Optional[RubricContentPropertyDict]
|
|
878
|
+
"""Evaluation criteria based on a specific property."""
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
RubricContentOrDict = Union[RubricContent, RubricContentDict]
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
class Rubric(_common.BaseModel):
|
|
885
|
+
"""Message representing a single testable criterion for evaluation.
|
|
886
|
+
|
|
887
|
+
One input prompt could have multiple rubrics.
|
|
888
|
+
"""
|
|
889
|
+
|
|
890
|
+
rubric_id: Optional[str] = Field(
|
|
891
|
+
default=None,
|
|
892
|
+
description="""Required. Unique identifier for the rubric.
|
|
893
|
+
This ID is used to refer to this rubric, e.g., in RubricVerdict.""",
|
|
894
|
+
)
|
|
895
|
+
content: Optional[RubricContent] = Field(
|
|
896
|
+
default=None,
|
|
897
|
+
description="""Required. The actual testable criteria for the rubric.""",
|
|
898
|
+
)
|
|
899
|
+
type: Optional[str] = Field(
|
|
900
|
+
default=None,
|
|
901
|
+
description="""Optional. A type designator for the rubric, which can inform how it's
|
|
902
|
+
evaluated or interpreted by systems or users.
|
|
903
|
+
It's recommended to use consistent, well-defined, upper snake_case strings.
|
|
904
|
+
Examples: "SUMMARIZATION_QUALITY", "SAFETY_HARMFUL_CONTENT",
|
|
905
|
+
"INSTRUCTION_ADHERENCE".""",
|
|
906
|
+
)
|
|
907
|
+
importance: Optional[Importance] = Field(
|
|
908
|
+
default=None,
|
|
909
|
+
description="""Optional. The relative importance of this rubric.""",
|
|
910
|
+
)
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
class RubricDict(TypedDict, total=False):
|
|
914
|
+
"""Message representing a single testable criterion for evaluation.
|
|
915
|
+
|
|
916
|
+
One input prompt could have multiple rubrics.
|
|
917
|
+
"""
|
|
918
|
+
|
|
919
|
+
rubric_id: Optional[str]
|
|
920
|
+
"""Required. Unique identifier for the rubric.
|
|
921
|
+
This ID is used to refer to this rubric, e.g., in RubricVerdict."""
|
|
922
|
+
|
|
923
|
+
content: Optional[RubricContentDict]
|
|
924
|
+
"""Required. The actual testable criteria for the rubric."""
|
|
925
|
+
|
|
926
|
+
type: Optional[str]
|
|
927
|
+
"""Optional. A type designator for the rubric, which can inform how it's
|
|
928
|
+
evaluated or interpreted by systems or users.
|
|
929
|
+
It's recommended to use consistent, well-defined, upper snake_case strings.
|
|
930
|
+
Examples: "SUMMARIZATION_QUALITY", "SAFETY_HARMFUL_CONTENT",
|
|
931
|
+
"INSTRUCTION_ADHERENCE"."""
|
|
932
|
+
|
|
933
|
+
importance: Optional[Importance]
|
|
934
|
+
"""Optional. The relative importance of this rubric."""
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
RubricOrDict = Union[Rubric, RubricDict]
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
class RubricVerdict(_common.BaseModel):
|
|
941
|
+
"""Represents the verdict of an evaluation against a single rubric."""
|
|
942
|
+
|
|
943
|
+
evaluated_rubric: Optional[Rubric] = Field(
|
|
944
|
+
default=None,
|
|
945
|
+
description="""Required. The full rubric definition that was evaluated.
|
|
946
|
+
Storing this ensures the verdict is self-contained and understandable,
|
|
947
|
+
especially if the original rubric definition changes or was dynamically
|
|
948
|
+
generated.""",
|
|
949
|
+
)
|
|
950
|
+
verdict: Optional[bool] = Field(
|
|
951
|
+
default=None,
|
|
952
|
+
description="""Required. Outcome of the evaluation against the rubric, represented as a
|
|
953
|
+
boolean. `true` indicates a "Pass", `false` indicates a "Fail".""",
|
|
954
|
+
)
|
|
955
|
+
reasoning: Optional[str] = Field(
|
|
956
|
+
default=None,
|
|
957
|
+
description="""Optional. Human-readable reasoning or explanation for the verdict.
|
|
958
|
+
This can include specific examples or details from the evaluated content
|
|
959
|
+
that justify the given verdict.""",
|
|
960
|
+
)
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
class RubricVerdictDict(TypedDict, total=False):
|
|
964
|
+
"""Represents the verdict of an evaluation against a single rubric."""
|
|
965
|
+
|
|
966
|
+
evaluated_rubric: Optional[RubricDict]
|
|
967
|
+
"""Required. The full rubric definition that was evaluated.
|
|
968
|
+
Storing this ensures the verdict is self-contained and understandable,
|
|
969
|
+
especially if the original rubric definition changes or was dynamically
|
|
970
|
+
generated."""
|
|
971
|
+
|
|
972
|
+
verdict: Optional[bool]
|
|
973
|
+
"""Required. Outcome of the evaluation against the rubric, represented as a
|
|
974
|
+
boolean. `true` indicates a "Pass", `false` indicates a "Fail"."""
|
|
975
|
+
|
|
976
|
+
reasoning: Optional[str]
|
|
977
|
+
"""Optional. Human-readable reasoning or explanation for the verdict.
|
|
978
|
+
This can include specific examples or details from the evaluated content
|
|
979
|
+
that justify the given verdict."""
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
RubricVerdictOrDict = Union[RubricVerdict, RubricVerdictDict]
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
class CandidateResult(_common.BaseModel):
|
|
986
|
+
"""Result for a single candidate."""
|
|
987
|
+
|
|
988
|
+
candidate: Optional[str] = Field(
|
|
989
|
+
default=None,
|
|
990
|
+
description="""The candidate that is being evaluated. The value is the same as the candidate name in the EvaluationRequest.""",
|
|
991
|
+
)
|
|
992
|
+
metric: Optional[str] = Field(
|
|
993
|
+
default=None, description="""The metric that was evaluated."""
|
|
994
|
+
)
|
|
995
|
+
score: Optional[float] = Field(
|
|
996
|
+
default=None, description="""The score of the metric."""
|
|
997
|
+
)
|
|
998
|
+
explanation: Optional[str] = Field(
|
|
999
|
+
default=None, description="""The explanation for the metric."""
|
|
1000
|
+
)
|
|
1001
|
+
rubric_verdicts: Optional[list[RubricVerdict]] = Field(
|
|
1002
|
+
default=None, description="""The rubric verdicts for the metric."""
|
|
1003
|
+
)
|
|
1004
|
+
additional_results: Optional[dict[str, Any]] = Field(
|
|
1005
|
+
default=None, description="""Additional results for the metric."""
|
|
1006
|
+
)
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
class CandidateResultDict(TypedDict, total=False):
|
|
1010
|
+
"""Result for a single candidate."""
|
|
1011
|
+
|
|
1012
|
+
candidate: Optional[str]
|
|
1013
|
+
"""The candidate that is being evaluated. The value is the same as the candidate name in the EvaluationRequest."""
|
|
1014
|
+
|
|
1015
|
+
metric: Optional[str]
|
|
1016
|
+
"""The metric that was evaluated."""
|
|
1017
|
+
|
|
1018
|
+
score: Optional[float]
|
|
1019
|
+
"""The score of the metric."""
|
|
1020
|
+
|
|
1021
|
+
explanation: Optional[str]
|
|
1022
|
+
"""The explanation for the metric."""
|
|
1023
|
+
|
|
1024
|
+
rubric_verdicts: Optional[list[RubricVerdictDict]]
|
|
1025
|
+
"""The rubric verdicts for the metric."""
|
|
1026
|
+
|
|
1027
|
+
additional_results: Optional[dict[str, Any]]
|
|
1028
|
+
"""Additional results for the metric."""
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
CandidateResultOrDict = Union[CandidateResult, CandidateResultDict]
|