Skip to content

Commit 1a2baa1

Browse files
Merge pull request #1944 from gooddata/snapshot-master-5f40cd0d-to-rel/dev
[bot] Merge master/5f40cd0d into rel/dev
2 parents 9792c2d + 5f40cd0 commit 1a2baa1

29 files changed

Lines changed: 1961 additions & 250 deletions

‎packages/gooddata-eval/src/gooddata_eval/cli/agentic_runner.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from gooddata_eval.core.agentic.dashboard_skill import evaluate_agentic_dashboard_skill
1919
from gooddata_eval.core.agentic.dashboard_summary import evaluate_agentic_dashboard_summary
2020
from gooddata_eval.core.agentic.document_skill import evaluate_agentic_document_skill
21+
from gooddata_eval.core.agentic.forecasting import evaluate_agentic_forecasting
2122
from gooddata_eval.core.agentic.general_question import evaluate_agentic_general_question
2223
from gooddata_eval.core.agentic.guardrail import evaluate_agentic_guardrail
2324
from gooddata_eval.core.agentic.kda_skill import evaluate_agentic_kda_skill
@@ -57,6 +58,7 @@ class _LfKw(TypedDict, total=False):
5758
"agentic_guardrail",
5859
"agentic_conversation",
5960
"agentic_kda_skill",
61+
"agentic_forecasting",
6062
"agentic_dashboard_summary",
6163
"agentic_anomaly_detection",
6264
"agentic_what_if",
@@ -305,6 +307,19 @@ def _dispatch_agentic(
305307
user_context=item.user_context,
306308
**lf_kw,
307309
)
310+
elif kind == "agentic_forecasting":
311+
return evaluate_agentic_forecasting(
312+
host=host,
313+
token=token,
314+
workspace_id=workspace_id,
315+
question=item.question,
316+
expected_output=eo if isinstance(eo, dict) else {},
317+
k=k,
318+
gate=gate,
319+
agent_id=agent_id,
320+
user_context=item.user_context,
321+
**lf_kw,
322+
)
308323
elif kind == "agentic_dashboard_summary":
309324
summary_input = item.summary_input
310325
if summary_input is None:
@@ -428,6 +443,18 @@ def _apply_timings(item_report: ItemReport, timings: Any) -> None:
428443
item_report.simulated_user_latency_s = timings.simulated_user_s
429444

430445

446+
def _apply_best_run_latency(item_report: ItemReport, source: Any) -> None:
447+
"""Copy the rank-selected run's own wall time, mirroring the single-shot path's
448+
``ItemReport.best_run_latency_s`` (see ``core/runner.py``'s ``_run_one_item``).
449+
450+
Kinds not yet wired to measure it pass None and keep the field at its own None
451+
default rather than reporting an invented number.
452+
"""
453+
best_run_latency_s = getattr(source, "best_run_latency_s", None)
454+
if best_run_latency_s is not None:
455+
item_report.best_run_latency_s = best_run_latency_s
456+
457+
431458
def run_agentic_items(
432459
items: list[DatasetItem],
433460
host: str,
@@ -525,6 +552,7 @@ def _process_item(index: int, item: DatasetItem) -> ItemReport:
525552
item_report.response_id = response_id
526553
item_report.best_detail = detail or {}
527554
_apply_timings(item_report, getattr(outcome, "timings", None))
555+
_apply_best_run_latency(item_report, outcome)
528556
_apply_run_counts(item_report, outcome)
529557
_apply_failed_runs(item_report, outcome)
530558
_apply_run_latencies(item_report, outcome)
@@ -536,6 +564,7 @@ def _process_item(index: int, item: DatasetItem) -> ItemReport:
536564
item_report.response_id = getattr(exc, "response_id", None)
537565
item_report.best_detail = getattr(exc, "detail", None) or {}
538566
_apply_timings(item_report, getattr(exc, "timings", None))
567+
_apply_best_run_latency(item_report, exc)
539568
_apply_run_counts(item_report, exc)
540569
_apply_failed_runs(item_report, exc)
541570
_apply_run_latencies(item_report, exc)
@@ -579,6 +608,7 @@ def _process_item(index: int, item: DatasetItem) -> ItemReport:
579608
# runs and then raised would otherwise show up in the per-response table and not in
580609
# the per-conversation one.
581610
traces.discard()
611+
_apply_best_run_latency(item_report, exc)
582612
finally:
583613
item_report.latency_s = time.perf_counter() - t0
584614
item_report.trace_latencies_s = traces.stop()
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# (C) 2026 GoodData Corporation
2+
"""The common tail of every ``evaluate_agentic_*`` function.
3+
4+
Before this module, each of the agentic evaluators hand-wrote the same block: copy
5+
``reasoning_steps``/``conversation_id``/``response_id``/``detail``/``runs_passed``/
6+
``runs_effective``/``best_run_latency_s`` (and sometimes ``timings``) either onto a
7+
raised exception or into the returned ``AgenticEvalOutcome``. Eleven independent copies
8+
of the same ~7 lines meant a new universal field needed eleven edits, not one, and
9+
nothing failed loudly when a copy was missed -- exactly what happened to ``timings``
10+
(see ``AgenticAssertionError``'s docstring: "while it lived in eight copies, two
11+
declared timings and six did not") and again to ``best_run_latency_s`` (every agentic
12+
kind silently reported it as ``null`` until this was noticed and fixed kind-by-kind).
13+
14+
``agentic_detail`` has the same motivation for the ``detail`` dict's timeline fields:
15+
``timeline_detail`` builds both ``latency_breakdown`` and ``tool_calls`` from the same
16+
events so they stay index-aligned, but roughly half the evaluators called
17+
``build_latency_breakdown`` directly and silently never got a ``tool_calls`` key.
18+
"""
19+
20+
from __future__ import annotations
21+
22+
from typing import Any, NoReturn
23+
24+
from gooddata_eval.core.models import (
25+
AgenticAssertionError,
26+
AgenticEvalOutcome,
27+
ReasoningStepEvent,
28+
ToolCallEvent,
29+
timeline_detail,
30+
)
31+
from gooddata_eval.core.timing import PhaseTimings
32+
33+
__all__ = ["agentic_detail", "agentic_success", "raise_agentic_failure"]
34+
35+
36+
def agentic_detail(
37+
tool_call_events: list[ToolCallEvent],
38+
reasoning_step_events: list[ReasoningStepEvent] | None,
39+
**kind_specific: Any,
40+
) -> dict:
41+
"""A kind's full ``detail`` dict: its own fields plus the universal timeline ones.
42+
43+
``kind_specific`` comes first in the merge so a kind can never accidentally shadow
44+
``latency_breakdown``/``tool_calls`` with a same-named field of its own.
45+
"""
46+
return {**kind_specific, **timeline_detail(tool_call_events, reasoning_step_events)}
47+
48+
49+
def raise_agentic_failure(
50+
exception_cls: type[AgenticAssertionError],
51+
message: str,
52+
*,
53+
reasoning_steps: list[str],
54+
conversation_id: str,
55+
response_id: str | None,
56+
detail: dict,
57+
runs_passed: int,
58+
runs_effective: int,
59+
best_run_latency_s: float | None,
60+
timings: PhaseTimings | None = None,
61+
failed_runs: list[dict] | None = None,
62+
run_latencies_s: list[float] | None = None,
63+
) -> NoReturn:
64+
"""Build ``exception_cls(message)`` with every common field attached, and raise it.
65+
66+
``exception_cls`` must be an ``AgenticAssertionError`` subclass -- that base class is
67+
what declares these fields as legal targets (see its docstring). A kind whose own
68+
"no verdict at all" branch raises a bare ``JudgeResponseError`` instead (not a subclass)
69+
does not go through this helper for that branch.
70+
71+
``timings`` stays optional: only the three kinds that track per-run ``PhaseTimings``
72+
(general_question, metric_skill, dashboard_skill) pass one -- the rest keep their
73+
own ``PhaseTimings()`` zero default, same as before this helper existed. ``failed_runs``
74+
and ``run_latencies_s`` are likewise optional: not every kind has built them by the
75+
time it raises.
76+
"""
77+
exc = exception_cls(message)
78+
exc.reasoning_steps = reasoning_steps
79+
exc.conversation_id = conversation_id
80+
exc.response_id = response_id
81+
exc.detail = detail
82+
exc.runs_passed = runs_passed
83+
exc.runs_effective = runs_effective
84+
exc.best_run_latency_s = best_run_latency_s
85+
if timings is not None:
86+
exc.timings = timings
87+
if failed_runs is not None:
88+
exc.failed_runs = failed_runs
89+
if run_latencies_s is not None:
90+
exc.run_latencies_s = run_latencies_s
91+
raise exc
92+
93+
94+
def agentic_success(
95+
*,
96+
reasoning_steps: list[str],
97+
conversation_id: str | None,
98+
response_id: str | None,
99+
detail: dict,
100+
runs_passed: int,
101+
runs_effective: int,
102+
best_run_latency_s: float | None,
103+
timings: PhaseTimings | None = None,
104+
failed_runs: list[dict] | None = None,
105+
run_latencies_s: list[float] | None = None,
106+
) -> AgenticEvalOutcome:
107+
"""The success-path mirror of ``raise_agentic_failure`` -- same fields, same shape."""
108+
kwargs: dict[str, Any] = {
109+
"reasoning_steps": reasoning_steps,
110+
"conversation_id": conversation_id,
111+
"response_id": response_id,
112+
"detail": detail,
113+
"runs_passed": runs_passed,
114+
"runs_effective": runs_effective,
115+
"best_run_latency_s": best_run_latency_s,
116+
}
117+
if timings is not None:
118+
kwargs["timings"] = timings
119+
if failed_runs is not None:
120+
kwargs["failed_runs"] = failed_runs
121+
if run_latencies_s is not None:
122+
kwargs["run_latencies_s"] = run_latencies_s
123+
return AgenticEvalOutcome(**kwargs)

‎packages/gooddata-eval/src/gooddata_eval/core/agentic/alert_skill.py‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
log_gate_scores,
2424
stamp_gate_metadata,
2525
)
26+
from gooddata_eval.core.agentic._outcome import agentic_detail, agentic_success, raise_agentic_failure
2627
from gooddata_eval.core.agentic._trace_linker import (
2728
RunIdentity,
2829
RunTraceContext,
@@ -700,7 +701,8 @@ class AlertRunResult:
700701
# also report operator/threshold/metric/recipients as False.
701702
exit_reason: LoopExit = LoopExit.BUDGET_EXHAUSTED
702703
turns_used: int = 0
703-
# This run's own wall time, from just before its chat call to the end of its scoring.
704+
# This run's own wall time, across all its turns -- mirrors the single-shot
705+
# path's best_run_latency_s (see core/runner.py's _run_one_item).
704706
run_latency_s: float = 0.0
705707

706708

@@ -975,6 +977,7 @@ def run_agentic_alert_skill(
975977

976978
def _run_once(conv_id: str) -> AlertRunResult:
977979
alert_id_to_delete: str | None = None
980+
run_started = time.monotonic()
978981
try:
979982
alert_id: str | None = None
980983
actual_args: dict = {}
@@ -1260,9 +1263,25 @@ def _write_scores(ctx: RunTraceContext) -> None:
12601263

12611264
best = summary.best
12621265
ev = best.eval
1263-
# max_iterations is the same for every run, so it stays at the item level rather than
1264-
# being repeated into each failing run's detail.
1265-
detail = {**_run_detail(best), "max_iterations": max_iterations}
1266+
detail = agentic_detail(
1267+
best.tool_call_events,
1268+
best.reasoning_step_events,
1269+
alert_created=ev.alert_created,
1270+
operator_correct=ev.operator_correct,
1271+
threshold_correct=ev.threshold_correct,
1272+
trigger_correct=ev.trigger_correct,
1273+
filters_correct=ev.filters_correct,
1274+
metric_correct=ev.metric_correct,
1275+
recipients_correct=ev.recipients_correct,
1276+
attributes_correct=ev.attributes_correct,
1277+
granularity_correct=ev.granularity_correct,
1278+
actual_alert_arguments=best.actual_alert_arguments,
1279+
# Why the loop stopped. alert_created=False alone cannot tell a refusal from a run
1280+
# that hit max_iterations while still on track -- see LoopExit.
1281+
exit_reason=best.exit_reason.value,
1282+
turns_used=best.turns_used,
1283+
max_iterations=max_iterations,
1284+
)
12661285
# Same predicate runs_passed is taken over, so an item's failed_runs and its counts
12671286
# cannot disagree about which runs failed.
12681287
failed_runs = build_failed_runs(
@@ -1273,29 +1292,34 @@ def _write_scores(ctx: RunTraceContext) -> None:
12731292

12741293
if not gate_passed(gate, pass_at_k=summary.pass_at_k, pass_power_k=summary.pass_power_k):
12751294
gate_note = gate_failure_note(gate, runs_passed, runs_effective)
1276-
exc = AlertSkillAssertionError(
1295+
raise_agentic_failure(
1296+
AlertSkillAssertionError,
12771297
f"Alert skill assertion failed. {gate_note} strict_pass={ev.strict_pass}. "
1278-
+ ", ".join(f"{name}={value}" for name, value in ev.checks().items())
1279-
+ f". Actual args: {best.actual_alert_arguments}"
1298+
f"alert_created={ev.alert_created}, operator_correct={ev.operator_correct}, "
1299+
f"threshold_correct={ev.threshold_correct}, trigger_correct={ev.trigger_correct}, "
1300+
f"filters_correct={ev.filters_correct}, metric_correct={ev.metric_correct}, "
1301+
f"recipients_correct={ev.recipients_correct}, "
1302+
f"attributes_correct={ev.attributes_correct}, "
1303+
f"granularity_correct={ev.granularity_correct}. "
1304+
f"Actual args: {best.actual_alert_arguments}",
1305+
reasoning_steps=best.reasoning_steps,
1306+
conversation_id=best.conversation_id,
1307+
response_id=best.response_id,
1308+
detail=detail,
1309+
runs_passed=runs_passed,
1310+
runs_effective=runs_effective,
1311+
failed_runs=failed_runs,
1312+
run_latencies_s=[r.run_latency_s for r in summary.run_results],
1313+
best_run_latency_s=best.run_latency_s,
12801314
)
1281-
exc.reasoning_steps = best.reasoning_steps
1282-
exc.conversation_id = best.conversation_id
1283-
exc.response_id = best.response_id
1284-
exc.detail = detail
1285-
exc.runs_passed = runs_passed
1286-
exc.runs_effective = runs_effective
1287-
exc.failed_runs = failed_runs
1288-
exc.run_latencies_s = [r.run_latency_s for r in summary.run_results]
1289-
raise exc
1290-
return AgenticEvalOutcome(
1291-
runs_passed=runs_passed,
1292-
runs_effective=runs_effective,
1315+
return agentic_success(
12931316
reasoning_steps=best.reasoning_steps,
12941317
conversation_id=best.conversation_id,
12951318
response_id=best.response_id,
12961319
detail=detail,
1297-
# Also on the success path: pass@K clears the gate with one passing run, so a
1298-
# 1/3 item reports success while two of its runs failed for reasons worth reading.
1320+
runs_passed=runs_passed,
1321+
runs_effective=runs_effective,
12991322
failed_runs=failed_runs,
13001323
run_latencies_s=[r.run_latency_s for r in summary.run_results],
1324+
best_run_latency_s=best.run_latency_s,
13011325
)

0 commit comments

Comments
 (0)