Skip to content

Commit adcbd45

Browse files
authored
Merge pull request #1965 from gooddata/qa-29478-sim-user-choice
fix(gooddata-eval): sim user prompt names the date dataset and pick
2 parents d0c7e6b + 9be7fa5 commit adcbd45

4 files changed

Lines changed: 110 additions & 7 deletions

File tree

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ def generate_simulated_alert_response(
592592

593593
original_request = f'Your original request to the agent was: "{question}"\n' if question else ""
594594

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+
595610
# Only a stated title is enforced: an unstated one is the agent's to choose, and telling the
596611
# sim-user nothing keeps it from objecting to a generated name.
597612
title_rule = (
@@ -607,8 +622,11 @@ def generate_simulated_alert_response(
607622
+ original_request
608623
+ "Rules you MUST follow:\n"
609624
f"1. Your goal: metric={metric}, operator={operator}, threshold={threshold}, "
610-
f"recipients={recipients}, trigger={trigger_key}" + (f", filters={filters}" if filters else "") + ".\n"
611-
"2. Never revert or change a decision that was already confirmed in a previous turn.\n"
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"
612630
"3. If the agent shows a final summary, an alert proposal or asks for confirmation, check "
613631
" ALL of these against your goal: recipients, trigger (how often you are alerted), "
614632
" filters / time window, threshold and operator. If ANY of them differs — for example the "

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ class AgenticRunSummary:
108108
def generate_simulated_response(agent_message: str, expected_output: CreatedVisualization) -> str:
109109
"""Generate a simulated user reply to an agent clarification question.
110110
111-
Uses OpenAI gpt-5.2 to produce a realistic reply that guides the agent
112-
toward the expected visualization without revealing the answer directly.
111+
Uses OpenAI gpt-5.2 to produce a realistic reply that guides the agent toward the
112+
expected visualization without revealing the answer directly. Objects are named in words
113+
made from their ids (`uri_to_display_name`: `metric/total_returns` -> "total returns"), not
114+
by their titles, which are not available here, and never as `{type/id}` references: a goal
115+
of references makes the simulated user volunteer them, handing the agent objects it should
116+
resolve itself. A date filter names its date dataset the same way, without which the
117+
simulated user cannot say which date "2024" means.
113118
Requires the [llm-judge] extra: pip install gooddata-eval[llm-judge]
114119
"""
115120
try:
@@ -138,10 +143,12 @@ def generate_simulated_response(agent_message: str, expected_output: CreatedVisu
138143
granularity = filter_dict.get("granularity", "")
139144
from_val = filter_dict.get("from", "")
140145
to_val = filter_dict.get("to", "")
146+
dataset = filter_dict.get("using")
147+
on_dataset = f" on the {uri_to_display_name(dataset)}" if isinstance(dataset, str) and dataset else ""
141148
filter_parts.append(
142-
f"date filter: {granularity} from {from_val} to {to_val}"
149+
f"date filter{on_dataset}: {granularity} from {from_val} to {to_val}"
143150
if granularity
144-
else f"date filter: {from_val} to {to_val}"
151+
else f"date filter{on_dataset}: {from_val} to {to_val}"
145152
)
146153
elif ft == "ranking_filter":
147154
n = filter_dict.get("top") or filter_dict.get("bottom")
@@ -196,7 +203,9 @@ def generate_simulated_response(agent_message: str, expected_output: CreatedVisu
196203
f"Respond naturally to the agent's question. Be helpful and answer what they're asking about.\n"
197204
f"If the agent asks specifically about items from your goal (like which metrics or dimensions "
198205
f"you want), you should mention them. Keep your response concise and natural, as a real user would."
199-
f"{no_filter_hint}"
206+
f"{no_filter_hint}\n"
207+
f"If the agent offers alternatives, choose the one that matches your goal and repeat it as the "
208+
f"agent wrote it."
200209
),
201210
},
202211
],

‎packages/gooddata-eval/tests/test_agentic_alert_skill.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,3 +1950,27 @@ def test_exit_reason_names_the_agents_own_chat_failure(exc, exit_value):
19501950

19511951
assert detail["exit_reason"] == exit_value
19521952
assert detail["alert_created"] is False
1953+
1954+
1955+
# The agent offers metrics as {type/id} and may describe one as ignoring filters, which read
1956+
# like rule 5's "no filters"; the simulated user named that metric instead of the fixture's.
1957+
def test_sim_user_is_told_which_offered_metric_to_choose() -> None:
1958+
prompt = _sim_user_prompt({"Operator": "LESS_THAN", "Threshold": 1000, "metric_id": "of_orders"})
1959+
assert "choose the option for your goal metric (of_orders;" in prompt
1960+
assert "repeat that option as the agent wrote it" in prompt
1961+
assert "never changes which metric you want: rule 5 is about filters on the alert" in prompt
1962+
# The reply repeats the agent's option; the prompt hands it no reference to volunteer.
1963+
assert "metric/of_orders" not in prompt
1964+
1965+
1966+
# When the fixture's metric is the all-time one, nothing in the rule may steer away from it.
1967+
def test_sim_user_choice_rule_does_not_argue_against_an_all_time_goal() -> None:
1968+
prompt = _sim_user_prompt({"Operator": "LESS_THAN", "Threshold": 1000, "metric_id": "orders_all_time"})
1969+
assert "choose the option for your goal metric (orders_all_time;" in prompt
1970+
assert "different metric" not in prompt
1971+
1972+
1973+
def test_sim_user_without_a_metric_gets_no_metric_choice_rule() -> None:
1974+
assert "choose the option for your goal metric" not in _sim_user_prompt(
1975+
{"Operator": "LESS_THAN", "Threshold": 1000}
1976+
)

‎packages/gooddata-eval/tests/test_agentic_visualization.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,55 @@ def test_execute_single_run_records_the_agents_own_failure_on_a_follow_up(monkey
854854
result = _execute_single_run(client, "conv-1", "Show revenue", [_expected()])
855855

856856
assert result.exit_reason is loop_exit
857+
858+
859+
def _sim_user_call(agent_message: str, viz: CreatedVisualization) -> Any:
860+
"""Run the visualization sim-user against a stub OpenAI client and return the call it made."""
861+
fake_openai = MagicMock()
862+
fake_openai.return_value.chat.completions.create.return_value = MagicMock(
863+
choices=[MagicMock(message=MagicMock(content="ok"))]
864+
)
865+
with patch("openai.OpenAI", fake_openai), patch.dict("os.environ", {"OPENAI_API_KEY": "test-key"}):
866+
agentic_visualization.generate_simulated_response(agent_message, viz)
867+
return fake_openai.return_value.chat.completions.create.call_args
868+
869+
870+
def _returns_by_category_in_2024() -> CreatedVisualization:
871+
return CreatedVisualization.model_validate(
872+
{
873+
"id": "v1",
874+
"type": "table",
875+
"query": {
876+
"fields": {"m": {"using": "metric/total_returns"}, "d": {"using": "label/product_category"}},
877+
"filter_by": {
878+
"f": {
879+
"type": "date_filter",
880+
"using": "dataset/return_date",
881+
"granularity": "YEAR",
882+
"from": "2024-01-01",
883+
"to": "2024-12-31",
884+
}
885+
},
886+
},
887+
"metrics": ["m"],
888+
"view_by": ["d"],
889+
}
890+
)
891+
892+
893+
# A date filter without its dataset cannot say whether "2024" is the order or the return date;
894+
# objects given by reference made the simulated user volunteer them to the agent.
895+
def test_sim_user_goal_names_the_date_dataset_and_no_reference() -> None:
896+
prompt = _sim_user_call("Which date should define 2024?", _returns_by_category_in_2024()).kwargs["messages"][1][
897+
"content"
898+
]
899+
goal = prompt.split("Your goal")[1]
900+
assert "Metrics: total returns\n" in goal
901+
assert "date filter on the return date: YEAR from 2024-01-01 to 2024-12-31" in goal
902+
assert "{" not in goal
903+
assert "choose the one that matches your goal" in goal
904+
905+
906+
def test_sim_user_goal_keeps_dimensions_by_name() -> None:
907+
prompt = _sim_user_call("Which chart?", _returns_by_category_in_2024()).kwargs["messages"][1]["content"]
908+
assert "Dimensions: product category\n" in prompt

0 commit comments

Comments
 (0)