Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/35058-asked-back-asks-after-comma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): the asked-back "asks" check reads a request phrase that follows a comma

Clause-②: no
Metadata-protocol: none

A Chinese ask-back that put its request after a comma and used no question mark (「我不替你选,请确认你要哪一个:」) failed `asked-back:asks` with "the reply asks the person nothing": a request phrase counted only at the start of the text, a line or a sentence. A request phrase (`please confirm`, `could you clarify`, 请确认, 请说明, 您是指 and the rest of the list) now also asks after a clause mark of either width (`,` `,` `;` `;` `:` `:`). The phrase must still open its clause, so a quoted one (「点“请确认”提交」) or a reported one (`I asked finance to please confirm`) asks nothing, and `which one` / `which of` still counts only at the start of a sentence, because after a comma it is usually a relative clause. A reply that states a figure still fails `asked-back:no-figure`, whatever it asks.

`asked-back` is now at rule revision 3 (`DATASET_GRADER_REVISIONS`), so its grades carry `revision: 3` and the `Run · datasets` row reads `asked-back rev 3 k/N`. A round graded at revision 2 is not compared like for like with one graded now. A replay (`--driver recorded:F`) grades with the current rules.
5 changes: 3 additions & 2 deletions packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // a
- `scenario-dataset-grade.ts` — a card's dataset question (`run.datasetQuestions`) graded on the route the answer took,
never its figure (`gradeDatasetQuestion`; card-level `gradeCardDatasetQuestion`), by the grader its expected route
names: `metric-selected` (a `query_dataset` answer whose `provenance` names the expected dataset and measure; the
arguments the model sent decide nothing), `asked-back` (the reply asks, names every candidate by a word other than
arguments the model sent decide nothing), `asked-back` (the reply asks — a question mark, or a request phrase such as `please confirm` or
请确认 opening a sentence or a clause, after `,` `,` `;` `:` and the like — names every candidate by a word other than
the asked one, and states no figure; an option list's numbering, an option named by its place — `option 2`, `the
3rd one`, 「第 1 个」 — a count of the options it offers — `2 metrics`, 「2 个指标」 — a date, and a year a time word
or 年 marks are no figure, unless a counted noun follows it: `for 2031 orders`) and `fallback-labelled` (an object query on the expected object answered, no dataset did, and the reply
says the figure is not a governed metric: a closed word list, English and Chinese, in `labelsFallback`). Its notes
say what the turn did on the way, ungraded: a loaded skill, no `list_datasets` call, the `candidates` a
`list_datasets` answer offered. A grader whose rule has changed stamps its grade with `revision`
(`DATASET_GRADER_REVISIONS`, which says what each revision changed; absent ⇒ revision 1): `asked-back` is at 2.
(`DATASET_GRADER_REVISIONS`, which says what each revision changed; absent ⇒ revision 1): `asked-back` is at 3.
- `scenario-run-grade.ts` — an answer graded on correct / cited / leaks, per persona against
that persona's truth; a `withheld` truth is must-not-reveal. A figure computed over rows
outside the persona's scope is flagged only when no figure of the persona's own rows
Expand Down
26 changes: 22 additions & 4 deletions packages/qa/scenarios/src/score/scenario-dataset-grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ export interface DatasetGrade {
* - `asked-back` 2: an option named by its place (`option 2`, `the 3rd one`,
* 「第 1 个」) and a date whose year follows a time word (`through
* 2026-11-17`) are no figure.
* - `asked-back` 3: a request phrase (请确认, `please confirm`) after a
* clause mark (`,` `,` `;` `;` `:` `:`) asks, as it did after a
* sentence's end.
*/
export const DATASET_GRADER_REVISIONS: Readonly<Partial<Record<DatasetGrader, number>>> = { 'asked-back': 2 };
export const DATASET_GRADER_REVISIONS: Readonly<Partial<Record<DatasetGrader, number>>> = { 'asked-back': 3 };

/**
* The app tools that answer a question from object records: the MCP door's
Expand Down Expand Up @@ -101,11 +104,26 @@ function provenanceOf(c: Call): { dataset: string; measures: string[] } | undefi
return { dataset: p.dataset.name, measures };
}

/** A request for the person's choice (`please confirm`, 请确认, 您是指): it asks wherever a sentence or a clause opens with it. */
const REQUEST_PHRASE = String.raw`(?:please (?:confirm|clarify|specify|tell me|let me know)|could you (?:clarify|confirm|specify)|请(?:确认|说明|告诉我|明确)|您是指|你是指)`;

/**
* The reply asks the person something: a question mark (either width), or
* one of the asking phrases below at a line's or sentence's start.
* The reply asks the person something: a question mark (either width), or an
* asking phrase that opens what it is part of.
*
* - A request phrase ({@link REQUEST_PHRASE}) opens the text, a line, a
* sentence (after `.` `。` `!` `!`) or a clause (after `,` `,` `;` `;`
* `:` `:`, either width): 「我不替你选,请确认你要哪一个:」 asks with no
* question mark.
* - `which one` / `which of` opens the text, a line or a sentence only:
* after a comma it is as often a relative clause (`…, which of course
* differ`) as a question, and a question spelled that way ends in a
* question mark.
*
* A phrase inside a clause asks nothing: quoted (「点“请确认”提交」) or
* reported (`I asked finance to please confirm the totals`).
*/
const ASKS = /[??]|(?:^|[.。!!\n]\s*)(?:please (?:confirm|clarify|specify|tell me|let me know)|could you (?:clarify|confirm|specify)|which (?:one|of)|请(?:确认|说明|告诉我|明确)|您是指|你是指)/i;
const ASKS = new RegExp(String.raw`[??]|(?:^|[.。!!\n,,;;::]\s*)${REQUEST_PHRASE}|(?:^|[.。!!\n]\s*)which (?:one|of)`, 'i');

/** Numbered-list markers (`1.`, `2)`, `3、`) at a line's start: an option list's numbering, never a figure. */
const LIST_MARKER = /^[ \t]*(?:[-*][ \t]+)?\(?\d{1,2}(?:[.)][ \t]+|、[ \t]*)/gm;
Expand Down
72 changes: 63 additions & 9 deletions packages/qa/scenarios/test/score/scenario-dataset-grade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ describe('asked-back — asks which reading is meant, names every candidate, sta
});
});

describe('asked-back on recorded replies — an option named by its place and a date are no figure (travel_expense dq_travel_spend)', () => {
const TRAVEL = resolve(HERE, '../../../../../docs/qa/scenarios/travel_expense.json');
const travel = (() => {
const { card, refusals } = loadScenarioFile(TRAVEL, { areas: readCapabilityAreas(AREAS), library: 'open' });
expect(refusals).toEqual([]);
return namespacedScenario(card!);
})();
const gradeTravel = (replyText: string) => gradeCardDatasetQuestion(travel, 'dq_travel_spend', { replyText, toolCalls: [] });
const TRAVEL = resolve(HERE, '../../../../../docs/qa/scenarios/travel_expense.json');
const travel = (() => {
const { card, refusals } = loadScenarioFile(TRAVEL, { areas: readCapabilityAreas(AREAS), library: 'open' });
expect(refusals).toEqual([]);
return namespacedScenario(card!);
})();
const gradeTravel = (replyText: string) => gradeCardDatasetQuestion(travel, 'dq_travel_spend', { replyText, toolCalls: [] });

describe('asked-back on recorded replies — an option named by its place and a date are no figure (travel_expense dq_travel_spend)', () => {
// A recorded zh reply (five-rep with-skill round, repeat 2): it was graded "the reply states 1, 3, 1, 3".
const ZH = [
'这个问题有几种口径,我需要你先确认用哪一个,然后再计算。平台里有三个指标都可能对应「差旅花费」:',
Expand All @@ -188,7 +188,7 @@ describe('asked-back on recorded replies — an option named by its place and a
for (const reply of [ZH, EN]) {
expect(statedFigures(reply)).toEqual([]);
const g = gradeTravel(reply);
expect([g.grader, g.pass, failed(g), g.revision]).toEqual(['asked-back', true, [], 2]);
expect([g.grader, g.pass, failed(g), g.revision]).toEqual(['asked-back', true, [], 3]);
}
});

Expand Down Expand Up @@ -236,6 +236,60 @@ describe('asked-back on recorded replies — an option named by its place and a
});
});

describe('asked-back:asks — a request phrase after a clause mark asks, with no question mark (travel_expense dq_travel_spend)', () => {
// A recorded zh reply (ask-loop iteration 6, repeat 3): 请确认 follows a full-width comma and no ? is in it.
const ZH = [
'“差旅花费总额”有两个口径都能对上,我不替你选,请确认你要哪一个:',
'',
'- **Estimated spend(预计费用)**,来自数据集 **Trip plan(出差计划)**。说明:所有状态的出差申请预计费用总和。',
'- **Claimed amount(报销金额)**,来自数据集 **Reimbursement(报销)**。说明:所有报销单的总额之和,包括已驳回的。',
'',
'另外,数据集 **Travel spend** 也叫“差旅花费”,但它的指标(Spend,即报销行金额之和)没有匹配这个词,所以我没有把它列为选项。如果你要的是它的口径,告诉我即可。',
'',
'确定口径后,我会按该指标计算总额,并注明来源和统计范围。',
].join('\n');

it('the recorded reply passes every asked-back check at revision 3', () => {
const g = gradeTravel(ZH);
expect([g.grader, g.pass, failed(g), g.revision]).toEqual(['asked-back', true, [], 3]);
});

it('a request phrase after a clause mark of either width asks: ,, ;; ::', () => {
for (const reply of [
'有两个口径,请确认:报销金额或预计费用',
'有两个口径;请说明要报销金额还是预计费用',
'有两个口径: 您是指报销金额还是预计费用',
'Two measures match, please confirm which: claimed amount or estimated spend',
'Two measures match; could you clarify whether you mean claimed amount or estimated spend',
'Two measures match: please let me know if you want claimed amount or estimated spend',
]) {
const g = gradeTravel(reply);
expect([reply, g.pass, failed(g)]).toEqual([reply, true, []]);
}
});

it('a figure in a reply whose 请确认 sits mid-sentence still fails no-figure', () => {
for (const [reply, figures] of [
[`${ZH}\n目前报销金额合计 10,290 元。`, [10290]],
['报销金额合计 10,290 元,请确认是否按报销金额还是预计费用', [10290]],
] as const) {
expect([reply.slice(-40), failed(gradeTravel(reply))]).toEqual([reply.slice(-40), ['asked-back:no-figure']]);
expect(statedFigures(reply)).toEqual(figures);
}
});

it('a phrase inside a clause asks nothing — quoted, reported, or `which of` as a relative clause after a comma', () => {
for (const reply of [
'报销金额和预计费用都在页面上,点“请确认”提交即可。',
'I asked finance to please confirm the claimed amount and the estimated spend.',
'There are two measures, claimed amount and estimated spend, which of course differ.',
'Claimed amount and estimated spend are both defined, which one team maintains.',
]) {
expect([reply, failed(gradeTravel(reply))]).toEqual([reply, ['asked-back:asks']]);
}
});
});

describe('fallback-labelled — an object query answered, and the reply says it is not a governed metric', () => {
const countPayments = { name: 'aggregate_records', input: { objectName: 'demoorder_payment', aggregations: [{ function: 'count' }] }, output: '{"value":72}' };

Expand Down
Loading