gooddata-eval 1.80.1.dev3__py3-none-any.whl → 1.80.1.dev5__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.
- gooddata_eval/cli/agentic_runner.py +28 -10
- gooddata_eval/cli/main.py +6 -1
- gooddata_eval/core/_retry.py +27 -0
- gooddata_eval/core/agentic/_search_expectation.py +310 -0
- gooddata_eval/core/agentic/alert_skill.py +20 -2
- gooddata_eval/core/agentic/search_tool.py +421 -89
- gooddata_eval/core/agentic/visualization.py +14 -5
- gooddata_eval/core/catalog/__init__.py +1 -0
- gooddata_eval/core/catalog/evaluate.py +268 -0
- gooddata_eval/core/catalog/http_client.py +98 -0
- gooddata_eval/core/dataset/langfuse_source.py +31 -4
- gooddata_eval/core/evaluators/__init__.py +4 -2
- gooddata_eval/core/evaluators/_text_utils.py +34 -1
- gooddata_eval/core/evaluators/catalog_metadata.py +200 -0
- gooddata_eval/core/evaluators/takeaway.py +12 -24
- gooddata_eval/core/models.py +18 -1
- gooddata_eval/core/takeaway/http_client.py +4 -25
- {gooddata_eval-1.80.1.dev3.dist-info → gooddata_eval-1.80.1.dev5.dist-info}/METADATA +54 -6
- {gooddata_eval-1.80.1.dev3.dist-info → gooddata_eval-1.80.1.dev5.dist-info}/RECORD +22 -17
- {gooddata_eval-1.80.1.dev3.dist-info → gooddata_eval-1.80.1.dev5.dist-info}/WHEEL +0 -0
- {gooddata_eval-1.80.1.dev3.dist-info → gooddata_eval-1.80.1.dev5.dist-info}/entry_points.txt +0 -0
- {gooddata_eval-1.80.1.dev3.dist-info → gooddata_eval-1.80.1.dev5.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -11,6 +11,7 @@ from typing import Any, TypedDict
|
|
|
11
11
|
|
|
12
12
|
from gooddata_eval.core.agentic._gate import DEFAULT_GATE, EvalGate, normalize_gate
|
|
13
13
|
from gooddata_eval.core.agentic._langfuse import make_langfuse_client
|
|
14
|
+
from gooddata_eval.core.agentic._search_expectation import SEARCH_ARGUMENT_KEYS
|
|
14
15
|
from gooddata_eval.core.agentic._trace_linker import BackgroundTraceLinker, SubmitTraceLink, run_trace_link_inline
|
|
15
16
|
from gooddata_eval.core.agentic.alert_skill import evaluate_agentic_alert_skill
|
|
16
17
|
from gooddata_eval.core.agentic.anomaly_detection import evaluate_agentic_anomaly_detection
|
|
@@ -81,7 +82,8 @@ UNGATED_AGENTIC_TEST_KINDS = frozenset({"agentic_conversation"})
|
|
|
81
82
|
# reads like a model regression.
|
|
82
83
|
#
|
|
83
84
|
# agentic_general_question, agentic_guardrail answer questions only, no tool writes
|
|
84
|
-
# agentic_search search_objects, read-only by definition
|
|
85
|
+
# agentic_search search_objects, read-only by definition; an item
|
|
86
|
+
# with setup_turns runs serially (item_runs_in_parallel)
|
|
85
87
|
# vis_agentic, agentic_visualization visualizations come back as AAC proposals
|
|
86
88
|
# in the chat response; nothing is persisted
|
|
87
89
|
# and neither module has cleanup code
|
|
@@ -115,6 +117,18 @@ def runs_in_parallel(test_kind: str) -> bool:
|
|
|
115
117
|
return test_kind in PARALLEL_SAFE_TEST_KINDS
|
|
116
118
|
|
|
117
119
|
|
|
120
|
+
def item_runs_in_parallel(item: DatasetItem) -> bool:
|
|
121
|
+
"""True for an item of a cleared kind that sends nothing the clearance does not cover.
|
|
122
|
+
|
|
123
|
+
``agentic_search`` is cleared for its search. An item's ``setup_turns`` are free text sent before the question,
|
|
124
|
+
and nothing stops one from asking the agent to save something, so such an item runs serially.
|
|
125
|
+
"""
|
|
126
|
+
if not runs_in_parallel(item.test_kind):
|
|
127
|
+
return False
|
|
128
|
+
eo = item.expected_output
|
|
129
|
+
return not (item.test_kind == "agentic_search" and isinstance(eo, dict) and "setup_turns" in eo)
|
|
130
|
+
|
|
131
|
+
|
|
118
132
|
def _parse_visualization_expected(expected_output: Any) -> list[CreatedVisualization]:
|
|
119
133
|
"""Parse expected_output into a list of CreatedVisualization candidates.
|
|
120
134
|
|
|
@@ -253,15 +267,18 @@ def _dispatch_agentic(
|
|
|
253
267
|
**lf_kw,
|
|
254
268
|
)
|
|
255
269
|
elif kind == "agentic_search":
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
270
|
+
if not isinstance(eo, dict):
|
|
271
|
+
raise ValueError(f"agentic_search expected_output must be an object, got {eo!r}")
|
|
272
|
+
eo_dict = eo
|
|
273
|
+
# Anything but bare search_objects arguments is parsed as an item, so an unknown key fails it.
|
|
274
|
+
is_item_shape = "tool_call" in eo_dict or not eo_dict.keys() <= SEARCH_ARGUMENT_KEYS
|
|
259
275
|
return evaluate_agentic_search_tool(
|
|
260
276
|
host=host,
|
|
261
277
|
token=token,
|
|
262
278
|
workspace_id=workspace_id,
|
|
263
279
|
question=item.question,
|
|
264
|
-
expected_tool_call=
|
|
280
|
+
expected_tool_call=None if is_item_shape else eo_dict,
|
|
281
|
+
expected_output=eo_dict if is_item_shape else None,
|
|
265
282
|
k=k,
|
|
266
283
|
gate=gate,
|
|
267
284
|
agent_id=agent_id,
|
|
@@ -485,7 +502,8 @@ def run_agentic_items(
|
|
|
485
502
|
) -> EvalReport:
|
|
486
503
|
"""Run agentic items through evaluate_agentic_* and return an EvalReport.
|
|
487
504
|
|
|
488
|
-
``concurrency`` > 1 runs PARALLEL_SAFE_TEST_KINDS items simultaneously
|
|
505
|
+
``concurrency`` > 1 runs PARALLEL_SAFE_TEST_KINDS items simultaneously, except those
|
|
506
|
+
``item_runs_in_parallel`` holds back.
|
|
489
507
|
WORKSPACE_MUTATING_TEST_KINDS items always run one at a time, and in a separate phase
|
|
490
508
|
from the parallel ones -- a metric being created and dropped mid-run would otherwise be
|
|
491
509
|
visible to a catalog-reading item running alongside it.
|
|
@@ -637,13 +655,13 @@ def run_agentic_items(
|
|
|
637
655
|
concurrency = max(1, concurrency)
|
|
638
656
|
indexed = list(enumerate(items, start=1))
|
|
639
657
|
if concurrency > 1:
|
|
640
|
-
parallel = [(i, it) for i, it in indexed if
|
|
641
|
-
serial = [(i, it) for i, it in indexed if not
|
|
658
|
+
parallel = [(i, it) for i, it in indexed if item_runs_in_parallel(it)]
|
|
659
|
+
serial = [(i, it) for i, it in indexed if not item_runs_in_parallel(it)]
|
|
642
660
|
if not parallel and serial:
|
|
643
661
|
blocked = ", ".join(sorted({it.test_kind for _, it in serial}))
|
|
644
662
|
print(
|
|
645
|
-
f"warning: --concurrency {concurrency} has no effect here; every item is a "
|
|
646
|
-
|
|
663
|
+
f"warning: --concurrency {concurrency} has no effect here; every item ({blocked}) is a "
|
|
664
|
+
"workspace-mutating kind or a search item with setup turns, and those always run one at a time.",
|
|
647
665
|
file=sys.stderr,
|
|
648
666
|
)
|
|
649
667
|
else:
|
gooddata_eval/cli/main.py
CHANGED
|
@@ -15,6 +15,7 @@ from rich.console import Console
|
|
|
15
15
|
from rich.table import Table
|
|
16
16
|
|
|
17
17
|
from gooddata_eval.cli.agentic_runner import AGENTIC_TEST_KINDS, UNGATED_AGENTIC_TEST_KINDS, run_agentic_items
|
|
18
|
+
from gooddata_eval.core.catalog.http_client import CatalogMetadataClient
|
|
18
19
|
from gooddata_eval.core.chat.sse_client import ChatClient, set_default_item_timeout, set_default_turn_timeout
|
|
19
20
|
from gooddata_eval.core.config import (
|
|
20
21
|
DEFAULT_GATE,
|
|
@@ -48,7 +49,8 @@ class _RoutingBackend:
|
|
|
48
49
|
"""Dispatch each item to the right backend by test_kind.
|
|
49
50
|
|
|
50
51
|
Kinds in `by_kind` go to their dedicated endpoint client (`dashboard_summary` to the
|
|
51
|
-
summary endpoint, `document_takeaway` to the takeaway endpoint
|
|
52
|
+
summary endpoint, `document_takeaway` to the takeaway endpoint, `catalog_metadata` to the
|
|
53
|
+
Analytics Catalog generate endpoints); everything else uses
|
|
52
54
|
the conversational chat endpoint.
|
|
53
55
|
"""
|
|
54
56
|
|
|
@@ -620,6 +622,9 @@ def _run(config: RunConfig) -> int:
|
|
|
620
622
|
"document_takeaway": TakeawayClient(
|
|
621
623
|
host=config.host, token=config.token, workspace_id=config.workspace_id
|
|
622
624
|
),
|
|
625
|
+
"catalog_metadata": CatalogMetadataClient(
|
|
626
|
+
host=config.host, token=config.token, workspace_id=config.workspace_id
|
|
627
|
+
),
|
|
623
628
|
},
|
|
624
629
|
)
|
|
625
630
|
try:
|
gooddata_eval/core/_retry.py
CHANGED
|
@@ -13,6 +13,8 @@ import time
|
|
|
13
13
|
from collections.abc import Callable
|
|
14
14
|
from typing import TypeVar
|
|
15
15
|
|
|
16
|
+
import httpx
|
|
17
|
+
|
|
16
18
|
_log = logging.getLogger(__name__)
|
|
17
19
|
|
|
18
20
|
T = TypeVar("T")
|
|
@@ -24,6 +26,31 @@ T = TypeVar("T")
|
|
|
24
26
|
RETRYABLE_STATUS_CODES: frozenset[int] = frozenset({429, 500, 502, 503, 504})
|
|
25
27
|
|
|
26
28
|
|
|
29
|
+
# Failures of the single-shot endpoint clients (takeaway, catalog) that say nothing about the
|
|
30
|
+
# request. A read timeout is left out: the server was computing, and retrying spends the whole
|
|
31
|
+
# timeout again on every attempt.
|
|
32
|
+
RETRYABLE_TRANSPORT_ERRORS = (httpx.ConnectError, httpx.ConnectTimeout, httpx.RemoteProtocolError, httpx.PoolTimeout)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def is_retryable_request_error(exc: Exception) -> bool:
|
|
36
|
+
"""Whether a single-shot endpoint client retries this failure: a retryable status or transport error."""
|
|
37
|
+
if isinstance(exc, httpx.HTTPStatusError):
|
|
38
|
+
return exc.response.status_code in RETRYABLE_STATUS_CODES
|
|
39
|
+
return isinstance(exc, RETRYABLE_TRANSPORT_ERRORS)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_transient(exc: httpx.HTTPError) -> bool:
|
|
43
|
+
"""Whether a failure left after the client's retries says nothing about the request.
|
|
44
|
+
|
|
45
|
+
429, 5xx and transport failures (a read timeout included) are transient; any other 4xx
|
|
46
|
+
(flag off, no agent, invalid body) and an unsupported URL scheme are setup problems.
|
|
47
|
+
"""
|
|
48
|
+
if isinstance(exc, httpx.HTTPStatusError):
|
|
49
|
+
status = exc.response.status_code
|
|
50
|
+
return status == 429 or status >= 500
|
|
51
|
+
return isinstance(exc, httpx.TransportError) and not isinstance(exc, httpx.UnsupportedProtocol)
|
|
52
|
+
|
|
53
|
+
|
|
27
54
|
def int_env(name: str, default: int) -> int:
|
|
28
55
|
"""Read an int from the environment, falling back to ``default`` when unset or blank."""
|
|
29
56
|
raw = os.getenv(name)
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# (C) 2026 GoodData Corporation. All rights reserved.
|
|
2
|
+
"""The search-tool item: the expected ``search_objects`` arguments plus the checks an item opts into.
|
|
3
|
+
|
|
4
|
+
An item that carries only ``tool_call``, or reaches the runner as the bare arguments, is scored on
|
|
5
|
+
``tool_selection`` (gating) and ``tool_correctness`` (informing). Each other key adds one check, and a
|
|
6
|
+
key the module does not know is rejected, so a misspelt check cannot read as a pass.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from gooddata_eval.core.models import ChatResult, ToolCallEvent
|
|
16
|
+
|
|
17
|
+
SEARCH_TOOL = "search_objects"
|
|
18
|
+
|
|
19
|
+
# The keys of an item's expected output beside ``tool_call``. Public so a caller holding a raw item can
|
|
20
|
+
# tell the options shape from bare arguments.
|
|
21
|
+
SEARCH_OPTION_KEYS = frozenset(
|
|
22
|
+
{
|
|
23
|
+
"expected_objects",
|
|
24
|
+
"expect_widget",
|
|
25
|
+
"required_tools",
|
|
26
|
+
"forbidden_tools",
|
|
27
|
+
"search_required",
|
|
28
|
+
"answer_rubric",
|
|
29
|
+
"expected_limit",
|
|
30
|
+
"no_raw_ids",
|
|
31
|
+
"setup_turns",
|
|
32
|
+
"report_only",
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
_KNOWN_KEYS = SEARCH_OPTION_KEYS | {"tool_call"}
|
|
36
|
+
# The search_objects parameters, and emit_widget, the old name of user_requested_search. An expected output with
|
|
37
|
+
# any other key is read as an item, so a misspelt check key fails it instead of passing as an argument.
|
|
38
|
+
SEARCH_ARGUMENT_KEYS = frozenset(
|
|
39
|
+
{"keywords", "object_types", "limit", "compatible_with_afm", "kda_eligible", "user_requested_search", "emit_widget"}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
_OBJECT_TYPES = frozenset(
|
|
43
|
+
{
|
|
44
|
+
"metric",
|
|
45
|
+
"fact",
|
|
46
|
+
"attribute",
|
|
47
|
+
"label",
|
|
48
|
+
"date_attribute",
|
|
49
|
+
"computed_attribute",
|
|
50
|
+
"dataset",
|
|
51
|
+
"date",
|
|
52
|
+
"parameter",
|
|
53
|
+
"visualization",
|
|
54
|
+
"dashboard",
|
|
55
|
+
"document",
|
|
56
|
+
"report",
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
# The agent's tools take an attribute by either of its ids, and search returns a date attribute with
|
|
60
|
+
# ``type`` attribute and ``final_type`` date_attribute, so these spellings name one object.
|
|
61
|
+
_ATTRIBUTE_TYPES = frozenset({"attribute", "label", "date_attribute"})
|
|
62
|
+
|
|
63
|
+
# A ``{type/id}`` chip is the UI's own syntax for a named object and renders as its title, also inside
|
|
64
|
+
# inline code. An id outside a chip reaches the user as raw text.
|
|
65
|
+
_CHIP = re.compile(r"\{[a-z_]+/[^{}\s]+\}")
|
|
66
|
+
_UUID = re.compile(r"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b", re.IGNORECASE)
|
|
67
|
+
_TYPED_ID = re.compile(rf"\b(?:{'|'.join(sorted(_OBJECT_TYPES))})/([A-Za-z0-9_](?:[A-Za-z0-9_.-]*[A-Za-z0-9_])?)")
|
|
68
|
+
# Prose pairs type words with a slash ("date/time", "label/value pairs"). Only an id with an underscore,
|
|
69
|
+
# a dot or a digit, as the workspace ids have, counts. A one-word id such as metric/revenue is not caught.
|
|
70
|
+
_ID_MARK = re.compile(r"[_.0-9]")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True)
|
|
74
|
+
class SearchExpectation:
|
|
75
|
+
"""What one item expects. Every field but ``tool_args`` is an opt-in check.
|
|
76
|
+
|
|
77
|
+
``setup_turns`` should only read the workspace (search, describe, an unsaved chart). The CLI runs an item with
|
|
78
|
+
setup turns in its serial phase, so a write cannot race another item, but nothing removes what it writes.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
tool_args: dict[str, Any] = field(default_factory=dict)
|
|
82
|
+
expected_objects: tuple[str, ...] = ()
|
|
83
|
+
expect_widget: bool | None = None
|
|
84
|
+
required_tools: tuple[str, ...] = ()
|
|
85
|
+
forbidden_tools: tuple[str, ...] = ()
|
|
86
|
+
search_required: bool = True
|
|
87
|
+
answer_rubric: tuple[str, ...] = ()
|
|
88
|
+
expected_limit: int | None = None
|
|
89
|
+
no_raw_ids: bool = False
|
|
90
|
+
setup_turns: tuple[str, ...] = ()
|
|
91
|
+
report_only: bool = False
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def has_turn_checks(self) -> bool:
|
|
95
|
+
"""Whether the item opts into a check of the scored turn. Each one is published as a score of its own."""
|
|
96
|
+
return bool(
|
|
97
|
+
self.expected_objects
|
|
98
|
+
or self.expect_widget is not None
|
|
99
|
+
or self.required_tools
|
|
100
|
+
or self.forbidden_tools
|
|
101
|
+
or self.answer_rubric
|
|
102
|
+
or self.expected_limit is not None
|
|
103
|
+
or self.no_raw_ids
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def has_checks(self) -> bool:
|
|
108
|
+
"""Whether the item opts into anything beyond ``tool_selection`` and ``tool_correctness``."""
|
|
109
|
+
return self.has_turn_checks or bool(self.setup_turns) or not self.search_required
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _string_list(key: str, value: Any) -> tuple[str, ...]:
|
|
113
|
+
# isinstance, not str(entry): an unquoted YAML `no` loads as False and would turn into the text "False".
|
|
114
|
+
if not isinstance(value, list) or not value:
|
|
115
|
+
raise ValueError(f"{key} must be a non-empty list of strings, got {value!r}")
|
|
116
|
+
if any(not isinstance(entry, str) or not entry.strip() for entry in value):
|
|
117
|
+
raise ValueError(f"{key} must hold non-empty strings only, got {value!r}")
|
|
118
|
+
return tuple(value)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _flag(key: str, value: Any) -> bool:
|
|
122
|
+
if not isinstance(value, bool):
|
|
123
|
+
raise ValueError(f"{key} must be true or false, got {value!r}")
|
|
124
|
+
return value
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _object_ref(ref: str) -> tuple[str, str]:
|
|
128
|
+
object_type, sep, object_id = ref.partition("/")
|
|
129
|
+
if not sep or object_type not in _OBJECT_TYPES or not object_id or object_id != object_id.strip():
|
|
130
|
+
raise ValueError(f"expected_objects entry must be '<type>/<id>' with a known type, got {ref!r}")
|
|
131
|
+
return object_type, object_id
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _tool_args(tool_call: Any) -> dict[str, Any]:
|
|
135
|
+
if not isinstance(tool_call, dict):
|
|
136
|
+
raise ValueError(f"tool_call must be an object, got {tool_call!r}")
|
|
137
|
+
name = tool_call.get("function_name")
|
|
138
|
+
if name is not None and name != SEARCH_TOOL:
|
|
139
|
+
raise ValueError(f"tool_call.function_name must be {SEARCH_TOOL!r}, got {name!r}")
|
|
140
|
+
return check_arguments(tool_call.get("function_arguments", {}))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def check_arguments(args: Any) -> dict[str, Any]:
|
|
144
|
+
"""The expected ``search_objects`` arguments, whichever way the item gives them.
|
|
145
|
+
|
|
146
|
+
Raises:
|
|
147
|
+
ValueError: The arguments are not an object, or ``compatible_with_afm`` is not lists of objects.
|
|
148
|
+
"""
|
|
149
|
+
if not isinstance(args, dict):
|
|
150
|
+
raise ValueError(f"tool_call.function_arguments must be an object, got {args!r}")
|
|
151
|
+
afm = args.get("compatible_with_afm")
|
|
152
|
+
if afm is not None and (
|
|
153
|
+
not isinstance(afm, dict)
|
|
154
|
+
or not set(afm) <= {"measures", "attributes"}
|
|
155
|
+
or any(value is not None and not isinstance(value, list) for value in afm.values())
|
|
156
|
+
or any(not isinstance(item, dict) for value in afm.values() for item in value or [])
|
|
157
|
+
):
|
|
158
|
+
raise ValueError(f"compatible_with_afm must hold lists of measure and attribute objects, got {afm!r}")
|
|
159
|
+
return dict(args)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def parse_expectation(expected_output: Any) -> SearchExpectation:
|
|
163
|
+
"""Read an item's whole expected output.
|
|
164
|
+
|
|
165
|
+
Raises:
|
|
166
|
+
ValueError: The expected output is not an object, names an unknown key, or holds a value the
|
|
167
|
+
run could not score. Raised before any request is sent.
|
|
168
|
+
"""
|
|
169
|
+
if not isinstance(expected_output, dict):
|
|
170
|
+
raise ValueError(f"expected_output must be an object, got {expected_output!r}")
|
|
171
|
+
unknown = sorted(set(expected_output) - _KNOWN_KEYS)
|
|
172
|
+
if unknown:
|
|
173
|
+
raise ValueError(f"expected_output has unknown keys {unknown}; known keys are {sorted(_KNOWN_KEYS)}")
|
|
174
|
+
raw = expected_output
|
|
175
|
+
tool_args = _tool_args(raw["tool_call"]) if "tool_call" in raw else {}
|
|
176
|
+
|
|
177
|
+
expected_objects: tuple[str, ...] = ()
|
|
178
|
+
if "expected_objects" in raw:
|
|
179
|
+
expected_objects = _string_list("expected_objects", raw["expected_objects"])
|
|
180
|
+
for ref in expected_objects:
|
|
181
|
+
_object_ref(ref)
|
|
182
|
+
required = _string_list("required_tools", raw["required_tools"]) if "required_tools" in raw else ()
|
|
183
|
+
forbidden = _string_list("forbidden_tools", raw["forbidden_tools"]) if "forbidden_tools" in raw else ()
|
|
184
|
+
both = sorted(set(required) & set(forbidden))
|
|
185
|
+
if both:
|
|
186
|
+
raise ValueError(f"tools {both} are both required and forbidden")
|
|
187
|
+
limit = raw.get("expected_limit")
|
|
188
|
+
if "expected_limit" in raw and (not isinstance(limit, int) or isinstance(limit, bool) or limit < 1):
|
|
189
|
+
raise ValueError(f"expected_limit must be a positive integer, got {limit!r}")
|
|
190
|
+
|
|
191
|
+
spec = SearchExpectation(
|
|
192
|
+
tool_args=tool_args,
|
|
193
|
+
expected_objects=expected_objects,
|
|
194
|
+
expect_widget=_flag("expect_widget", raw["expect_widget"]) if "expect_widget" in raw else None,
|
|
195
|
+
required_tools=required,
|
|
196
|
+
forbidden_tools=forbidden,
|
|
197
|
+
search_required=_flag("search_required", raw["search_required"]) if "search_required" in raw else True,
|
|
198
|
+
answer_rubric=_string_list("answer_rubric", raw["answer_rubric"]) if "answer_rubric" in raw else (),
|
|
199
|
+
expected_limit=limit,
|
|
200
|
+
no_raw_ids=_flag("no_raw_ids", raw["no_raw_ids"]) if "no_raw_ids" in raw else False,
|
|
201
|
+
setup_turns=_string_list("setup_turns", raw["setup_turns"]) if "setup_turns" in raw else (),
|
|
202
|
+
report_only=_flag("report_only", raw["report_only"]) if "report_only" in raw else False,
|
|
203
|
+
)
|
|
204
|
+
if "tool_call" not in raw and not spec.has_checks:
|
|
205
|
+
raise ValueError("expected_output asserts nothing: give tool_call or at least one check")
|
|
206
|
+
# tool_correctness only informs, so without tool_selection's gate a check of the turn is all that can fail a run.
|
|
207
|
+
if not spec.search_required and not spec.has_turn_checks:
|
|
208
|
+
raise ValueError(
|
|
209
|
+
"search_required: false needs a check of the scored turn (such as expect_widget or forbidden_tools), "
|
|
210
|
+
"or the item passes whatever the agent does"
|
|
211
|
+
)
|
|
212
|
+
if spec.report_only and not spec.has_turn_checks:
|
|
213
|
+
raise ValueError("report_only has no check to report")
|
|
214
|
+
return spec
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _ref_key(object_type: str, object_id: str) -> tuple[str, str]:
|
|
218
|
+
return ("attribute" if object_type in _ATTRIBUTE_TYPES else object_type, object_id)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def call_args(tc: ToolCallEvent) -> dict[str, Any]:
|
|
222
|
+
"""The call's arguments, or {} when they are missing or not a JSON object."""
|
|
223
|
+
args = tc.parsed_arguments()
|
|
224
|
+
return args if isinstance(args, dict) else {}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def search_calls(events: list[ToolCallEvent]) -> list[ToolCallEvent]:
|
|
228
|
+
"""The turn's ``search_objects`` calls, in order."""
|
|
229
|
+
return [tc for tc in events if tc.function_name == SEARCH_TOOL]
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _objects(container: Any) -> list[dict]:
|
|
233
|
+
"""The object entries of a search result or widget part; none when its shape is not the expected one."""
|
|
234
|
+
objects = container.get("objects") if isinstance(container, dict) else None
|
|
235
|
+
return [obj for obj in objects if isinstance(obj, dict)] if isinstance(objects, list) else []
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def returned_refs(result: ChatResult) -> list[str]:
|
|
239
|
+
"""Every object the turn's searches returned, as ``type/id``, first sighting first.
|
|
240
|
+
|
|
241
|
+
Read from the ``search_objects`` results and from the ``searchResults`` widget parts: a search
|
|
242
|
+
the agent runs for itself shows no widget, so its result is the only place its objects appear.
|
|
243
|
+
"""
|
|
244
|
+
refs: dict[tuple[str, str], str] = {}
|
|
245
|
+
|
|
246
|
+
def _add(object_type: Any, object_id: Any) -> None:
|
|
247
|
+
if isinstance(object_type, str) and isinstance(object_id, str) and object_type and object_id:
|
|
248
|
+
refs.setdefault(_ref_key(object_type, object_id), f"{object_type}/{object_id}")
|
|
249
|
+
|
|
250
|
+
for tc in search_calls(result.tool_call_events or []):
|
|
251
|
+
for obj in _objects(tc.parsed_result()):
|
|
252
|
+
_add(obj.get("final_type") or obj.get("type"), obj.get("id"))
|
|
253
|
+
for part in result.search_results:
|
|
254
|
+
for obj in _objects(part):
|
|
255
|
+
_add(obj.get("type"), obj.get("id"))
|
|
256
|
+
return list(refs.values())
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _key_of(ref: str) -> tuple[str, str]:
|
|
260
|
+
object_type, _, object_id = ref.partition("/")
|
|
261
|
+
return _ref_key(object_type, object_id)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def missing_objects(expected: tuple[str, ...], returned: list[str]) -> list[str]:
|
|
265
|
+
"""The expected refs no search returned. Every one must be found, not any one."""
|
|
266
|
+
found = {_key_of(ref) for ref in returned}
|
|
267
|
+
return [ref for ref in expected if _key_of(ref) not in found]
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def raw_ids(text: str) -> list[str]:
|
|
271
|
+
"""The UUIDs and ``type/id`` spellings in ``text`` that sit outside a ``{type/id}`` chip."""
|
|
272
|
+
outside = _CHIP.sub(" ", text)
|
|
273
|
+
typed = [m.group(0) for m in _TYPED_ID.finditer(outside) if _ID_MARK.search(m.group(1))]
|
|
274
|
+
return _UUID.findall(outside) + typed
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def deterministic_checks(spec: SearchExpectation, result: ChatResult) -> tuple[dict[str, bool], dict[str, Any]]:
|
|
278
|
+
"""The checks of one scored turn that need no judge, with the evidence of each failure."""
|
|
279
|
+
checks: dict[str, bool] = {}
|
|
280
|
+
details: dict[str, Any] = {}
|
|
281
|
+
|
|
282
|
+
def _check(name: str, ok: bool, why: Any) -> None:
|
|
283
|
+
checks[name] = ok
|
|
284
|
+
if not ok:
|
|
285
|
+
details[name] = why
|
|
286
|
+
|
|
287
|
+
events = result.tool_call_events or []
|
|
288
|
+
if spec.expected_objects:
|
|
289
|
+
returned = returned_refs(result)
|
|
290
|
+
missing = missing_objects(spec.expected_objects, returned)
|
|
291
|
+
_check("search_expected_objects", not missing, {"missing": missing, "returned": returned[:30]})
|
|
292
|
+
if spec.expect_widget is not None:
|
|
293
|
+
parts = len(result.search_results)
|
|
294
|
+
_check("search_widget", (parts > 0) == spec.expect_widget, {"expected": spec.expect_widget, "parts": parts})
|
|
295
|
+
if spec.required_tools or spec.forbidden_tools:
|
|
296
|
+
called = [tc.function_name for tc in events]
|
|
297
|
+
not_called = [name for name in spec.required_tools if name not in called]
|
|
298
|
+
forbidden = [name for name in spec.forbidden_tools if name in called]
|
|
299
|
+
_check(
|
|
300
|
+
"search_routing",
|
|
301
|
+
not not_called and not forbidden,
|
|
302
|
+
{"not_called": not_called, "forbidden_called": forbidden, "called": called},
|
|
303
|
+
)
|
|
304
|
+
if spec.expected_limit is not None:
|
|
305
|
+
limits = [call_args(tc).get("limit") for tc in search_calls(events)]
|
|
306
|
+
_check("search_limit", spec.expected_limit in limits, {"expected": spec.expected_limit, "limits": limits})
|
|
307
|
+
if spec.no_raw_ids:
|
|
308
|
+
found = raw_ids(result.text_response or "")
|
|
309
|
+
_check("search_no_raw_ids", not found, {"raw_ids": found})
|
|
310
|
+
return checks, details
|
|
@@ -592,6 +592,21 @@ def generate_simulated_alert_response(
|
|
|
592
592
|
|
|
593
593
|
original_request = f'Your original request to the agent was: "{question}"\n' if question else ""
|
|
594
594
|
|
|
595
|
+
# The agent may offer several metrics and describe one as ignoring filters or counting all
|
|
596
|
+
# time. That reads like rule 5's "no filters ... all time", which made the simulated user
|
|
597
|
+
# pick it. The pick follows the goal's metric whatever its description says, matched by id
|
|
598
|
+
# or by title, and repeats the option as the agent wrote it, so the reply adds no reference
|
|
599
|
+
# the agent did not offer. A fixture names a bare metric id: `_check_metric` compares it as
|
|
600
|
+
# written.
|
|
601
|
+
metric_choice_rule = (
|
|
602
|
+
f" If the agent offers several metrics to choose from, choose the option for your goal metric "
|
|
603
|
+
f"({expected.metric_id}; the agent may show it by this id or only by its title) and repeat that option "
|
|
604
|
+
"as the agent wrote it. How the agent describes a metric, for example as ignoring filters or counting all "
|
|
605
|
+
"time, never changes which metric you want: rule 5 is about filters on the alert.\n"
|
|
606
|
+
if expected.metric_id
|
|
607
|
+
else ""
|
|
608
|
+
)
|
|
609
|
+
|
|
595
610
|
# Only a stated title is enforced: an unstated one is the agent's to choose, and telling the
|
|
596
611
|
# sim-user nothing keeps it from objecting to a generated name.
|
|
597
612
|
title_rule = (
|
|
@@ -607,8 +622,11 @@ def generate_simulated_alert_response(
|
|
|
607
622
|
+ original_request
|
|
608
623
|
+ "Rules you MUST follow:\n"
|
|
609
624
|
f"1. Your goal: metric={metric}, operator={operator}, threshold={threshold}, "
|
|
610
|
-
f"recipients={recipients}, trigger={trigger_key}"
|
|
611
|
-
"
|
|
625
|
+
f"recipients={recipients}, trigger={trigger_key}"
|
|
626
|
+
+ (f", filters={filters}" if filters else "")
|
|
627
|
+
+ ".\n"
|
|
628
|
+
+ metric_choice_rule
|
|
629
|
+
+ "2. Never revert or change a decision that was already confirmed in a previous turn.\n"
|
|
612
630
|
"3. If the agent shows a final summary, an alert proposal or asks for confirmation, check "
|
|
613
631
|
" ALL of these against your goal: recipients, trigger (how often you are alerted), "
|
|
614
632
|
" filters / time window, threshold and operator. If ANY of them differs — for example the "
|