gooddata-eval 1.81.1.dev3__py3-none-any.whl → 1.81.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/core/agentic/_kda_answer.py +155 -0
- gooddata_eval/core/agentic/_kda_expectation.py +136 -15
- gooddata_eval/core/agentic/_search_expectation.py +113 -3
- gooddata_eval/core/agentic/document_skill.py +21 -6
- gooddata_eval/core/agentic/kda_skill.py +241 -23
- gooddata_eval/core/agentic/search_tool.py +8 -6
- gooddata_eval/core/chat/sse_client.py +4 -0
- {gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/METADATA +44 -2
- {gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/RECORD +12 -11
- {gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/WHEEL +0 -0
- {gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/entry_points.txt +0 -0
- {gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# (C) 2026 GoodData Corporation. All rights reserved.
|
|
2
|
+
"""Whether a KDA answer, and the suggestions after it, name the drivers the analysis returned.
|
|
3
|
+
|
|
4
|
+
The execute tool returns ``data.significant_drivers``: one row per attribute value, with its own
|
|
5
|
+
``delta`` between the periods. The answer is read as text, so a driver counts as named when its
|
|
6
|
+
value appears as a whole word, plural allowed. Two kinds of value are skipped: a date, which the
|
|
7
|
+
answer writes as "July 19" where the driver says "2025-07-19", and a value shorter than three
|
|
8
|
+
characters, which matches ordinary words ("A", "No", "1").
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
# How many of the largest drivers a failed check reports.
|
|
17
|
+
_TOP_DRIVERS = 5
|
|
18
|
+
_MIN_VALUE_CHARS = 3
|
|
19
|
+
_DATE_VALUE = re.compile(
|
|
20
|
+
r"^\d{4}-\d{1,2}(-\d{1,2})?([ T]\d{1,2}(:\d{2}){0,2}(\.\d+)?(Z|[+-]\d{2}(:?\d{2})?)?)?$", re.IGNORECASE
|
|
21
|
+
)
|
|
22
|
+
# "10,769" is the same number as "10769". A plain space is not a separator: "2024 100 stores" is two numbers.
|
|
23
|
+
_THOUSANDS = re.compile(r"(?<=\d)[, ](?=\d{3}(?!\d))")
|
|
24
|
+
_NUMBER = re.compile(r"\d+(\.\d+)?")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _normalized(text: str) -> str:
|
|
28
|
+
return " ".join(_THOUSANDS.sub("", text).casefold().split())
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _value_text(value: Any) -> str | None:
|
|
32
|
+
if isinstance(value, bool) or value is None:
|
|
33
|
+
return None
|
|
34
|
+
if isinstance(value, float) and value.is_integer():
|
|
35
|
+
value = int(value)
|
|
36
|
+
raw = str(value).strip()
|
|
37
|
+
if _DATE_VALUE.match(raw):
|
|
38
|
+
return None
|
|
39
|
+
text = _normalized(raw)
|
|
40
|
+
return text if len(text) >= _MIN_VALUE_CHARS else None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _drivers(execute_result: Any) -> list[dict[str, Any]]:
|
|
44
|
+
data = execute_result.get("data") if isinstance(execute_result, dict) else None
|
|
45
|
+
drivers = data.get("significant_drivers") if isinstance(data, dict) else None
|
|
46
|
+
return [d for d in drivers if isinstance(d, dict)] if isinstance(drivers, list) else []
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _delta(driver: dict[str, Any]) -> float:
|
|
50
|
+
delta = driver.get("delta")
|
|
51
|
+
if isinstance(delta, bool) or not isinstance(delta, int | float):
|
|
52
|
+
return 0.0
|
|
53
|
+
return abs(float(delta))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _ran(execute_result: Any) -> bool:
|
|
57
|
+
return isinstance(execute_result, dict) and execute_result.get("success") is True
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def driver_values(execute_result: Any, limit: int | None = None) -> list[str]:
|
|
61
|
+
"""The driver values an answer can name, largest change first, without repeats."""
|
|
62
|
+
ranked = sorted(_drivers(execute_result), key=_delta, reverse=True)
|
|
63
|
+
values = list(dict.fromkeys(v for v in (_value_text(d.get("value")) for d in ranked) if v))
|
|
64
|
+
return values if limit is None else values[:limit]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _value_pattern(value: str) -> str:
|
|
68
|
+
"""A whole number never matches inside a decimal; a word matches its plural, "y" also as "ies"."""
|
|
69
|
+
if _NUMBER.fullmatch(value):
|
|
70
|
+
return rf"(?<![\w.]){re.escape(value)}(?!\w|[.,]\d)"
|
|
71
|
+
if len(value) > 1 and value.endswith("y") and value[-2] not in "aeiou":
|
|
72
|
+
return rf"(?<!\w){re.escape(value[:-1])}(?:y|ies)(?!\w)"
|
|
73
|
+
return rf"(?<!\w){re.escape(value)}(?:e?s)?(?!\w)"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def named_values(text: str, values: list[str]) -> list[str]:
|
|
77
|
+
"""The values that appear in ``text`` as whole words, singular or plural."""
|
|
78
|
+
haystack = _normalized(text)
|
|
79
|
+
return [v for v in values if re.search(_value_pattern(v), haystack)]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def check_answer_grounded(execute_result: Any, answer: str) -> tuple[bool, dict[str, Any]]:
|
|
83
|
+
"""Whether the answer names a driver the analysis returned.
|
|
84
|
+
|
|
85
|
+
Any driver counts, not only the largest: a question about regions is answered with the region
|
|
86
|
+
drivers, which need not be the largest ones. An analysis that ran and returned no driver to
|
|
87
|
+
name passes; a run with no analysis does not.
|
|
88
|
+
"""
|
|
89
|
+
if not _ran(execute_result):
|
|
90
|
+
return False, {"reason": "no analysis ran"}
|
|
91
|
+
values = driver_values(execute_result)
|
|
92
|
+
if not values:
|
|
93
|
+
return True, {"top_drivers": []}
|
|
94
|
+
named = named_values(answer, values)
|
|
95
|
+
return bool(named), {"top_drivers": values[:_TOP_DRIVERS], "named": named}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def suggested_actions(suggestions: Any) -> list[dict[str, Any]]:
|
|
99
|
+
"""The suggested actions, [] when there are none.
|
|
100
|
+
|
|
101
|
+
Raises:
|
|
102
|
+
ValueError: The suggestions have a shape this check cannot read.
|
|
103
|
+
"""
|
|
104
|
+
if suggestions is None:
|
|
105
|
+
return []
|
|
106
|
+
actions = suggestions.get("actions") if isinstance(suggestions, dict) else suggestions
|
|
107
|
+
if actions is None:
|
|
108
|
+
return []
|
|
109
|
+
if not isinstance(actions, list) or not all(isinstance(a, dict) for a in actions):
|
|
110
|
+
raise ValueError(f"unreadable suggestion actions {actions!r}")
|
|
111
|
+
return actions
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def check_suggestions_name_driver(execute_result: Any, answer: str, suggestions: Any) -> tuple[bool, dict[str, Any]]:
|
|
115
|
+
"""Whether the first suggested action names a driver the answer named.
|
|
116
|
+
|
|
117
|
+
True when there are no actions, or the answer names no driver: the rule binds only an answer
|
|
118
|
+
that highlights drivers by name. False when no analysis ran.
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
ValueError: The suggestions have a shape this check cannot read.
|
|
122
|
+
"""
|
|
123
|
+
actions = suggested_actions(suggestions)
|
|
124
|
+
if not _ran(execute_result):
|
|
125
|
+
return False, {"reason": "no analysis ran"}
|
|
126
|
+
if not actions:
|
|
127
|
+
return True, {"first_action": None}
|
|
128
|
+
first = actions[0]
|
|
129
|
+
in_answer = named_values(answer, driver_values(execute_result))
|
|
130
|
+
if not in_answer:
|
|
131
|
+
return True, {"first_action": first, "drivers_in_answer": []}
|
|
132
|
+
action_text = f"{first.get('query') or ''} {first.get('label') or ''}"
|
|
133
|
+
named = named_values(action_text, in_answer)
|
|
134
|
+
return bool(named), {"first_action": first, "drivers_in_answer": in_answer, "named": named}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def suggestions_from_turn(items: list[dict[str, Any]], turn: int) -> Any:
|
|
138
|
+
"""The suggestions of the last turn from user turn ``turn`` (0-based) on, None when that turn has none.
|
|
139
|
+
|
|
140
|
+
A later user message starts a new turn: the suggestions of an earlier turn are not the last turn's.
|
|
141
|
+
"""
|
|
142
|
+
users = 0
|
|
143
|
+
latest: Any = None
|
|
144
|
+
for item in items:
|
|
145
|
+
role = item.get("role") if isinstance(item, dict) else None
|
|
146
|
+
if role == "user":
|
|
147
|
+
users += 1
|
|
148
|
+
latest = None
|
|
149
|
+
continue
|
|
150
|
+
if role != "assistant" or users <= turn:
|
|
151
|
+
continue
|
|
152
|
+
content = item.get("content")
|
|
153
|
+
if isinstance(content, dict) and content.get("suggestions") is not None:
|
|
154
|
+
latest = content["suggestions"]
|
|
155
|
+
return latest
|
|
@@ -8,6 +8,18 @@ the key, nothing here runs and the item is scored on completion only.
|
|
|
8
8
|
``any_of`` lists complete alternatives. Each option replaces some fields of the item, and a run
|
|
9
9
|
passes when one option matches every field. The summary goes with the date attribute, so an
|
|
10
10
|
option that changes one usually states both.
|
|
11
|
+
|
|
12
|
+
The behaviour keys are opt-in as well, and each adds one score:
|
|
13
|
+
|
|
14
|
+
- ``expect_no_create: true``: no analysis may be created or run (``kda_not_created``).
|
|
15
|
+
- ``expect_clarification: false``: the turn that asks for the analysis runs it (``kda_first_turn``).
|
|
16
|
+
``true``: the first turn asks a question and runs nothing (``kda_clarified``).
|
|
17
|
+
- ``user_replies``: scripted messages sent after the question, in the same conversation. The
|
|
18
|
+
analysis of the last scripted turn, or of a later one, is the one scored.
|
|
19
|
+
- ``rubric``: an LLM judge grades the conversation against it (``kda_rubric``).
|
|
20
|
+
- ``check_answer: true``: the answer names a driver the analysis returned (``kda_answer_grounded``).
|
|
21
|
+
- ``check_suggestions: true``: when the answer names a driver, the first suggested action names one
|
|
22
|
+
too (``kda_suggestions``).
|
|
11
23
|
"""
|
|
12
24
|
|
|
13
25
|
from __future__ import annotations
|
|
@@ -33,7 +45,19 @@ _FIELD_KEYS = {
|
|
|
33
45
|
"summary": "Summary",
|
|
34
46
|
}
|
|
35
47
|
_OPTION_KEYS = frozenset(_FIELD_KEYS.values())
|
|
36
|
-
|
|
48
|
+
_BEHAVIOUR_KEYS = frozenset(
|
|
49
|
+
{"expect_no_create", "expect_clarification", "user_replies", "rubric", "check_answer", "check_suggestions"}
|
|
50
|
+
)
|
|
51
|
+
_ITEM_KEYS = _OPTION_KEYS | {"check_fields", "any_of"} | _BEHAVIOUR_KEYS
|
|
52
|
+
# The scores the behaviour keys add, each published only by an item that sets its key.
|
|
53
|
+
KDA_BEHAVIOUR_SCORES = (
|
|
54
|
+
"kda_not_created",
|
|
55
|
+
"kda_first_turn",
|
|
56
|
+
"kda_clarified",
|
|
57
|
+
"kda_rubric",
|
|
58
|
+
"kda_answer_grounded",
|
|
59
|
+
"kda_suggestions",
|
|
60
|
+
)
|
|
37
61
|
_SUMMARY_VALUES = ("analyzed_value", "reference_value", "change")
|
|
38
62
|
_SUMMARY_KEYS = frozenset({*_SUMMARY_VALUES, "absolute_tolerance"})
|
|
39
63
|
_DEFAULT_TOLERANCE = 0.01
|
|
@@ -43,8 +67,12 @@ _MEASURE_TYPES = ("metric", "fact", "attribute")
|
|
|
43
67
|
_AGGREGATIONS = ("SUM", "AVG", "MIN", "MAX", "MEDIAN", "COUNT")
|
|
44
68
|
_FILTER_STATES = ("include", "exclude")
|
|
45
69
|
# Spelled like the item's other keys, these would leave the checks off without a word.
|
|
46
|
-
_OPT_IN_KEYS = ("check_fields", "any_of")
|
|
70
|
+
_OPT_IN_KEYS = ("check_fields", "any_of", *sorted(_BEHAVIOUR_KEYS))
|
|
47
71
|
_DATE_FILTER = "date_filter"
|
|
72
|
+
_RANKING_FILTER = "ranking_filter"
|
|
73
|
+
_RANKING_SIDES = ("top", "bottom")
|
|
74
|
+
# The keys of the tool's ranking filter. The tool echoes the optional ones as null.
|
|
75
|
+
_RANKING_KEYS = frozenset({"type", "using", "attribute", *_RANKING_SIDES, "strict_limit_of_rows"})
|
|
48
76
|
# The agent's tools take an attribute by its label or its attribute id. Both ids are equal in the
|
|
49
77
|
# eval workspaces, so a filter is matched on the id alone.
|
|
50
78
|
_TYPE_PREFIXES = ("label/", "attribute/")
|
|
@@ -66,9 +94,18 @@ class KdaFieldOption:
|
|
|
66
94
|
|
|
67
95
|
@dataclass(frozen=True)
|
|
68
96
|
class KdaExpectation:
|
|
69
|
-
"""The item's
|
|
97
|
+
"""The item's checks. ``options`` is empty when the item does not opt into the field checks.
|
|
98
|
+
|
|
99
|
+
``expect_clarification`` is None when the item does not set it.
|
|
100
|
+
"""
|
|
70
101
|
|
|
71
102
|
options: tuple[KdaFieldOption, ...] = ()
|
|
103
|
+
expect_no_create: bool = False
|
|
104
|
+
expect_clarification: bool | None = None
|
|
105
|
+
user_replies: tuple[str, ...] = ()
|
|
106
|
+
rubric: str | None = None
|
|
107
|
+
check_answer: bool = False
|
|
108
|
+
check_suggestions: bool = False
|
|
72
109
|
|
|
73
110
|
@property
|
|
74
111
|
def check_fields(self) -> bool:
|
|
@@ -141,6 +178,25 @@ def _check_attribute_filter(entry: dict[str, Any]) -> None:
|
|
|
141
178
|
raise ValueError(f"attribute_filter {next(iter(state))} must be a non-empty list of strings, got {entry!r}")
|
|
142
179
|
|
|
143
180
|
|
|
181
|
+
def _check_ranking_filter(entry: dict[str, Any]) -> None:
|
|
182
|
+
if unknown := set(entry) - _RANKING_KEYS:
|
|
183
|
+
raise ValueError(f"ranking_filter has unknown keys {sorted(unknown)}, got {entry!r}")
|
|
184
|
+
using, attribute = entry.get("using"), entry.get("attribute")
|
|
185
|
+
if not isinstance(using, str) or not using.strip():
|
|
186
|
+
raise ValueError(f"ranking_filter needs a non-empty using, got {entry!r}")
|
|
187
|
+
if not isinstance(attribute, str) or not attribute.strip():
|
|
188
|
+
raise ValueError(f"ranking_filter needs a non-empty attribute, got {entry!r}")
|
|
189
|
+
counts = [entry.get(side) for side in _RANKING_SIDES if entry.get(side) is not None]
|
|
190
|
+
if len(counts) != 1 or not _is_count(counts[0]):
|
|
191
|
+
raise ValueError(f"ranking_filter needs exactly one of top, bottom as a positive integer, got {entry!r}")
|
|
192
|
+
if not isinstance(entry.get("strict_limit_of_rows"), bool | None):
|
|
193
|
+
raise ValueError(f"ranking_filter strict_limit_of_rows must be true, false or null, got {entry!r}")
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _is_count(value: Any) -> bool:
|
|
197
|
+
return isinstance(value, int) and not isinstance(value, bool) and value > 0
|
|
198
|
+
|
|
199
|
+
|
|
144
200
|
def _filters(value: Any) -> tuple[Any, ...]:
|
|
145
201
|
if not isinstance(value, list):
|
|
146
202
|
raise ValueError(f"Filters must be a list, [] for none, got {value!r}")
|
|
@@ -151,6 +207,8 @@ def _filters(value: Any) -> tuple[Any, ...]:
|
|
|
151
207
|
raise ValueError("Filters must not hold a date_filter: date filters are not checked, the periods are")
|
|
152
208
|
if entry.get("type") == "attribute_filter":
|
|
153
209
|
_check_attribute_filter(entry)
|
|
210
|
+
if entry.get("type") == _RANKING_FILTER:
|
|
211
|
+
_check_ranking_filter(entry)
|
|
154
212
|
return tuple(_filter_key(entry) for entry in value)
|
|
155
213
|
|
|
156
214
|
|
|
@@ -197,26 +255,22 @@ def _reject_respelt_keys(expected: dict[str, Any]) -> None:
|
|
|
197
255
|
raise ValueError(f"write {canonical!r}, not {key!r}")
|
|
198
256
|
|
|
199
257
|
|
|
200
|
-
def
|
|
201
|
-
"""
|
|
202
|
-
if
|
|
203
|
-
|
|
204
|
-
if not isinstance(expected, dict) or "check_fields" not in expected:
|
|
205
|
-
if isinstance(expected, dict) and "any_of" in expected:
|
|
258
|
+
def _field_options(expected: dict[str, Any]) -> tuple[KdaFieldOption, ...]:
|
|
259
|
+
"""The field checks of an item, empty when it does not set ``check_fields: true``."""
|
|
260
|
+
if "check_fields" not in expected:
|
|
261
|
+
if "any_of" in expected:
|
|
206
262
|
raise ValueError("any_of is read only with check_fields: true")
|
|
207
|
-
return
|
|
263
|
+
return ()
|
|
208
264
|
flag = expected["check_fields"]
|
|
209
265
|
if not isinstance(flag, bool):
|
|
210
266
|
raise ValueError(f"check_fields must be true or false, got {flag!r}")
|
|
211
267
|
if not flag:
|
|
212
268
|
if "any_of" in expected:
|
|
213
269
|
raise ValueError("any_of is read only with check_fields: true")
|
|
214
|
-
return
|
|
215
|
-
if unknown := set(expected) - _ITEM_KEYS:
|
|
216
|
-
raise ValueError(f"expected_output has unknown keys {sorted(unknown)}")
|
|
270
|
+
return ()
|
|
217
271
|
base = {key: value for key, value in expected.items() if key in _OPTION_KEYS}
|
|
218
272
|
if "any_of" not in expected:
|
|
219
|
-
return
|
|
273
|
+
return (_option(base, "expected_output"),)
|
|
220
274
|
options = expected["any_of"]
|
|
221
275
|
if not isinstance(options, list) or len(options) < 2 or not all(isinstance(o, dict) and o for o in options):
|
|
222
276
|
raise ValueError(f"any_of must list at least two non-empty objects, got {options!r}")
|
|
@@ -227,7 +281,64 @@ def parse_kda_expectation(expected: Any) -> KdaExpectation:
|
|
|
227
281
|
f"any_of[{index}] has keys {sorted(unknown)}; an option may state only {sorted(_OPTION_KEYS)}"
|
|
228
282
|
)
|
|
229
283
|
parsed.append(_option({**base, **option}, f"any_of[{index}]"))
|
|
230
|
-
return
|
|
284
|
+
return tuple(parsed)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _flag(expected: dict[str, Any], key: str) -> bool | None:
|
|
288
|
+
if key not in expected:
|
|
289
|
+
return None
|
|
290
|
+
value = expected[key]
|
|
291
|
+
if not isinstance(value, bool):
|
|
292
|
+
raise ValueError(f"{key} must be true or false, got {value!r}")
|
|
293
|
+
return value
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _user_replies(value: Any) -> tuple[str, ...]:
|
|
297
|
+
if not isinstance(value, list) or not value or not all(isinstance(v, str) and v.strip() for v in value):
|
|
298
|
+
raise ValueError(f"user_replies must be a non-empty list of non-empty strings, got {value!r}")
|
|
299
|
+
return tuple(v.strip() for v in value)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def parse_kda_expectation(expected: Any) -> KdaExpectation:
|
|
303
|
+
"""Read the item's checks, raising ValueError on a malformed one before any request is sent."""
|
|
304
|
+
if not isinstance(expected, dict):
|
|
305
|
+
return KdaExpectation()
|
|
306
|
+
_reject_respelt_keys(expected)
|
|
307
|
+
options = _field_options(expected)
|
|
308
|
+
# An item that opts into no check may carry other keys; one that opts in is read whole.
|
|
309
|
+
if (options or _BEHAVIOUR_KEYS & set(expected)) and (unknown := set(expected) - _ITEM_KEYS):
|
|
310
|
+
raise ValueError(f"expected_output has unknown keys {sorted(unknown)}")
|
|
311
|
+
no_create = _flag(expected, "expect_no_create") or False
|
|
312
|
+
clarification = _flag(expected, "expect_clarification")
|
|
313
|
+
check_answer = _flag(expected, "check_answer") or False
|
|
314
|
+
check_suggestions = _flag(expected, "check_suggestions") or False
|
|
315
|
+
rubric = expected.get("rubric")
|
|
316
|
+
if "rubric" in expected and (not isinstance(rubric, str) or not rubric.strip()):
|
|
317
|
+
raise ValueError(f"rubric must be a non-empty string, got {rubric!r}")
|
|
318
|
+
replies = _user_replies(expected["user_replies"]) if "user_replies" in expected else ()
|
|
319
|
+
if no_create:
|
|
320
|
+
# Each of these needs an analysis that ran, which the item says must not happen.
|
|
321
|
+
clashes = [
|
|
322
|
+
key
|
|
323
|
+
for key, on in (
|
|
324
|
+
("check_fields", bool(options)),
|
|
325
|
+
("check_answer", check_answer),
|
|
326
|
+
("check_suggestions", check_suggestions),
|
|
327
|
+
("expect_clarification", clarification is not None),
|
|
328
|
+
)
|
|
329
|
+
if on
|
|
330
|
+
]
|
|
331
|
+
if clashes:
|
|
332
|
+
raise ValueError(f"expect_no_create cannot be combined with {', '.join(clashes)}")
|
|
333
|
+
return KdaExpectation(
|
|
334
|
+
options=options,
|
|
335
|
+
expect_no_create=no_create,
|
|
336
|
+
expect_clarification=clarification,
|
|
337
|
+
user_replies=replies,
|
|
338
|
+
rubric=rubric.strip() if isinstance(rubric, str) else None,
|
|
339
|
+
check_answer=check_answer,
|
|
340
|
+
check_suggestions=check_suggestions,
|
|
341
|
+
)
|
|
231
342
|
|
|
232
343
|
|
|
233
344
|
def _bare_id(using: Any) -> Any:
|
|
@@ -253,6 +364,16 @@ def _filter_key(entry: dict[str, Any]) -> Any:
|
|
|
253
364
|
tuple(sorted(state.get("include") or [])),
|
|
254
365
|
tuple(sorted(state.get("exclude") or [])),
|
|
255
366
|
)
|
|
367
|
+
if entry.get("type") == _RANKING_FILTER and isinstance(entry.get("using"), str):
|
|
368
|
+
# The tool echoes optional keys as null (strict_limit_of_rows), and names the attribute either way.
|
|
369
|
+
return (
|
|
370
|
+
_RANKING_FILTER,
|
|
371
|
+
entry["using"].strip(),
|
|
372
|
+
_bare_id(entry.get("attribute")),
|
|
373
|
+
*(json.dumps(entry.get(side), default=str) for side in _RANKING_SIDES),
|
|
374
|
+
# Unset reads as false: the tool echoes null when the agent did not ask for a strict limit.
|
|
375
|
+
bool(entry.get("strict_limit_of_rows")),
|
|
376
|
+
)
|
|
256
377
|
return json.dumps(entry, sort_keys=True, default=str)
|
|
257
378
|
|
|
258
379
|
|
|
@@ -12,6 +12,7 @@ import re
|
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
13
|
from typing import Any
|
|
14
14
|
|
|
15
|
+
from gooddata_eval.core.chat.sse_client import UNHANDLED_PART_TYPES
|
|
15
16
|
from gooddata_eval.core.models import ChatResult, ToolCallEvent
|
|
16
17
|
|
|
17
18
|
SEARCH_TOOL = "search_objects"
|
|
@@ -30,6 +31,10 @@ SEARCH_OPTION_KEYS = frozenset(
|
|
|
30
31
|
"no_raw_ids",
|
|
31
32
|
"setup_turns",
|
|
32
33
|
"report_only",
|
|
34
|
+
"expect_user_requested_search",
|
|
35
|
+
"widget_objects",
|
|
36
|
+
"forbidden_parts",
|
|
37
|
+
"no_object_urls",
|
|
33
38
|
}
|
|
34
39
|
)
|
|
35
40
|
_KNOWN_KEYS = SEARCH_OPTION_KEYS | {"tool_call"}
|
|
@@ -69,6 +74,34 @@ _TYPED_ID = re.compile(rf"\b(?:{'|'.join(sorted(_OBJECT_TYPES))})/([A-Za-z0-9_](
|
|
|
69
74
|
# a dot or a digit, as the workspace ids have, counts. A one-word id such as metric/revenue is not caught.
|
|
70
75
|
_ID_MARK = re.compile(r"[_.0-9]")
|
|
71
76
|
|
|
77
|
+
# ``forbidden_parts`` may only name a type that lands in ``unhandled_parts`` (a draft: document, report,
|
|
78
|
+
# dashboard), so a misspelt type cannot read as a pass.
|
|
79
|
+
_UNHANDLED_PART_TYPES = UNHANDLED_PART_TYPES
|
|
80
|
+
# A link: an absolute ``http(s)`` or ``gooddata://`` URL, or a markdown link to an app path. The UI opens an
|
|
81
|
+
# object from the Search list, so an object link in the text is one the model wrote itself.
|
|
82
|
+
_LINK = re.compile(r"(?:https?|gooddata)://[^\s<>()\[\]\"'`]+|\]\(\s*<?(/[^\s)>]+)")
|
|
83
|
+
# The routes that open one object, so an id segment follows the type: an app route
|
|
84
|
+
# (``/workspace/<ws>/reports/document/<id>``, ``/dashboards/#/workspace/<ws>/dashboard/<id>``), the entity API
|
|
85
|
+
# (``/entities/workspaces/<ws>/<type>/<id>``) and Analytical Designer (``/analyze/#/<ws>/<id>``). A list page
|
|
86
|
+
# (``/workspace/<ws>/reports``) and a help page with a ``workspaces`` segment are none of them.
|
|
87
|
+
_OBJECT_PATH = re.compile(
|
|
88
|
+
r"/workspace/[^/\s#?]+/(?:reports?|dashboards?|documents?|visualizations?|metrics?|analyze)/[^/\s#?]+"
|
|
89
|
+
r"|/entities/workspaces/[^/\s]+/[^/\s]+/[^/\s?#]+"
|
|
90
|
+
r"|/analyze/#/[^/\s]+/[^/\s]+",
|
|
91
|
+
re.IGNORECASE,
|
|
92
|
+
)
|
|
93
|
+
# A made-up object link on any host: the path ends in an object type and an id
|
|
94
|
+
# (``https://analytics.gooddata.com/documents/<id>``). An id has a ``_``, a dot or a digit; a help page slug
|
|
95
|
+
# (``/docs/cloud/dashboards/filters/``) has none, and a path under ``/docs/`` is never read this way.
|
|
96
|
+
_TYPED_ID_PATH = re.compile(
|
|
97
|
+
r"/(?:documents?|dashboards?|reports?|visualizations?|metrics?)/([^/\s?#]*[_.0-9][^/\s?#]*)/?(?:[?#].*)?$",
|
|
98
|
+
re.IGNORECASE,
|
|
99
|
+
)
|
|
100
|
+
# Sentence punctuation the link pattern takes in after a URL ("see https://h/x.").
|
|
101
|
+
_TRAILING_PUNCTUATION = ".,;:!?*_"
|
|
102
|
+
# The parts of a link an id can fill on its own: path segments and query values.
|
|
103
|
+
_LINK_PARTS = re.compile(r"[/#?&=]")
|
|
104
|
+
|
|
72
105
|
|
|
73
106
|
@dataclass(frozen=True)
|
|
74
107
|
class SearchExpectation:
|
|
@@ -89,6 +122,10 @@ class SearchExpectation:
|
|
|
89
122
|
no_raw_ids: bool = False
|
|
90
123
|
setup_turns: tuple[str, ...] = ()
|
|
91
124
|
report_only: bool = False
|
|
125
|
+
expect_user_requested_search: bool | None = None
|
|
126
|
+
widget_objects: tuple[str, ...] = ()
|
|
127
|
+
forbidden_parts: tuple[str, ...] = ()
|
|
128
|
+
no_object_urls: bool = False
|
|
92
129
|
|
|
93
130
|
@property
|
|
94
131
|
def has_turn_checks(self) -> bool:
|
|
@@ -101,6 +138,10 @@ class SearchExpectation:
|
|
|
101
138
|
or self.answer_rubric
|
|
102
139
|
or self.expected_limit is not None
|
|
103
140
|
or self.no_raw_ids
|
|
141
|
+
or self.expect_user_requested_search is not None
|
|
142
|
+
or self.widget_objects
|
|
143
|
+
or self.forbidden_parts
|
|
144
|
+
or self.no_object_urls
|
|
104
145
|
)
|
|
105
146
|
|
|
106
147
|
@property
|
|
@@ -124,10 +165,10 @@ def _flag(key: str, value: Any) -> bool:
|
|
|
124
165
|
return value
|
|
125
166
|
|
|
126
167
|
|
|
127
|
-
def _object_ref(ref: str) -> tuple[str, str]:
|
|
168
|
+
def _object_ref(key: str, ref: str) -> tuple[str, str]:
|
|
128
169
|
object_type, sep, object_id = ref.partition("/")
|
|
129
170
|
if not sep or object_type not in _OBJECT_TYPES or not object_id or object_id != object_id.strip():
|
|
130
|
-
raise ValueError(f"
|
|
171
|
+
raise ValueError(f"{key} entry must be '<type>/<id>' with a known type, got {ref!r}")
|
|
131
172
|
return object_type, object_id
|
|
132
173
|
|
|
133
174
|
|
|
@@ -178,12 +219,21 @@ def parse_expectation(expected_output: Any) -> SearchExpectation:
|
|
|
178
219
|
if "expected_objects" in raw:
|
|
179
220
|
expected_objects = _string_list("expected_objects", raw["expected_objects"])
|
|
180
221
|
for ref in expected_objects:
|
|
181
|
-
_object_ref(ref)
|
|
222
|
+
_object_ref("expected_objects", ref)
|
|
182
223
|
required = _string_list("required_tools", raw["required_tools"]) if "required_tools" in raw else ()
|
|
183
224
|
forbidden = _string_list("forbidden_tools", raw["forbidden_tools"]) if "forbidden_tools" in raw else ()
|
|
184
225
|
both = sorted(set(required) & set(forbidden))
|
|
185
226
|
if both:
|
|
186
227
|
raise ValueError(f"tools {both} are both required and forbidden")
|
|
228
|
+
widget_objects: tuple[str, ...] = ()
|
|
229
|
+
if "widget_objects" in raw:
|
|
230
|
+
widget_objects = _string_list("widget_objects", raw["widget_objects"])
|
|
231
|
+
for ref in widget_objects:
|
|
232
|
+
_object_ref("widget_objects", ref)
|
|
233
|
+
forbidden_parts = _string_list("forbidden_parts", raw["forbidden_parts"]) if "forbidden_parts" in raw else ()
|
|
234
|
+
unknown_parts = sorted(set(forbidden_parts) - _UNHANDLED_PART_TYPES)
|
|
235
|
+
if unknown_parts:
|
|
236
|
+
raise ValueError(f"forbidden_parts {unknown_parts} are not among {sorted(_UNHANDLED_PART_TYPES)}")
|
|
187
237
|
limit = raw.get("expected_limit")
|
|
188
238
|
if "expected_limit" in raw and (not isinstance(limit, int) or isinstance(limit, bool) or limit < 1):
|
|
189
239
|
raise ValueError(f"expected_limit must be a positive integer, got {limit!r}")
|
|
@@ -200,6 +250,14 @@ def parse_expectation(expected_output: Any) -> SearchExpectation:
|
|
|
200
250
|
no_raw_ids=_flag("no_raw_ids", raw["no_raw_ids"]) if "no_raw_ids" in raw else False,
|
|
201
251
|
setup_turns=_string_list("setup_turns", raw["setup_turns"]) if "setup_turns" in raw else (),
|
|
202
252
|
report_only=_flag("report_only", raw["report_only"]) if "report_only" in raw else False,
|
|
253
|
+
expect_user_requested_search=(
|
|
254
|
+
_flag("expect_user_requested_search", raw["expect_user_requested_search"])
|
|
255
|
+
if "expect_user_requested_search" in raw
|
|
256
|
+
else None
|
|
257
|
+
),
|
|
258
|
+
widget_objects=widget_objects,
|
|
259
|
+
forbidden_parts=forbidden_parts,
|
|
260
|
+
no_object_urls=_flag("no_object_urls", raw["no_object_urls"]) if "no_object_urls" in raw else False,
|
|
203
261
|
)
|
|
204
262
|
if "tool_call" not in raw and not spec.has_checks:
|
|
205
263
|
raise ValueError("expected_output asserts nothing: give tool_call or at least one check")
|
|
@@ -274,6 +332,38 @@ def raw_ids(text: str) -> list[str]:
|
|
|
274
332
|
return _UUID.findall(outside) + typed
|
|
275
333
|
|
|
276
334
|
|
|
335
|
+
def widget_refs(result: ChatResult) -> list[str]:
|
|
336
|
+
"""Every object the turn's ``searchResults`` parts list, as ``type/id``, first sighting first."""
|
|
337
|
+
refs: dict[tuple[str, str], str] = {}
|
|
338
|
+
for part in result.search_results:
|
|
339
|
+
for obj in _objects(part):
|
|
340
|
+
object_type, object_id = obj.get("type"), obj.get("id")
|
|
341
|
+
if isinstance(object_type, str) and isinstance(object_id, str) and object_type and object_id:
|
|
342
|
+
refs.setdefault(_ref_key(object_type, object_id), f"{object_type}/{object_id}")
|
|
343
|
+
return list(refs.values())
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def object_urls(text: str, object_ids: tuple[str, ...] = ()) -> list[str]:
|
|
347
|
+
"""The links in ``text`` that point at a workspace object.
|
|
348
|
+
|
|
349
|
+
A link counts when it is a ``gooddata://`` link, follows an app or API route to one object, ends in an object
|
|
350
|
+
type and an id outside ``/docs/``, or has one of ``object_ids`` (the ids the turn's searches returned) as a
|
|
351
|
+
whole path segment or query value.
|
|
352
|
+
"""
|
|
353
|
+
found: list[str] = []
|
|
354
|
+
for match in _LINK.finditer(text):
|
|
355
|
+
link = (match.group(1) or match.group(0)).rstrip(_TRAILING_PUNCTUATION)
|
|
356
|
+
parts = set(_LINK_PARTS.split(link))
|
|
357
|
+
if (
|
|
358
|
+
link.lower().startswith("gooddata://")
|
|
359
|
+
or _OBJECT_PATH.search(link)
|
|
360
|
+
or ("/docs/" not in link.lower() and _TYPED_ID_PATH.search(link))
|
|
361
|
+
or any(object_id in parts for object_id in object_ids)
|
|
362
|
+
):
|
|
363
|
+
found.append(link)
|
|
364
|
+
return found
|
|
365
|
+
|
|
366
|
+
|
|
277
367
|
def deterministic_checks(spec: SearchExpectation, result: ChatResult) -> tuple[dict[str, bool], dict[str, Any]]:
|
|
278
368
|
"""The checks of one scored turn that need no judge, with the evidence of each failure."""
|
|
279
369
|
checks: dict[str, bool] = {}
|
|
@@ -307,4 +397,24 @@ def deterministic_checks(spec: SearchExpectation, result: ChatResult) -> tuple[d
|
|
|
307
397
|
if spec.no_raw_ids:
|
|
308
398
|
found = raw_ids(result.text_response or "")
|
|
309
399
|
_check("search_no_raw_ids", not found, {"raw_ids": found})
|
|
400
|
+
if spec.expect_user_requested_search is not None:
|
|
401
|
+
flags = [call_args(tc).get("user_requested_search") for tc in search_calls(events)]
|
|
402
|
+
asked = any(flag is True for flag in flags)
|
|
403
|
+
_check(
|
|
404
|
+
"search_user_requested",
|
|
405
|
+
asked == spec.expect_user_requested_search,
|
|
406
|
+
{"expected": spec.expect_user_requested_search, "user_requested_search": flags},
|
|
407
|
+
)
|
|
408
|
+
if spec.widget_objects:
|
|
409
|
+
listed = widget_refs(result)
|
|
410
|
+
missing = missing_objects(spec.widget_objects, listed)
|
|
411
|
+
_check("search_widget_objects", not missing, {"missing": missing, "listed": listed[:30]})
|
|
412
|
+
if spec.forbidden_parts:
|
|
413
|
+
streamed = [part.get("type") for part in result.unhandled_parts]
|
|
414
|
+
forbidden = [ptype for ptype in streamed if ptype in spec.forbidden_parts]
|
|
415
|
+
_check("search_forbidden_parts", not forbidden, {"forbidden": forbidden, "parts": streamed})
|
|
416
|
+
if spec.no_object_urls:
|
|
417
|
+
ids = tuple(ref.partition("/")[2] for ref in returned_refs(result))
|
|
418
|
+
urls = object_urls(result.text_response or "", ids)
|
|
419
|
+
_check("search_no_object_urls", not urls, {"object_urls": urls})
|
|
310
420
|
return checks, details
|
|
@@ -60,6 +60,7 @@ _DEFAULT_MAX_ITERATIONS = 4
|
|
|
60
60
|
|
|
61
61
|
_DRAFT_TOOL = "draft_document"
|
|
62
62
|
_BUILDER_SKILL = "document_builder"
|
|
63
|
+
_EDITOR_SKILL = "document_editor"
|
|
63
64
|
_PART_TYPE = "document"
|
|
64
65
|
_SET_SKILLS_TOOL = "set_skills"
|
|
65
66
|
# The Report names gen-ai sent before Publisher's Document names. Any of them on the wire means
|
|
@@ -389,6 +390,11 @@ def _rework(expected_output: dict) -> dict | None:
|
|
|
389
390
|
return rework if isinstance(rework, dict) else None
|
|
390
391
|
|
|
391
392
|
|
|
393
|
+
def _required_skill(expected_output: dict) -> str:
|
|
394
|
+
"""The skill the run must have activated: the editor edits the open document, the builder drafts a new one."""
|
|
395
|
+
return _EDITOR_SKILL if _rework(expected_output) is not None else _BUILDER_SKILL
|
|
396
|
+
|
|
397
|
+
|
|
392
398
|
def _validate_rework(rework: Any) -> None:
|
|
393
399
|
"""Reject a ``rework`` expectation the run could not score meaningfully.
|
|
394
400
|
|
|
@@ -1567,7 +1573,7 @@ def _execute_single_document_run(
|
|
|
1567
1573
|
tool_result,
|
|
1568
1574
|
graded_part,
|
|
1569
1575
|
expected_output,
|
|
1570
|
-
skill_activated=_skill_activated(all_tool_call_events,
|
|
1576
|
+
skill_activated=_skill_activated(all_tool_call_events, _required_skill(expected_output)),
|
|
1571
1577
|
legacy_names=legacy_wire_names(all_parts, all_tool_call_events),
|
|
1572
1578
|
exempt_takeaways=exempt,
|
|
1573
1579
|
)
|
|
@@ -1922,11 +1928,20 @@ def evaluate_agentic_document_skill(
|
|
|
1922
1928
|
if not best.evaluation.wire_names_current:
|
|
1923
1929
|
skill_note = " gen-ai still sends the Report names, so it predates the Document rename."
|
|
1924
1930
|
elif not best.evaluation.skill_activated:
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
)
|
|
1931
|
+
# Both document skills register under the same flags, so the other one being active
|
|
1932
|
+
# rules the flags out and leaves a routing failure.
|
|
1933
|
+
required_skill = _required_skill(expected_output)
|
|
1934
|
+
other_skill = _BUILDER_SKILL if required_skill == _EDITOR_SKILL else _EDITOR_SKILL
|
|
1935
|
+
if _skill_activated(best.tool_call_events, other_skill):
|
|
1936
|
+
skill_note = (
|
|
1937
|
+
f" It activated {other_skill} instead of {required_skill}: a routing failure, not the flags."
|
|
1938
|
+
)
|
|
1939
|
+
else:
|
|
1940
|
+
skill_note = (
|
|
1941
|
+
f" set_skills never activated {required_skill}: either the copilot routed elsewhere, or the"
|
|
1942
|
+
" skill is not registered. It registers only with enableGenAiReportBuilderSkill and the"
|
|
1943
|
+
" org's enableBusinessBriefingReportsApp both on."
|
|
1944
|
+
)
|
|
1930
1945
|
exc = DocumentSkillAssertionError(
|
|
1931
1946
|
f"Document skill assertion failed. {gate_note}{skill_note} "
|
|
1932
1947
|
f"Checks: {best.evaluation.strict_checks}. "
|
|
@@ -6,11 +6,14 @@ from __future__ import annotations
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
8
|
import time
|
|
9
|
+
from collections.abc import Callable
|
|
9
10
|
from dataclasses import dataclass, field
|
|
10
11
|
from typing import Any
|
|
11
12
|
|
|
12
13
|
import httpx
|
|
13
14
|
|
|
15
|
+
from gooddata_eval.core.agentic._clarification import read_first_reply
|
|
16
|
+
from gooddata_eval.core.agentic._conversation_context import asks_in_text
|
|
14
17
|
from gooddata_eval.core.agentic._failed_runs import build_failed_runs
|
|
15
18
|
from gooddata_eval.core.agentic._failure_message import FailedCheck, failed_check_records, failed_checks_from
|
|
16
19
|
from gooddata_eval.core.agentic._gate import (
|
|
@@ -20,7 +23,13 @@ from gooddata_eval.core.agentic._gate import (
|
|
|
20
23
|
log_gate_scores,
|
|
21
24
|
stamp_gate_metadata,
|
|
22
25
|
)
|
|
26
|
+
from gooddata_eval.core.agentic._kda_answer import (
|
|
27
|
+
check_answer_grounded,
|
|
28
|
+
check_suggestions_name_driver,
|
|
29
|
+
suggestions_from_turn,
|
|
30
|
+
)
|
|
23
31
|
from gooddata_eval.core.agentic._kda_expectation import (
|
|
32
|
+
KDA_BEHAVIOUR_SCORES,
|
|
24
33
|
KDA_FIELD_SCORES,
|
|
25
34
|
KdaExpectation,
|
|
26
35
|
KdaFieldResult,
|
|
@@ -28,6 +37,7 @@ from gooddata_eval.core.agentic._kda_expectation import (
|
|
|
28
37
|
parse_kda_expectation,
|
|
29
38
|
)
|
|
30
39
|
from gooddata_eval.core.agentic._outcome import (
|
|
40
|
+
CHAT_FAILURE_EXITS,
|
|
31
41
|
agentic_detail,
|
|
32
42
|
agentic_success,
|
|
33
43
|
chat_failure_exit,
|
|
@@ -45,9 +55,11 @@ from gooddata_eval.core.agentic._trace_linker import (
|
|
|
45
55
|
submit_trace_scoring,
|
|
46
56
|
utc_now,
|
|
47
57
|
)
|
|
58
|
+
from gooddata_eval.core.agentic.metric_skill import _judge_provider_errors
|
|
48
59
|
from gooddata_eval.core.chat.render import render_answer_text
|
|
49
60
|
from gooddata_eval.core.chat.sse_client import ChatClient, ChatError
|
|
50
61
|
from gooddata_eval.core.config import ReasoningEffort
|
|
62
|
+
from gooddata_eval.core.evaluators._llm_judge import JudgeVerdict, LLMJudge, score_run
|
|
51
63
|
from gooddata_eval.core.langfuse.item_scope import item_scope
|
|
52
64
|
from gooddata_eval.core.models import (
|
|
53
65
|
AgenticAssertionError,
|
|
@@ -63,6 +75,7 @@ from gooddata_eval.core.models import (
|
|
|
63
75
|
_log = logging.getLogger(__name__)
|
|
64
76
|
|
|
65
77
|
__all__ = [
|
|
78
|
+
"KDA_BEHAVIOUR_SCORES",
|
|
66
79
|
"KDA_FIELD_SCORES",
|
|
67
80
|
"AgenticKdaSummary",
|
|
68
81
|
"KdaEvaluation",
|
|
@@ -77,6 +90,11 @@ _DEFAULT_K = 1
|
|
|
77
90
|
# 3 real questions' worth (metric, period, +1 slack) since a simulated reply is now sent on
|
|
78
91
|
# every non-final turn (see run_agentic_kda_skill), not just ones classified as a question.
|
|
79
92
|
_DEFAULT_MAX_ITERATIONS = 4
|
|
93
|
+
_RUBRIC_STEPS = [
|
|
94
|
+
"EXPECTED OUTPUT states the criteria the assistant's behaviour must meet.",
|
|
95
|
+
"ACTUAL OUTPUT holds the conversation, user and assistant turns in order.",
|
|
96
|
+
"Pass only when the assistant's replies meet every criterion. Fail when any reply breaks one.",
|
|
97
|
+
]
|
|
80
98
|
|
|
81
99
|
|
|
82
100
|
def _hint_source(expected_output: dict) -> dict:
|
|
@@ -239,6 +257,13 @@ class KdaEvaluation:
|
|
|
239
257
|
An item with ``check_fields: true`` also gates on ``fields``: the measure, date attribute,
|
|
240
258
|
periods, non-date filters and summary of the create call and its execution. ``fields`` is
|
|
241
259
|
None when the item does not opt in or the run never called create.
|
|
260
|
+
|
|
261
|
+
``behaviour`` holds the checks of the item's behaviour keys, by score name without the
|
|
262
|
+
``kda_`` prefix, and ``behaviour_detail`` what each one compared. An item with
|
|
263
|
+
``expect_no_create`` gates on ``not_created`` in place of triggered, executed and success.
|
|
264
|
+
|
|
265
|
+
``unscored`` names the behaviour checks the harness could not grade (the judge gave no
|
|
266
|
+
verdict, the conversation could not be read). They read False, and ``harness_error`` says why.
|
|
242
267
|
"""
|
|
243
268
|
|
|
244
269
|
triggered: bool
|
|
@@ -247,18 +272,31 @@ class KdaEvaluation:
|
|
|
247
272
|
turn_completed: bool
|
|
248
273
|
disambiguated: bool = False
|
|
249
274
|
fields: KdaFieldResult | None = None
|
|
275
|
+
expect_no_create: bool = False
|
|
276
|
+
behaviour: dict[str, bool] = field(default_factory=dict)
|
|
277
|
+
behaviour_detail: dict[str, Any] = field(default_factory=dict)
|
|
278
|
+
unscored: tuple[str, ...] = ()
|
|
279
|
+
harness_error: str | None = None
|
|
250
280
|
|
|
251
281
|
@property
|
|
252
|
-
def
|
|
253
|
-
"""
|
|
254
|
-
|
|
282
|
+
def completion_checks(self) -> dict[str, bool]:
|
|
283
|
+
"""The completion checks the item gates on: ``expect_no_create`` drops the three it rules out."""
|
|
284
|
+
if self.expect_no_create:
|
|
285
|
+
return {"turn_completed": self.turn_completed}
|
|
286
|
+
return {
|
|
255
287
|
"triggered": self.triggered,
|
|
256
288
|
"executed": self.executed,
|
|
257
289
|
"success": self.success,
|
|
258
290
|
"turn_completed": self.turn_completed,
|
|
259
291
|
}
|
|
292
|
+
|
|
293
|
+
@property
|
|
294
|
+
def strict_checks(self) -> dict[str, bool]:
|
|
295
|
+
"""Every check strict_pass requires, by name."""
|
|
296
|
+
checks = dict(self.completion_checks)
|
|
260
297
|
if self.fields is not None:
|
|
261
298
|
checks.update({f"{name}_correct": ok for name, ok in self.fields.checks.items()})
|
|
299
|
+
checks.update(self.behaviour)
|
|
262
300
|
return checks
|
|
263
301
|
|
|
264
302
|
@property
|
|
@@ -309,10 +347,12 @@ def _evaluate_run(
|
|
|
309
347
|
turn_completed: bool,
|
|
310
348
|
disambiguated: bool = False,
|
|
311
349
|
spec: KdaExpectation | None = None,
|
|
350
|
+
behaviour: _BehaviourResult | None = None,
|
|
312
351
|
) -> KdaEvaluation:
|
|
313
352
|
triggered = create_args is not None
|
|
314
353
|
executed = execute_result is not None
|
|
315
354
|
success = executed and execute_result.get("success") is True
|
|
355
|
+
result = behaviour or _BehaviourResult()
|
|
316
356
|
return KdaEvaluation(
|
|
317
357
|
triggered=triggered,
|
|
318
358
|
executed=executed,
|
|
@@ -320,9 +360,107 @@ def _evaluate_run(
|
|
|
320
360
|
turn_completed=turn_completed,
|
|
321
361
|
disambiguated=disambiguated,
|
|
322
362
|
fields=check_kda_fields(spec, create_args, execute_result) if spec is not None else None,
|
|
363
|
+
expect_no_create=spec is not None and spec.expect_no_create,
|
|
364
|
+
behaviour={name: ok for name, (ok, _) in result.checks.items()},
|
|
365
|
+
behaviour_detail={name: detail for name, (_, detail) in result.checks.items()},
|
|
366
|
+
unscored=tuple(result.unscored),
|
|
367
|
+
harness_error="; ".join(result.harness_errors) or None,
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
@dataclass
|
|
372
|
+
class _BehaviourResult:
|
|
373
|
+
"""The behaviour checks of one run: each with what it compared, and those the harness could not grade."""
|
|
374
|
+
|
|
375
|
+
checks: dict[str, tuple[bool, Any]] = field(default_factory=dict)
|
|
376
|
+
unscored: list[str] = field(default_factory=list)
|
|
377
|
+
harness_errors: list[str] = field(default_factory=list)
|
|
378
|
+
|
|
379
|
+
def unscored_check(self, name: str, reason: str) -> None:
|
|
380
|
+
self.checks[name] = (False, {"harness_error": reason})
|
|
381
|
+
self.unscored.append(name)
|
|
382
|
+
self.harness_errors.append(f"{name}: {reason}")
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _ran_analysis(events: list[ToolCallEvent]) -> bool:
|
|
386
|
+
"""Whether any create or execute call in ``events`` succeeded."""
|
|
387
|
+
names = ("create_key_driver_analysis", "execute_key_driver_analysis")
|
|
388
|
+
return any(
|
|
389
|
+
tc.function_name in names and (_json_object(tc.parsed_result()) or {}).get("success") is True for tc in events
|
|
323
390
|
)
|
|
324
391
|
|
|
325
392
|
|
|
393
|
+
def _created(events: list[ToolCallEvent]) -> bool:
|
|
394
|
+
"""Whether a create call in ``events`` succeeded."""
|
|
395
|
+
return any(
|
|
396
|
+
tc.function_name == "create_key_driver_analysis"
|
|
397
|
+
and (_json_object(tc.parsed_result()) or {}).get("success") is True
|
|
398
|
+
for tc in events
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def _judge(judge: LLMJudge, rubric: str, question: str, transcript: list[tuple[str, str]]) -> JudgeVerdict:
|
|
403
|
+
conversation = "\n\n".join(f"{role}: {text}" for role, text in transcript)
|
|
404
|
+
try:
|
|
405
|
+
return score_run(judge, input=question, expected_output=rubric, actual_output=conversation)
|
|
406
|
+
except _judge_provider_errors() as exc:
|
|
407
|
+
return JudgeVerdict(passed=False, reasoning="", error=f"{type(exc).__name__}: {exc}")
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _behaviour_checks(
|
|
411
|
+
spec: KdaExpectation,
|
|
412
|
+
*,
|
|
413
|
+
judge: LLMJudge | None,
|
|
414
|
+
question: str,
|
|
415
|
+
turns: list[ChatResult],
|
|
416
|
+
texts: list[str],
|
|
417
|
+
transcript: list[tuple[str, str]],
|
|
418
|
+
events: list[ToolCallEvent],
|
|
419
|
+
asked_turn: int,
|
|
420
|
+
scored_turn: int | None,
|
|
421
|
+
execute_result: dict | None,
|
|
422
|
+
answered: bool,
|
|
423
|
+
read_suggestions: Callable[[int], Any],
|
|
424
|
+
) -> _BehaviourResult:
|
|
425
|
+
"""The checks of the item's behaviour keys, each with what it compared.
|
|
426
|
+
|
|
427
|
+
``asked_turn`` is the index of the turn that asked for the analysis: the last scripted one.
|
|
428
|
+
``scored_turn`` is the index of the turn whose analysis is scored, None when no turn ran one.
|
|
429
|
+
The answer and suggestion checks read that turn alone: an earlier clarification may name a
|
|
430
|
+
driver the analysis answer does not.
|
|
431
|
+
"""
|
|
432
|
+
result = _BehaviourResult()
|
|
433
|
+
checks = result.checks
|
|
434
|
+
if spec.expect_no_create:
|
|
435
|
+
# A run whose chat failed before any complete answer proves no refusal.
|
|
436
|
+
ran = _ran_analysis(events)
|
|
437
|
+
checks["not_created"] = (answered and not ran, {"analysis_ran": ran, "answered": answered})
|
|
438
|
+
if spec.expect_clarification is False:
|
|
439
|
+
created = asked_turn < len(turns) and _created(turns[asked_turn].tool_call_events or [])
|
|
440
|
+
checks["first_turn"] = (created, {"turn": asked_turn + 1, "created": created})
|
|
441
|
+
if spec.expect_clarification is True:
|
|
442
|
+
first = turns[0] if turns else None
|
|
443
|
+
asked = first is not None and read_first_reply(first, asked_in_text=asks_in_text(first, texts[0])).asked
|
|
444
|
+
created = first is not None and _created(first.tool_call_events or [])
|
|
445
|
+
checks["clarified"] = (asked and not created, {"asked": asked, "created_in_first_turn": created})
|
|
446
|
+
if spec.rubric and judge is not None:
|
|
447
|
+
verdict = _judge(judge, spec.rubric, question, transcript)
|
|
448
|
+
if verdict.error is not None:
|
|
449
|
+
result.unscored_check("rubric", f"judge gave no verdict: {verdict.error}")
|
|
450
|
+
else:
|
|
451
|
+
checks["rubric"] = (verdict.passed, {"reasoning": verdict.reasoning})
|
|
452
|
+
answer = texts[scored_turn] if scored_turn is not None and scored_turn < len(texts) else ""
|
|
453
|
+
if spec.check_answer:
|
|
454
|
+
checks["answer_grounded"] = check_answer_grounded(execute_result, answer)
|
|
455
|
+
if spec.check_suggestions:
|
|
456
|
+
try:
|
|
457
|
+
suggestions = read_suggestions(scored_turn) if scored_turn is not None else None
|
|
458
|
+
checks["suggestions"] = check_suggestions_name_driver(execute_result, answer, suggestions)
|
|
459
|
+
except (httpx.HTTPError, ValueError) as exc:
|
|
460
|
+
result.unscored_check("suggestions", f"{type(exc).__name__}: {exc}")
|
|
461
|
+
return result
|
|
462
|
+
|
|
463
|
+
|
|
326
464
|
def run_agentic_kda_skill(
|
|
327
465
|
host: str,
|
|
328
466
|
token: str,
|
|
@@ -346,11 +484,26 @@ def run_agentic_kda_skill(
|
|
|
346
484
|
visualization.py/alert_skill.py's own break conditions) -- missing a genuine
|
|
347
485
|
clarifying question hard-fails the run, while sending one after an unrecognized final
|
|
348
486
|
answer only costs one harmless extra turn, so the asymmetry favors never guessing.
|
|
487
|
+
|
|
488
|
+
An item with ``user_replies`` sends them after the question, one per turn, whatever the
|
|
489
|
+
agent did. The analysis is scored from the last scripted turn on, and the simulated user
|
|
490
|
+
takes over only after it, and ``max_iterations`` counts from the last scripted turn. An item
|
|
491
|
+
with ``expect_no_create`` gets no simulated reply.
|
|
492
|
+
|
|
493
|
+
Raises:
|
|
494
|
+
ValueError: The item is malformed. Raised before any request.
|
|
495
|
+
ImportError, OSError: The item has a rubric and the LLM judge cannot be built.
|
|
349
496
|
"""
|
|
350
497
|
if k < 1:
|
|
351
498
|
# k=0 or negative would otherwise silently run once, indistinguishable from k=1.
|
|
352
499
|
raise ValueError(f"k must be >= 1, got {k}")
|
|
353
500
|
spec = parse_kda_expectation(expected_output)
|
|
501
|
+
# Built before the first request: a missing judge is a setup error, not one to find after every run.
|
|
502
|
+
judge = LLMJudge(_RUBRIC_STEPS) if spec.rubric else None
|
|
503
|
+
scripted = [question, *spec.user_replies]
|
|
504
|
+
asked_turn = len(scripted) - 1
|
|
505
|
+
# max_iterations counts from the last scripted turn, as it counts from the question without replies.
|
|
506
|
+
budget = asked_turn + max_iterations
|
|
354
507
|
run_results: list[KdaRunResult] = []
|
|
355
508
|
client = ChatClient(
|
|
356
509
|
host=host,
|
|
@@ -373,6 +526,10 @@ def run_agentic_kda_skill(
|
|
|
373
526
|
response_id: str | None = None
|
|
374
527
|
all_tool_call_events: list[ToolCallEvent] = []
|
|
375
528
|
all_reasoning_step_events: list[ReasoningStepEvent] = []
|
|
529
|
+
turn_results: list[ChatResult] = []
|
|
530
|
+
texts: list[str] = []
|
|
531
|
+
scored_turn: int | None = None
|
|
532
|
+
transcript: list[tuple[str, str]] = []
|
|
376
533
|
turn_offset = 0.0 # each turn's call_ts/ts restarts near 0 -- shift by prior turns' wall time
|
|
377
534
|
tool_index_offset = 0
|
|
378
535
|
reasoning_index_offset = 0
|
|
@@ -396,8 +553,12 @@ def run_agentic_kda_skill(
|
|
|
396
553
|
steps = 0
|
|
397
554
|
|
|
398
555
|
run_started = time.monotonic()
|
|
399
|
-
for iteration in range(
|
|
556
|
+
for iteration in range(budget):
|
|
400
557
|
turns_used = iteration + 1
|
|
558
|
+
scored = iteration >= asked_turn
|
|
559
|
+
if iteration < len(scripted):
|
|
560
|
+
current_question = scripted[iteration]
|
|
561
|
+
transcript.append(("User", current_question))
|
|
401
562
|
try:
|
|
402
563
|
chat_result = client.send_message(conv_id, current_question)
|
|
403
564
|
except (ChatError, httpx.HTTPError) as exc:
|
|
@@ -413,9 +574,10 @@ def run_agentic_kda_skill(
|
|
|
413
574
|
reasoning_steps.extend(partial.reasoning_steps or [])
|
|
414
575
|
response_id = partial.response_id or response_id
|
|
415
576
|
_accumulate(partial)
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
577
|
+
if scored:
|
|
578
|
+
create_args, execute_result = _extract_kda_calls(partial.tool_call_events or [])
|
|
579
|
+
if create_args is not None:
|
|
580
|
+
turn_wall_clock_sec = partial.turn_wall_clock_sec
|
|
419
581
|
turn_completed = False
|
|
420
582
|
exit_reason = chat_failure_exit(exc)
|
|
421
583
|
break
|
|
@@ -424,9 +586,18 @@ def run_agentic_kda_skill(
|
|
|
424
586
|
reasoning_steps.extend(chat_result.reasoning_steps or [])
|
|
425
587
|
response_id = chat_result.response_id or response_id
|
|
426
588
|
_accumulate(chat_result)
|
|
427
|
-
create_args, execute_result = _extract_kda_calls(chat_result.tool_call_events or [])
|
|
428
589
|
response_text = render_answer_text(chat_result)
|
|
590
|
+
turn_results.append(chat_result)
|
|
591
|
+
texts.append(response_text)
|
|
592
|
+
transcript.append(("Assistant", response_text))
|
|
429
593
|
turn_completed = chat_result.stream_ended and bool(response_text)
|
|
594
|
+
if not scored:
|
|
595
|
+
# A scripted turn before the last one: the next scripted message goes out whatever it did.
|
|
596
|
+
if not response_text:
|
|
597
|
+
exit_reason = LoopExit.AGENT_SILENT
|
|
598
|
+
break
|
|
599
|
+
continue
|
|
600
|
+
create_args, execute_result = _extract_kda_calls(chat_result.tool_call_events or [])
|
|
430
601
|
if create_args is not None:
|
|
431
602
|
# This turn's own time -- the turn that called create, not any earlier
|
|
432
603
|
# disambiguation turn or the simulated-reply generation. create and execute
|
|
@@ -434,12 +605,17 @@ def run_agentic_kda_skill(
|
|
|
434
605
|
# final either way -- execute_result may still be None (e.g. the skill's
|
|
435
606
|
# execute tool isn't available at all when data-sharing is off for the org).
|
|
436
607
|
turn_wall_clock_sec = chat_result.turn_wall_clock_sec
|
|
608
|
+
scored_turn = iteration
|
|
437
609
|
exit_reason = LoopExit.SUCCESS
|
|
438
610
|
break
|
|
439
611
|
if not response_text:
|
|
440
612
|
exit_reason = LoopExit.AGENT_SILENT
|
|
441
613
|
break
|
|
442
|
-
if
|
|
614
|
+
if spec.expect_no_create:
|
|
615
|
+
# The answer without an analysis is the goal; a simulated reply would only push for one.
|
|
616
|
+
exit_reason = LoopExit.SUCCESS
|
|
617
|
+
break
|
|
618
|
+
if iteration >= budget - 1:
|
|
443
619
|
break
|
|
444
620
|
# No text classification -- matches visualization.py/alert_skill.py: break only on
|
|
445
621
|
# the goal signal (create_args set) or an empty response, otherwise always send a
|
|
@@ -457,7 +633,21 @@ def run_agentic_kda_skill(
|
|
|
457
633
|
exit_reason = LoopExit.SIMULATED_USER_FAILED
|
|
458
634
|
break
|
|
459
635
|
|
|
460
|
-
|
|
636
|
+
behaviour = _behaviour_checks(
|
|
637
|
+
spec,
|
|
638
|
+
judge=judge,
|
|
639
|
+
question=question,
|
|
640
|
+
turns=turn_results,
|
|
641
|
+
texts=texts,
|
|
642
|
+
transcript=transcript,
|
|
643
|
+
events=all_tool_call_events,
|
|
644
|
+
asked_turn=asked_turn,
|
|
645
|
+
scored_turn=scored_turn,
|
|
646
|
+
execute_result=execute_result,
|
|
647
|
+
answered=turn_completed,
|
|
648
|
+
read_suggestions=lambda turn: suggestions_from_turn(client.list_items(conv_id), turn),
|
|
649
|
+
)
|
|
650
|
+
ev = _evaluate_run(create_args, execute_result, turn_completed, disambiguated, spec, behaviour)
|
|
461
651
|
return KdaRunResult(
|
|
462
652
|
conversation_id=conv_id,
|
|
463
653
|
evaluation=ev,
|
|
@@ -515,14 +705,12 @@ def _run_detail(run: KdaRunResult) -> dict:
|
|
|
515
705
|
"""
|
|
516
706
|
ev = run.evaluation
|
|
517
707
|
return {
|
|
518
|
-
|
|
519
|
-
"executed": ev.executed,
|
|
520
|
-
"success": ev.success,
|
|
521
|
-
"turn_completed": ev.turn_completed,
|
|
708
|
+
**ev.completion_checks,
|
|
522
709
|
"disambiguated": ev.disambiguated,
|
|
523
710
|
"actual_create_args": run.actual_create_args,
|
|
524
711
|
"actual_execute_result": run.actual_execute_result,
|
|
525
712
|
**_field_detail(ev),
|
|
713
|
+
**_behaviour_detail(ev),
|
|
526
714
|
# Why the loop stopped -- see LoopExit. Per-run rather than best-only: on a failing
|
|
527
715
|
# run it is the first thing worth reading.
|
|
528
716
|
"exit_reason": run.exit_reason.value,
|
|
@@ -542,11 +730,39 @@ def _field_detail(ev: KdaEvaluation) -> dict:
|
|
|
542
730
|
}
|
|
543
731
|
|
|
544
732
|
|
|
733
|
+
def _behaviour_detail(ev: KdaEvaluation) -> dict:
|
|
734
|
+
"""The behaviour verdicts as top-level booleans, plus what each one compared."""
|
|
735
|
+
if not ev.behaviour:
|
|
736
|
+
return {}
|
|
737
|
+
return {**ev.behaviour, "behaviour_detail": ev.behaviour_detail}
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
def _harness_error_of(run: KdaRunResult) -> str | None:
|
|
741
|
+
"""The harness error, for the run's label, only when it is what left the run without a verdict.
|
|
742
|
+
|
|
743
|
+
A run that failed a check the harness did grade, or whose chat failed, is a FAIL whatever the
|
|
744
|
+
unscored checks would have said.
|
|
745
|
+
"""
|
|
746
|
+
ev = run.evaluation
|
|
747
|
+
if not ev.harness_error or run.exit_reason in CHAT_FAILURE_EXITS:
|
|
748
|
+
return None
|
|
749
|
+
graded = [ok for name, ok in ev.strict_checks.items() if name not in ev.unscored]
|
|
750
|
+
return ev.harness_error if all(graded) else None
|
|
751
|
+
|
|
752
|
+
|
|
545
753
|
def _failed_checks(run: KdaRunResult) -> list[dict]:
|
|
546
|
-
"""The checks this run failed, by name
|
|
754
|
+
"""The checks this run failed, by name: a field check with its expected and actual value, a behaviour
|
|
755
|
+
check with what it compared."""
|
|
547
756
|
ev = run.evaluation
|
|
548
|
-
completion = {
|
|
757
|
+
completion = {
|
|
758
|
+
name: ok for name, ok in ev.strict_checks.items() if not name.endswith("_correct") and name not in ev.behaviour
|
|
759
|
+
}
|
|
549
760
|
records = failed_checks_from(completion)
|
|
761
|
+
records += failed_check_records(
|
|
762
|
+
FailedCheck(name, actual=ev.behaviour_detail.get(name))
|
|
763
|
+
for name, ok in ev.behaviour.items()
|
|
764
|
+
if not ok and name not in ev.unscored
|
|
765
|
+
)
|
|
550
766
|
if ev.fields is not None:
|
|
551
767
|
records += failed_check_records(
|
|
552
768
|
FailedCheck(f"{name}_correct", expected=ev.fields.expected[name], actual=ev.fields.actual[name])
|
|
@@ -612,7 +828,9 @@ def evaluate_agentic_kda_skill(
|
|
|
612
828
|
)
|
|
613
829
|
|
|
614
830
|
# Before the Langfuse scores, so an ERROR run gets its marker beside its usual scores.
|
|
615
|
-
run_labels = label_runs(
|
|
831
|
+
run_labels = label_runs(
|
|
832
|
+
summary.run_results, passed=lambda r: r.evaluation.strict_pass, judge_error=_harness_error_of
|
|
833
|
+
)
|
|
616
834
|
|
|
617
835
|
if langfuse is not None and dataset_item_id:
|
|
618
836
|
# Pinned on the calling thread: a deferred poll must not widen its query window.
|
|
@@ -627,8 +845,9 @@ def evaluate_agentic_kda_skill(
|
|
|
627
845
|
pt = ctx.trace(run.conversation_id)
|
|
628
846
|
run_name = ctx.run_name(run_idx)
|
|
629
847
|
ev = run.evaluation
|
|
630
|
-
# Gates strict_pass: completion, plus the
|
|
631
|
-
|
|
848
|
+
# Gates strict_pass: completion, plus the field and behaviour checks of an item that opts in.
|
|
849
|
+
# An unscored check is not published: the run's eval_error marker says why it has no verdict.
|
|
850
|
+
strict_checks = {f"kda_{name}": ok for name, ok in ev.strict_checks.items() if name not in ev.unscored}
|
|
632
851
|
# Not pt.latency: pt can be any trace of the conversation, not necessarily the KDA turn.
|
|
633
852
|
turn_wall_clock_sec = run.turn_wall_clock_sec
|
|
634
853
|
_log.info(
|
|
@@ -681,14 +900,12 @@ def evaluate_agentic_kda_skill(
|
|
|
681
900
|
detail = agentic_detail(
|
|
682
901
|
best.tool_call_events,
|
|
683
902
|
best.reasoning_step_events,
|
|
684
|
-
|
|
685
|
-
executed=ev.executed,
|
|
686
|
-
success=ev.success,
|
|
687
|
-
turn_completed=ev.turn_completed,
|
|
903
|
+
**ev.completion_checks,
|
|
688
904
|
disambiguated=ev.disambiguated,
|
|
689
905
|
actual_create_args=best.actual_create_args,
|
|
690
906
|
actual_execute_result=best.actual_execute_result,
|
|
691
907
|
**_field_detail(ev),
|
|
908
|
+
**_behaviour_detail(ev),
|
|
692
909
|
# Why the loop stopped -- see LoopExit.
|
|
693
910
|
exit_reason=best.exit_reason.value,
|
|
694
911
|
turns_used=best.turns_used,
|
|
@@ -710,6 +927,7 @@ def evaluate_agentic_kda_skill(
|
|
|
710
927
|
f"(triggered={ev.triggered}, executed={ev.executed}, "
|
|
711
928
|
f"success={ev.success}, turn_completed={ev.turn_completed}"
|
|
712
929
|
+ (f", fields={ev.fields.checks}" if ev.fields is not None else "")
|
|
930
|
+
+ (f", behaviour={ev.behaviour}" if ev.behaviour else "")
|
|
713
931
|
+ "). "
|
|
714
932
|
f"Actual create args: {best.actual_create_args}. "
|
|
715
933
|
f"Actual execute result: {best.actual_execute_result}."
|
|
@@ -91,6 +91,10 @@ SEARCH_CONDITIONAL_SCORES = (
|
|
|
91
91
|
"search_answer",
|
|
92
92
|
"search_limit",
|
|
93
93
|
"search_no_raw_ids",
|
|
94
|
+
"search_user_requested",
|
|
95
|
+
"search_widget_objects",
|
|
96
|
+
"search_forbidden_parts",
|
|
97
|
+
"search_no_object_urls",
|
|
94
98
|
)
|
|
95
99
|
# The names a score takes where it does not gate the item: every check of a report_only item, and tool_selection of
|
|
96
100
|
# an item with search_required false. A score name then means the same on every item.
|
|
@@ -112,12 +116,10 @@ def _tool_selection(tool_call_events: list[ToolCallEvent]) -> bool:
|
|
|
112
116
|
return any(tc.function_name == SEARCH_TOOL for tc in tool_call_events)
|
|
113
117
|
|
|
114
118
|
|
|
115
|
-
# Arguments
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
# rename -- this path did not, so every fixture written against the older signature
|
|
120
|
-
# scored tool_correctness=False while still passing on tool_selection alone.
|
|
119
|
+
# Arguments `tool_correctness` does not compare, so a fixture naming them does not fail
|
|
120
|
+
# the call. `limit` has a server-side default the agent is free to choose; `emit_widget`
|
|
121
|
+
# is the old name of `user_requested_search`. To check `user_requested_search`, an item
|
|
122
|
+
# sets the option `expect_user_requested_search`, which gates the run.
|
|
121
123
|
_IGNORED_SEARCH_ARGS = frozenset({"limit", "emit_widget", "user_requested_search"})
|
|
122
124
|
|
|
123
125
|
|
|
@@ -70,6 +70,7 @@ _KNOWN_PART_TYPES: frozenset[str] = frozenset(
|
|
|
70
70
|
"dashboard",
|
|
71
71
|
"dashboardPatch",
|
|
72
72
|
"document",
|
|
73
|
+
"report",
|
|
73
74
|
"kda",
|
|
74
75
|
"whatIf",
|
|
75
76
|
"searchResults",
|
|
@@ -78,6 +79,9 @@ _KNOWN_PART_TYPES: frozenset[str] = frozenset(
|
|
|
78
79
|
}
|
|
79
80
|
)
|
|
80
81
|
|
|
82
|
+
# The part types ``_handle_multipart`` leaves in ``unhandled_parts``: every known type but the four it routes.
|
|
83
|
+
UNHANDLED_PART_TYPES: frozenset[str] = _KNOWN_PART_TYPES - {"text", "visualization", "alertProposal", "searchResults"}
|
|
84
|
+
|
|
81
85
|
|
|
82
86
|
class ChatError(RuntimeError):
|
|
83
87
|
"""Non-retryable error reported by the chat SSE stream.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: gooddata-eval
|
|
3
|
-
Version: 1.81.1.
|
|
3
|
+
Version: 1.81.1.dev5
|
|
4
4
|
Summary: Evaluate the GoodData AI agent against your own questions and models.
|
|
5
5
|
Project-URL: Source, https://github.com/gooddata/gooddata-python-sdk
|
|
6
6
|
Author-email: GoodData <support@gooddata.com>
|
|
@@ -18,7 +18,7 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
18
18
|
Classifier: Topic :: Software Development
|
|
19
19
|
Classifier: Typing :: Typed
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
|
-
Requires-Dist: gooddata-sdk~=1.81.1.
|
|
21
|
+
Requires-Dist: gooddata-sdk~=1.81.1.dev5
|
|
22
22
|
Requires-Dist: httpx<1.0,>=0.27
|
|
23
23
|
Requires-Dist: jsonpatch<2.0,>=1.33
|
|
24
24
|
Requires-Dist: orjson<4.0.0,>=3.9.15
|
|
@@ -1222,6 +1222,48 @@ fail `kda_filters_correct`; omitted ones are no filters. The six names are `KDA_
|
|
|
1222
1222
|
create publishes none of them. A failing run reports the expected and the actual value of each
|
|
1223
1223
|
field it failed.
|
|
1224
1224
|
|
|
1225
|
+
A `ranking_filter` in `Filters` is compared on `using`, `attribute` (`label/` and `attribute/` are the
|
|
1226
|
+
same), `top` or `bottom`, and `strict_limit_of_rows` (unset reads as false). It needs `using`, `attribute`
|
|
1227
|
+
and one of `top`, `bottom` as a positive integer, as the execute tool does, and any other key is rejected.
|
|
1228
|
+
|
|
1229
|
+
### `agentic_kda_skill` behaviour checks
|
|
1230
|
+
|
|
1231
|
+
Each key below is opt-in and adds one score, which gates `strict_pass` like the others:
|
|
1232
|
+
|
|
1233
|
+
| Key | Score | Passes when |
|
|
1234
|
+
|---|---|---|
|
|
1235
|
+
| `"expect_no_create": true` | `kda_not_created` | the agent answered and no create or execute call succeeded (a create the tool rejected is allowed). The item is then not scored on `kda_triggered`, `kda_executed` or `kda_success`, and gets no simulated reply. It cannot be combined with `check_fields`, `check_answer`, `check_suggestions` or `expect_clarification` |
|
|
1236
|
+
| `"expect_clarification": false` | `kda_first_turn` | the turn that asked for the analysis (the last scripted one) created it |
|
|
1237
|
+
| `"expect_clarification": true` | `kda_clarified` | the first turn asks a question and creates no analysis |
|
|
1238
|
+
| `"rubric": "<criteria>"` | `kda_rubric` | an LLM judge reads the whole conversation and finds every criterion met |
|
|
1239
|
+
| `"check_answer": true` | `kda_answer_grounded` | an analysis ran, and the answer of the turn that ran it names one of its `significant_drivers` |
|
|
1240
|
+
| `"check_suggestions": true` | `kda_suggestions` | an analysis ran, and when its answer names a driver, the first suggested action of that turn names one of those drivers |
|
|
1241
|
+
|
|
1242
|
+
`"user_replies": ["...", ...]` sends scripted messages after the question, one per turn, in the
|
|
1243
|
+
same conversation, whatever the agent did. The analysis is scored from the last scripted turn on;
|
|
1244
|
+
the simulated user takes over after it. `max_iterations` counts from the last scripted turn, as it counts
|
|
1245
|
+
from the question of an item without replies: with the default 4, three simulated replies can follow.
|
|
1246
|
+
With `"expect_clarification": true`, the first turn is the one that must ask, and the replies answer
|
|
1247
|
+
that question. A clarification asked on a later turn cannot be expressed.
|
|
1248
|
+
|
|
1249
|
+
A driver counts as named when its value appears as a whole word, plural allowed. Date values and
|
|
1250
|
+
values shorter than three characters are skipped, and `10,769` matches `10769`.
|
|
1251
|
+
|
|
1252
|
+
A judge that gives no verdict, or a conversation whose suggestions cannot be read, leaves that check
|
|
1253
|
+
unscored: it reads False, is not listed as failed and is not published as a score. The run is labelled ERROR when every other check
|
|
1254
|
+
passed and the chat did not fail; otherwise it is a FAIL on the checks that were graded. The six
|
|
1255
|
+
names are `KDA_BEHAVIOUR_SCORES`; an item publishes only those of the keys it sets.
|
|
1256
|
+
|
|
1257
|
+
```json
|
|
1258
|
+
{
|
|
1259
|
+
"question": "Why is it so high?",
|
|
1260
|
+
"expected_output": {
|
|
1261
|
+
"expect_no_create": true,
|
|
1262
|
+
"rubric": "Describes the step-up the chart shows and proposes breakdowns that exist in the workspace. Runs no key driver analysis."
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1225
1267
|
### Items asked in a dashboard context (`user_context`)
|
|
1226
1268
|
|
|
1227
1269
|
An item can be asked the way a user asks from an open dashboard or an attached widget.
|
|
@@ -27,12 +27,13 @@ gooddata_eval/core/agentic/_failed_runs.py,sha256=1D3vFCKG4TUnNUdci6NO1yJlBFZ8GQ
|
|
|
27
27
|
gooddata_eval/core/agentic/_failure_message.py,sha256=PvjDyyBHni-m69UskjSs6oXEJcQVKAfcKkNJ5R-Xjm4,8036
|
|
28
28
|
gooddata_eval/core/agentic/_filters.py,sha256=arAesTihu67a-1xccREfN1KBj46Jm-dOJrBfajz67Lc,2009
|
|
29
29
|
gooddata_eval/core/agentic/_gate.py,sha256=9hwdjSm8RFPw9I-NF4s4hTUcVl1aD9RWp8RcRvLdp7U,3074
|
|
30
|
-
gooddata_eval/core/agentic/
|
|
30
|
+
gooddata_eval/core/agentic/_kda_answer.py,sha256=6AOrmxQ5c2oIUI9vZi8eb7EywP4_bb1d-fzit2HHySM,6402
|
|
31
|
+
gooddata_eval/core/agentic/_kda_expectation.py,sha256=p-_qFhiyNL6zMgNcZunchwq4ObGU4KTZrEZBzFiUcao,22109
|
|
31
32
|
gooddata_eval/core/agentic/_langfuse.py,sha256=74_pf1XU6fQG6qrgRB18XYrMlO69tnH1uNi5TJWPt-o,29706
|
|
32
33
|
gooddata_eval/core/agentic/_metric_expectation.py,sha256=mlhmVDEDgg4pkfOXmPSjwa7i8D6p3fYaEoMisGLVdVw,20520
|
|
33
34
|
gooddata_eval/core/agentic/_metric_workspace.py,sha256=5qQAdWtneniFqFtZoc4K7vQlrGD7cj8ErruQNgdu-po,11878
|
|
34
35
|
gooddata_eval/core/agentic/_outcome.py,sha256=AL1ULyD9zpC8A-MhyLp2CW68Rnezl39heRkHr7xcbEA,13478
|
|
35
|
-
gooddata_eval/core/agentic/_search_expectation.py,sha256=
|
|
36
|
+
gooddata_eval/core/agentic/_search_expectation.py,sha256=EstJtdhFkfaU0LL7hB7HPAMQh06P7dUqY1DqLRDqlR8,19927
|
|
36
37
|
gooddata_eval/core/agentic/_trace_linker.py,sha256=Bc-UOPB3bcJqb6kmHnkMnbNVbZPPB7Dn5awM7bNm-qY,15851
|
|
37
38
|
gooddata_eval/core/agentic/agent_switcher.py,sha256=DWkv2iB0RGzM4-wLkhoru4b8fPYHDwYaBPcSVcjZ74g,37636
|
|
38
39
|
gooddata_eval/core/agentic/alert_skill.py,sha256=fgwxAMcdtZbjLuyc92egHmclVG0yvt7MhH_rO3cGe50,111660
|
|
@@ -40,16 +41,16 @@ gooddata_eval/core/agentic/anomaly_detection.py,sha256=XMd0zsS3hgASJND6UwhNXdoBX
|
|
|
40
41
|
gooddata_eval/core/agentic/conversation.py,sha256=AC-k4ju2Ic_X8UkERLWHstNKKBGTtrj7p-Ld-82K8T8,75946
|
|
41
42
|
gooddata_eval/core/agentic/dashboard_skill.py,sha256=a0RLxlf_LGp0tt3Pk3V27-9Lmw5iFEFSKjOCvJ8lvS0,145855
|
|
42
43
|
gooddata_eval/core/agentic/dashboard_summary.py,sha256=6H-IXJvEkQQ69454GGayDSXzEa9apgoih18U_6so6gI,24438
|
|
43
|
-
gooddata_eval/core/agentic/document_skill.py,sha256=
|
|
44
|
+
gooddata_eval/core/agentic/document_skill.py,sha256=GPxMlXurtROqODPcJEJgHoLorbb4nQGHPb472x3nytY,92616
|
|
44
45
|
gooddata_eval/core/agentic/forecasting.py,sha256=vpq0BOuXNaMqlbPOt_MQi6avw6eqkbqcQ7Ql28KEZME,26965
|
|
45
46
|
gooddata_eval/core/agentic/general_question.py,sha256=YPaz7tbeV0lTHlfmUPNvJ5FD6y-nh5ZqpwLSQqpJI4Y,20480
|
|
46
47
|
gooddata_eval/core/agentic/guardrail.py,sha256=_7-nlBNVnGaYJx9Oq8V08npe1IunxgwH1bqKs0yplhY,17904
|
|
47
|
-
gooddata_eval/core/agentic/kda_skill.py,sha256=
|
|
48
|
+
gooddata_eval/core/agentic/kda_skill.py,sha256=V8wSxZG0C3DbGt1dQe339dvwq3pircc6hCsNXvPv9BA,42384
|
|
48
49
|
gooddata_eval/core/agentic/knowledge.py,sha256=hVAyQwCmewjTAdvfNHz6517obwxr3-KRb8yxmBkL1j4,17836
|
|
49
50
|
gooddata_eval/core/agentic/memory.py,sha256=HT89Ei3ZpV2AUlhW3DxV2jBx2BlrZQk4Ay8TbIeVmWY,24213
|
|
50
51
|
gooddata_eval/core/agentic/metric_skill.py,sha256=PX-nSGsszJYZHC4tUu732rwSrXjfA23YpHtJOVccdqw,64702
|
|
51
52
|
gooddata_eval/core/agentic/report_skill.py,sha256=ZpuKuQpor56ywDKauzQKAx18vFHcW6uq3nFgV2GjVvM,1583
|
|
52
|
-
gooddata_eval/core/agentic/search_tool.py,sha256=
|
|
53
|
+
gooddata_eval/core/agentic/search_tool.py,sha256=pHDKt9537OPKUWjYKPRyC0mUIACWFblG_TXCTgVJSb8,30517
|
|
53
54
|
gooddata_eval/core/agentic/visualization.py,sha256=TmXCe5cUQoWebAUQlbJYO0LohVIamBHgb_-5uRsQDNI,39239
|
|
54
55
|
gooddata_eval/core/agentic/what_if.py,sha256=AA3DJOrtezRLnUxzq48olwSgDQN6Qfwqfbx5XnsQhrA,28746
|
|
55
56
|
gooddata_eval/core/catalog/__init__.py,sha256=U54lANKm34yjqm7dZL9KkGouPbwAaQWC9wiAmb5B5g4,32
|
|
@@ -57,7 +58,7 @@ gooddata_eval/core/catalog/evaluate.py,sha256=Uf4ABvlIY0ks5OKTUpJsoFKHBai390cPid
|
|
|
57
58
|
gooddata_eval/core/catalog/http_client.py,sha256=OsT6tvSVXirSRkwKGGikJpAE1zETQO7V5KBLzvOm800,4439
|
|
58
59
|
gooddata_eval/core/chat/__init__.py,sha256=U54lANKm34yjqm7dZL9KkGouPbwAaQWC9wiAmb5B5g4,32
|
|
59
60
|
gooddata_eval/core/chat/render.py,sha256=wfA5opgrWt-H9L-H8hJm1zBR0kIEqvFros8gtG1_yXo,2116
|
|
60
|
-
gooddata_eval/core/chat/sse_client.py,sha256=
|
|
61
|
+
gooddata_eval/core/chat/sse_client.py,sha256=Yg_Tt7J1oStClOdP7MfrL-3vBfhRndwtdXMuSCJ6Wdo,38635
|
|
61
62
|
gooddata_eval/core/dataset/__init__.py,sha256=U54lANKm34yjqm7dZL9KkGouPbwAaQWC9wiAmb5B5g4,32
|
|
62
63
|
gooddata_eval/core/dataset/from_insights.py,sha256=v4Ev_WZHFzRFnGBzEyDppe-JvKW1I-WQwVHMHXXJ6wU,41212
|
|
63
64
|
gooddata_eval/core/dataset/langfuse_source.py,sha256=u_JaSGNQu4ztqdwnNHfS8v1dPSckM8DVCIzQGHYaQgg,12212
|
|
@@ -98,8 +99,8 @@ gooddata_eval/core/summary/http_client.py,sha256=Umae42fiiJQ0e4hv63NRROHYvcFAGgX
|
|
|
98
99
|
gooddata_eval/core/takeaway/__init__.py,sha256=U54lANKm34yjqm7dZL9KkGouPbwAaQWC9wiAmb5B5g4,32
|
|
99
100
|
gooddata_eval/core/takeaway/evaluate.py,sha256=AjS_rCHWUSJKv0jfEfL0-dVPoDaf3RkGdmeZiIwjd6A,11312
|
|
100
101
|
gooddata_eval/core/takeaway/http_client.py,sha256=YMfafOcHJ184i49Qoh0ZNPKKTMKBSgeDUM4zk_H3yM8,3955
|
|
101
|
-
gooddata_eval-1.81.1.
|
|
102
|
-
gooddata_eval-1.81.1.
|
|
103
|
-
gooddata_eval-1.81.1.
|
|
104
|
-
gooddata_eval-1.81.1.
|
|
105
|
-
gooddata_eval-1.81.1.
|
|
102
|
+
gooddata_eval-1.81.1.dev5.dist-info/METADATA,sha256=Usc5zskggHCv5FF70hHFCghC-kUWzfUiqnQHdKBHBmg,85131
|
|
103
|
+
gooddata_eval-1.81.1.dev5.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
104
|
+
gooddata_eval-1.81.1.dev5.dist-info/entry_points.txt,sha256=28nFp5Viknx4haPYgzK9QHlwPFfC6rPF6RmjC2ht8EI,56
|
|
105
|
+
gooddata_eval-1.81.1.dev5.dist-info/licenses/LICENSE.txt,sha256=LVfVlC9maU3K9lgMwdZnClQQsOIbOekdcdVKr9qzJtk,256836
|
|
106
|
+
gooddata_eval-1.81.1.dev5.dist-info/RECORD,,
|
|
File without changes
|
{gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{gooddata_eval-1.81.1.dev3.dist-info → gooddata_eval-1.81.1.dev5.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|