From 18f0d4bc3b21af610cd17658358168b03a1d1904 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 14:22:44 +0000 Subject: [PATCH 1/4] wip: next-step note asks nothing beside a fallback word Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../src/__tests__/dataset-tools.test.ts | 63 +++++++++++++++++-- .../src/dataset-next-step.ts | 44 +++++++++---- .../service-analytics/src/dataset-tools.ts | 5 +- 3 files changed, 94 insertions(+), 18 deletions(-) diff --git a/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts b/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts index c166b121d34..787cfbc6d9c 100644 --- a/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts +++ b/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts @@ -1291,6 +1291,13 @@ const ASK_FIRST: Record = { 'ja-JP': '使う前にどれを指しているかユーザーに確認してください。代わりに選ばないでください', }; const FOUR_LOCALES = [ADMIN, { ...ADMIN, locale: 'zh-CN' }, { ...ADMIN, locale: 'zh-TW' }, { ...ADMIN, locale: 'ja-JP' }] as ExecutionContext[]; +/** The question owed to a grouping that stands alone (D3 rule 5), by the locale the context names. */ +const WHICH_NUMBER: Record = { + en: 'ask the user which number they mean', + 'zh-CN': '问用户想看哪个数字', + 'zh-TW': '問使用者想看哪個數字', + 'ja-JP': 'どの数値を知りたいかユーザーに確認してください', +}; type ListOut = Awaited['listDatasets']>>; @@ -1400,11 +1407,22 @@ describe('[#34919] list_datasets nextStep on examples/app-crm — the decision e expect((await ask(['商机数', '商机金额'])).nextStep!.note).toContain('Each is its own metric'); }); - it('a mixed no_measure note falls back for the unknown word and still asks which number the grouping word means', async () => { - const out = await ask(['库存周转', '销售阶段']); - expect(out.nextStep).toMatchObject({ decision: 'no_measure', terms: ['库存周转', '销售阶段'] }); - expect(out.nextStep!.note).toContain('query_records'); - expect(out.nextStep!.note).toContain('ask the user which number they mean'); + // [#34996] One object answers "库存周转 by 销售阶段" through the fallback, so the + // note carries the fallback and no question: a note that said both was read as + // "ask". The grouping word is still named as the grouping it equals. + it('a mixed no_measure note falls back for the unknown word and asks nothing: the grouping does not stand alone', async () => { + for (const ctx of FOUR_LOCALES) { + const out = await ask(['库存周转', '销售阶段'], ctx); + const where = String(ctx.locale ?? 'en'); + expect(out.nextStep, where).toMatchObject({ decision: 'no_measure', terms: ['库存周转', '销售阶段'] }); + expect(out.nextStep!.note, where).toContain('query_records'); + expect(out.nextStep!.note, where).toContain('Stage'); + expect(out.nextStep!.note, `${where} ⇒ no question`).not.toContain(WHICH_NUMBER[where]); + // The control, same locale: alone, the grouping word still asks which number is meant, and sends nobody to the object tools. + const alone = (await ask(['销售阶段'], ctx)).nextStep!.note; + expect(alone, `${where} ⇒ alone asks`).toContain(WHICH_NUMBER[where]); + expect(alone, where).not.toContain('query_records'); + } }); it('a word with two matches ⇒ several_measures, the note naming each by its label and its dataset\'s label', async () => { @@ -1621,6 +1639,41 @@ describe('[#35005] list_datasets nextStep — a grouping or time word with a can } expect((await ask(['this quarter'])).nextStep!.note).toContain('ask the user which number they mean'); }); + + // [#34996] "How many sales orders this quarter?" with no order-count measure: + // "sales orders" is unknown and "this quarter" is near a dimension. The object + // tools answer the count, so the note offers the grouping, sends the unknown + // word to its labelled fallback and asks nothing. + it('a grouping candidate beside an unknown word: the unknown word falls back and nobody is asked which number', async () => { + for (const ctx of FOUR_LOCALES) { + const out = await ask(['sales orders', 'this quarter'], ctx); + expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['this quarter'] }); + expect(out.candidates).toEqual([{ term: 'this quarter', dataset: 'sales_metrics', member: 'dimensions.quarter' }]); + const note = out.nextStep!.note; + expect(note, loc(ctx)).toContain(GROUPING_OFFER[loc(ctx)]); + expect(note, loc(ctx)).toContain('sales orders'); + expect(note, loc(ctx)).toContain('query_records'); + expect(note, `${loc(ctx)} ⇒ no question`).not.toContain(WHICH_NUMBER[loc(ctx)]); + expect(note, loc(ctx)).not.toContain(ASK_BEFORE_COMPUTING[loc(ctx)]); + // The control, same locale: with no unknown word beside it, the grouping candidate still asks which number. + expect((await ask(['this quarter'], ctx)).nextStep!.note, `${loc(ctx)} ⇒ alone asks`).toContain(WHICH_NUMBER[loc(ctx)]); + // And a word that equals a dimension beside the candidate is a second grouping, not a fallback: still asked. + const groupings = (await ask(['this quarter', 'industry'], ctx)).nextStep!.note; + expect(groupings, `${loc(ctx)} ⇒ two groupings ask`).toContain(WHICH_NUMBER[loc(ctx)]); + expect(groupings, loc(ctx)).not.toContain('query_records'); + } + }); + + // [#34996] The several-matches and measure-candidate questions are untouched + // by the above: an unknown word beside them changes nothing about the ask. + it('an unknown word beside a measure candidate does not remove the question about that candidate', async () => { + for (const ctx of FOUR_LOCALES) { + const out = await ask(['销售', 'sales orders'], ctx); + expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['销售'] }); + expect(out.nextStep!.note, loc(ctx)).toContain(ASK_BEFORE_COMPUTING[loc(ctx)]); + expect(out.nextStep!.note, loc(ctx)).toContain('query_records'); + } + }); }); describe('[#34919] list_datasets nextStep — an incomplete catalogue says so (N4)', () => { diff --git a/packages/services/service-analytics/src/dataset-next-step.ts b/packages/services/service-analytics/src/dataset-next-step.ts index 432c7f9f236..b241cbd65a5 100644 --- a/packages/services/service-analytics/src/dataset-next-step.ts +++ b/packages/services/service-analytics/src/dataset-next-step.ts @@ -91,11 +91,27 @@ import type { PlatformLocaleTag } from '@objectstack/spec/system'; * measure and offers 行业 as a possible grouping, with no question; * `["库存周转", "金额"]` asks about 金额's candidates and names 库存周转 with * its fallback. A reported `candidates_only` word whose candidates are all - * dimensions is offered the same way, and with no measure word beside it the - * note asks which number is meant, as a grouping word does (D3 rule 5). (`several_measures` asks before anything is computed, so its + * dimensions is offered the same way, and when every word sent is a grouping + * the note asks which number is meant, as a grouping word does (D3 rule 5; the + * next section says when). (`several_measures` asks before anything is computed, so its * note needs no such tail.) Two words that equal the same measure are one * metric, and the note says so. * + * ## A grouping beside a word that falls back asks nothing + * + * [#34996] "Which number is meant" (D3 rule 5) is the question for a grouping + * that stands alone: every word sent equals only a dimension, or has only + * dimensions among its candidates. An unknown word beside it (no measure, no + * dimension, no candidate) is in rule 4, the labelled fallback to the object + * query tools, and that fallback computes the number the user named: "sales + * orders" beside "status" is a count of sales orders by status, as it was + * before any dataset listed a `status` dimension (M2, ruled A: the fallback + * answers what the object tools answer today). So the note then carries the + * fallback sentence and no question: `["sales orders", "status"]` and + * `["库存周转", "销售阶段"]` fall back, and `["销售阶段"]` or `["this quarter"]` + * alone still ask which number is meant. One note never says both: a reader + * told to answer and to ask in one breath asks. + * * ## An incomplete catalogue * * A `partial: true` answer still carries `nextStep`, computed from what it @@ -293,6 +309,12 @@ interface TermReading { readonly groupingOnly: boolean; } +/** + * An unknown word: it equals no measure and no dimension and has no candidate, + * so it takes the labelled fallback to the object query tools (D3 rule 4). + */ +const fallsBack = (r: TermReading): boolean => r.decision === 'no_measure' && r.dimensions.length === 0; + /** The member a `kind.name` pointer names in `entry`, as the entry lists it, or `undefined`. */ function memberOf(entry: DatasetToolCatalogEntry, pointer: string): (NamedMember & { kind: string }) | undefined { const dot = pointer.indexOf('.'); @@ -384,7 +406,7 @@ function leftOutSentences( for (const r of asked) sentences.push(copy.candidateHit(r.term, members(r.candidates))); if (asked.length > 0) sentences.push(copy.leftCandidateTail); sentences.push(...groupingCandidateSentences(leftOut, copy, members)); - const unknown = readings.filter((r) => r.decision === 'no_measure' && r.dimensions.length === 0); + const unknown = readings.filter(fallsBack); for (const r of unknown) sentences.push(copy.unknownHit(r.term)); if (unknown.length > 0) sentences.push(copy.leftFallbackTail); for (const r of readings) { @@ -439,13 +461,14 @@ export function composeDatasetNextStep(source: DatasetNextStepSource): DatasetNe case 'candidates_only': { // A word with a measure among its candidates is asked about; a word // whose candidates are all dimensions is offered as a grouping, and - // with no such measure word beside it the note asks which number is - // meant, as a grouping word does (D3 rule 5). + // when every word sent is a grouping the note asks which number is + // meant, as a grouping word does (D3 rule 5). An unknown word beside + // it falls back instead (rule 4), and the note asks nothing. const asked = reported.filter((r) => !r.groupingOnly); for (const r of asked) sentences.push(copy.candidateHit(r.term, members(r.candidates))); if (asked.length > 0) sentences.push(copy.candidateTail); sentences.push(...groupingCandidateSentences(reported, copy, members)); - if (asked.length === 0) sentences.push(copy.groupingTail); + if (asked.length === 0 && !readings.some(fallsBack)) sentences.push(copy.groupingTail); sentences.push(...leftOutSentences(decision, readings, copy, members)); break; } @@ -453,11 +476,10 @@ export function composeDatasetNextStep(source: DatasetNextStepSource): DatasetNe for (const r of reported) { sentences.push(r.dimensions.length > 0 ? copy.groupingHit(r.term, members(r.dimensions)) : copy.unknownHit(r.term)); } - // A word for a thing measured that names nothing falls back (D3 rule 4); - // a grouping word asks which number is meant (rule 5), beside the - // fallback too when the words are mixed. - if (reported.some((r) => r.dimensions.length === 0)) sentences.push(copy.fallbackTail); - if (reported.some((r) => r.dimensions.length > 0)) sentences.push(copy.groupingTail); + // A word for a thing measured that names nothing falls back (D3 rule 4), + // grouping word beside it or not; only when every word is a grouping + // does the note ask which number is meant (rule 5). + sentences.push(reported.some(fallsBack) ? copy.fallbackTail : copy.groupingTail); break; } } diff --git a/packages/services/service-analytics/src/dataset-tools.ts b/packages/services/service-analytics/src/dataset-tools.ts index 8bbc2078559..463a979a6b7 100644 --- a/packages/services/service-analytics/src/dataset-tools.ts +++ b/packages/services/service-analytics/src/dataset-tools.ts @@ -113,8 +113,9 @@ const LIST_DATASETS_DESCRIPTION = + 'are all dimensions is at most a possible grouping: never ask about it, and it never stops a matched measure. ' + 'No match and no candidates: fall back to the object query tools and ' + 'say in the answer that no governed metric was used (非指标口径); when the object you fall back to is a listed ' - + 'dataset\'s `object`, add one line naming that dataset and its measures. A dimension match alone picks a ' - + 'grouping, not a number: a measure must still match. `membersWithheld` means some members exist that this ' + + 'dataset\'s `object`, add one line naming that dataset and its measures. A dimension match picks a ' + + 'grouping, not a number: when the words name only groupings, ask which number is meant; beside a word that ' + + 'falls back it asks nothing, and the fallback stands. `membersWithheld` means some members exist that this ' + 'caller may not see. When `terms` were sent the answer carries `nextStep`: the case of this rule your words are ' + 'in (`decision`), the words it is about (`terms`) and what to do, already written (`note`); follow `note`, which ' + 'with one_measure also names the words left out with their candidates or possible groupings, and with ' From 37c9c844356c020fb65533af5e30893d953cf29d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 14:29:01 +0000 Subject: [PATCH 2/4] wip: ask skill rows, eval cases 21-23, regenerated MCP mirror Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- packages/mcp/src/ask-skill.generated.ts | 11 ++++--- skills/objectstack-ask/SKILL.md | 11 ++++--- .../evals/metric-selection-fallback.json | 30 +++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/mcp/src/ask-skill.generated.ts b/packages/mcp/src/ask-skill.generated.ts index 47bf6a0b01c..5750c0dd200 100644 --- a/packages/mcp/src/ask-skill.generated.ts +++ b/packages/mcp/src/ask-skill.generated.ts @@ -21,8 +21,8 @@ export const ASK_SKILL_DATA_LOOP: string = [ '- Call `list_datasets({ terms })` with those words, as the user wrote them.', ' Do not translate or reword a term: a match on a word', ' you supplied is your reading, not the user\'s. A term is the noun phrase for', - ' the thing, kept whole ("travel budget", not "travel" and "budget")', - ' and without the verbs, time words', + ' the thing, kept whole ("travel budget", not "travel" and "budget";', + ' "number of deals", not "deals") and without the verbs, time words', ' and question words around it ("trip days", not "trip days requested";', ' "报销金额", not "报销金额合计是多少").', '- Each dataset in the answer carries `matches`: one entry per hit, with the', @@ -43,8 +43,8 @@ export const ASK_SKILL_DATA_LOOP: string = [ '| One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate\'s label, its dataset\'s label and its description. Do not pick one. |', '| A word with a measure among its `candidates` | Ask the same way; with one candidate, ask whether it is the one meant. |', '| A word whose `candidates` are all dimensions | At most a possible grouping: never ask about it, and it never stops a matched measure. |', - '| Only a dimension matches | That is a grouping, not a number. Without a measure match, ask which number is meant. |', - '| No match and no candidates for the word for a thing measured | Step 4. |', + '| No word for a thing measured, only grouping words | A grouping is not a number: ask which number is meant. |', + '| No match and no candidates for the word for a thing measured | Step 4, without asking: a grouping word\'s match, or another word\'s, is no reason to ask. |', '| `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. |', '', 'When the answer has `nextStep`, follow its `decision` and `note`. If `note`', @@ -54,8 +54,7 @@ export const ASK_SKILL_DATA_LOOP: string = [ 'answers. State no figure of your own in it (no count, total', 'or option number): name each option by its label in a bullet, and quote its', 'description as written. Ask only about matches or candidates for words the user', - 'wrote; when their word matched nothing and has no candidates, go to step 4', - 'instead of asking about some other word\'s matches. `partial: true` on the answer means the catalogue may', + 'wrote. `partial: true` on the answer means the catalogue may', 'be incomplete; `warning` says why, and you repeat it when you fall back.', '', 'Use an option only once the user picks it: compute it by its exact name', diff --git a/skills/objectstack-ask/SKILL.md b/skills/objectstack-ask/SKILL.md index 38ffbd3633e..46959212f43 100644 --- a/skills/objectstack-ask/SKILL.md +++ b/skills/objectstack-ask/SKILL.md @@ -36,8 +36,8 @@ wrote its business definition) outranks a number you work out yourself. - Call `list_datasets({ terms })` with those words, as the user wrote them. Do not translate or reword a term: a match on a word you supplied is your reading, not the user's. A term is the noun phrase for - the thing, kept whole ("travel budget", not "travel" and "budget") - and without the verbs, time words + the thing, kept whole ("travel budget", not "travel" and "budget"; + "number of deals", not "deals") and without the verbs, time words and question words around it ("trip days", not "trip days requested"; "报销金额", not "报销金额合计是多少"). - Each dataset in the answer carries `matches`: one entry per hit, with the @@ -58,8 +58,8 @@ wrote its business definition) outranks a number you work out yourself. | One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate's label, its dataset's label and its description. Do not pick one. | | A word with a measure among its `candidates` | Ask the same way; with one candidate, ask whether it is the one meant. | | A word whose `candidates` are all dimensions | At most a possible grouping: never ask about it, and it never stops a matched measure. | -| Only a dimension matches | That is a grouping, not a number. Without a measure match, ask which number is meant. | -| No match and no candidates for the word for a thing measured | Step 4. | +| No word for a thing measured, only grouping words | A grouping is not a number: ask which number is meant. | +| No match and no candidates for the word for a thing measured | Step 4, without asking: a grouping word's match, or another word's, is no reason to ask. | | `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. | When the answer has `nextStep`, follow its `decision` and `note`. If `note` @@ -69,8 +69,7 @@ When you only ask, the reply is the question alone: no tool call until the user answers. State no figure of your own in it (no count, total or option number): name each option by its label in a bullet, and quote its description as written. Ask only about matches or candidates for words the user -wrote; when their word matched nothing and has no candidates, go to step 4 -instead of asking about some other word's matches. `partial: true` on the answer means the catalogue may +wrote. `partial: true` on the answer means the catalogue may be incomplete; `warning` says why, and you repeat it when you fall back. Use an option only once the user picks it: compute it by its exact name diff --git a/skills/objectstack-ask/evals/metric-selection-fallback.json b/skills/objectstack-ask/evals/metric-selection-fallback.json index 0c5d037ad68..101b8194890 100644 --- a/skills/objectstack-ask/evals/metric-selection-fallback.json +++ b/skills/objectstack-ask/evals/metric-selection-fallback.json @@ -200,6 +200,36 @@ "must_contain": ["query_dataset", "describe_object", "aggregate_records", "非指标口径"], "must_not_contain": ["您是指", "你是指", "您指的是", "你指的是", "do you mean", "Do you mean"] } + }, + { + "id": 21, + "prompt": "The user asks: \"How many sales orders are in each status?\" You called `list_datasets({ terms: ['sales orders', 'status'] })`. The answer lists one dataset, `order_book` (label Order Book, `object: 'sales_order'`), with `matches: []`; its one measure is `booked_amount`, labelled Booked Amount, and its one dimension is `order_status`, labelled Order Status. The answer carries `candidates: [{ term: 'status', dataset: 'order_book', member: 'dimensions.order_status' }]` and nothing for 'sales orders'. Its `nextStep` has `decision: 'candidates_only'`, `terms: ['status']` and this `note`: \"status\" matches no member exactly; it may name a grouping: Order Status (dataset: Order Book). A possible grouping is not a question: do not ask the user about it, and it does not stop a matched measure; group the answer only as the question asks. \"sales orders\" equals no measure and has no possible reading. For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them. `list_objects` shows `sales_order`. What do you do next, and how does the answer open?", + "expected_output": "The word for the thing measured, sales orders, has no match and no candidates, so this is the fallback, and nobody is asked anything: the user named the number (a count of sales orders), and one listed object holds those records. The word for the grouping has only a dimension among its candidates, which is at most a possible grouping and is no reason to ask; the `note` says the same. Calls `describe_object({ objectName: 'sales_order' })` and reads the fields, then `aggregate_records` once for a count grouped by the status field, instead of paging `query_records`. The reply carries no question back: it opens with one line saying the figures are not from a governed metric, computed from the Sales Order object's status field, then shows the count per status label. Because `sales_order` is the `object` of the listed dataset Order Book, it adds one line naming that dataset and its measure (Booked Amount), so the user can ask for the governed figure. No dataset query is made: no measure matched.", + "files": [], + "assertions": { + "must_contain": ["describe_object", "aggregate_records", "status"], + "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number", "which number"] + } + }, + { + "id": 22, + "prompt": "The user asks: \"How does the outstanding balance break down by aging bucket?\" You called `list_datasets({ terms: ['outstanding balance', 'aging bucket'] })`. The answer lists one dataset, `billing` (label Billing, `object: 'invoice'`), with `matches: [{ term: 'aging bucket', member: 'dimensions.aging', matchedOn: 'label' }]`; its measures are `billed_amount`, labelled Billed Amount, and `open_balance`, labelled Open Balance. 'outstanding balance' matched nothing in any dataset, and the answer has no `candidates`. `list_objects` shows `invoice`. What do you do next, and how does the answer open?", + "expected_output": "The question has a word for the thing measured, outstanding balance, and that word has no match and no candidates: this is the fallback, without asking. The match on aging bucket is a grouping word's match, which picks a grouping and is no reason to ask about the number; that question is only for a question with no word for a thing measured. Open Balance is not offered as a reading either: the answer lists no candidate for the user's word, and a match is never made by similarity. Calls `describe_object({ objectName: 'invoice' })` and reads the fields, then `aggregate_records` once for the sum of the balance field grouped by the aging bucket field, instead of paging `query_records`. The reply carries no question back: it opens with one line saying the figures are not from a governed metric, computed from the Invoice object's balance and aging bucket fields. Because `invoice` is the `object` of the listed dataset Billing, it adds one line naming that dataset and its measures (Billed Amount, Open Balance), so the user can ask for the governed figure.", + "files": [], + "assertions": { + "must_contain": ["describe_object", "aggregate_records"], + "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number", "which number"] + } + }, + { + "id": 23, + "prompt": "The user asks: \"What is the number of claims by status?\" You have called no tool yet. What is your first tool call, with what arguments, and why those words?", + "expected_output": "The first call is `list_datasets` with `terms: ['number of claims', 'status']`. A term is the user's noun phrase for the thing, kept whole: the counting head stays in it, because a dataset's owner may have declared the whole phrase as a measure's name, label or synonym, and a match is an equality, never a similarity. Sent whole, the phrase can equal exactly one measure, which is then computed with no question back. Cut down to its last noun, the word would equal nothing and could come back near several measures, an amount and a count among them, and the user would be asked to choose between readings of a word they did not write. The verb and the question words (\"What is the\") are left out, and `status` is sent as the grouping word. No object tool is called before this lookup.", + "files": [], + "assertions": { + "must_contain": ["list_datasets", "number of claims"], + "must_not_contain": ["'claims'", "\"claims\"", "list_objects(", "describe_object(", "aggregate_records("] + } } ] } From 6c5c5e2ae3c4b205179894d77e69160d7fbae118 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 14:30:30 +0000 Subject: [PATCH 3/4] wip: changeset for the ask fallback beside a grouping word Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../34996-ask-fallback-beside-grouping.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .changeset/34996-ask-fallback-beside-grouping.md diff --git a/.changeset/34996-ask-fallback-beside-grouping.md b/.changeset/34996-ask-fallback-beside-grouping.md new file mode 100644 index 00000000000..b8cae0cc065 --- /dev/null +++ b/.changeset/34996-ask-fallback-beside-grouping.md @@ -0,0 +1,20 @@ +--- +'@objectstack/service-analytics': patch +'@objectstack/mcp': patch +'@objectstack/skills': patch +--- + +fix(service-analytics): `list_datasets` no longer tells a client to ask "which number" when a word that falls back stands beside a grouping word + +Clause-②: no +Metadata-protocol: none + +A question such as "How many sales orders are in each status?" names its number. When no dataset measure answers to "sales orders" and none is offered as a candidate, the labelled fallback to the object query tools computes it. Until now the `nextStep` note of such an answer said two things at once whenever the grouping word equalled a dimension, or was near one: answer with the object query tools, and "A grouping alone is no answer: ask the user which number they mean." A client told both asked, and computed nothing. + +- **`list_datasets` `nextStep.note`** (`@objectstack/service-analytics`): the "which number is meant" sentence is written only when every word sent is a grouping (it equals a dimension, or has only dimensions among its candidates). With an unknown word beside it, the note carries that word's labelled fallback and no question. `decision`, `terms`, `matches` and `candidates` are what they were. Unchanged: a word that equals several measures, and a word with a measure among its candidates (one candidate included), are still asked about and never selected. +- **`list_datasets` description**: the sentence "A dimension match alone picks a grouping, not a number: a measure must still match." now says when the question is owed (the words name only groupings) and that it is not owed beside a word that falls back. +- **`objectstack-ask` skill, step 2** (`@objectstack/skills`, and the copy `GET /mcp/skill` serves from `@objectstack/mcp`): the row "Only a dimension matches" becomes "No word for a thing measured, only grouping words", and the fallback row says the fallback is taken without asking, whatever a grouping word or another word matched. The sentence under the table that said the same about another word's matches is cut, since the row now holds it. +- **`objectstack-ask` skill, step 1**: a term keeps its counting head ("number of deals", not "deals"), so a phrase the dataset's owner declared as a synonym is sent whole and can equal its one measure. +- Three eval cases (21 to 23) cover the fallback beside a grouping candidate, the fallback beside a dimension match, and the whole counting phrase. + +The skill file is 12 bytes shorter than before (1875 to 1872 tokens by the catalog's count). From 4342cf00921f946bc92b393dad8232a95d5fe2a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 16:22:29 +0000 Subject: [PATCH 4/4] fix(service-analytics): the which-number question beside a fallback is a closing condition the client judges The executor cannot tell a word for a thing measured from a filter value, so a grouping beside an unknown word gets the fallback and then one conditional sentence: ask which number is meant only when the question has no word for a thing measured. The description states the same condition in the client's terms, and the jsdoc no longer says the fallback computes a number the user named. Skill row five names filter words; eval case 24 covers the call with no word for a thing measured; cases 21 to 23 forbid the question put to the user and the cut-down term as sent, not words a correct reply uses in negation. Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../34996-ask-fallback-beside-grouping.md | 12 +-- packages/mcp/src/ask-skill.generated.ts | 2 +- .../src/__tests__/dataset-tools.test.ts | 94 ++++++++++++++----- .../src/dataset-next-step.ts | 68 ++++++++++---- .../service-analytics/src/dataset-tools.ts | 5 +- skills/objectstack-ask/SKILL.md | 2 +- .../evals/metric-selection-fallback.json | 20 +++- 7 files changed, 147 insertions(+), 56 deletions(-) diff --git a/.changeset/34996-ask-fallback-beside-grouping.md b/.changeset/34996-ask-fallback-beside-grouping.md index b8cae0cc065..18fb0c3b2d5 100644 --- a/.changeset/34996-ask-fallback-beside-grouping.md +++ b/.changeset/34996-ask-fallback-beside-grouping.md @@ -4,17 +4,17 @@ '@objectstack/skills': patch --- -fix(service-analytics): `list_datasets` no longer tells a client to ask "which number" when a word that falls back stands beside a grouping word +fix(service-analytics): `list_datasets` no longer tells a client outright to ask "which number" when a word that falls back stands beside a grouping word Clause-②: no Metadata-protocol: none A question such as "How many sales orders are in each status?" names its number. When no dataset measure answers to "sales orders" and none is offered as a candidate, the labelled fallback to the object query tools computes it. Until now the `nextStep` note of such an answer said two things at once whenever the grouping word equalled a dimension, or was near one: answer with the object query tools, and "A grouping alone is no answer: ask the user which number they mean." A client told both asked, and computed nothing. -- **`list_datasets` `nextStep.note`** (`@objectstack/service-analytics`): the "which number is meant" sentence is written only when every word sent is a grouping (it equals a dimension, or has only dimensions among its candidates). With an unknown word beside it, the note carries that word's labelled fallback and no question. `decision`, `terms`, `matches` and `candidates` are what they were. Unchanged: a word that equals several measures, and a word with a measure among its candidates (one candidate included), are still asked about and never selected. -- **`list_datasets` description**: the sentence "A dimension match alone picks a grouping, not a number: a measure must still match." now says when the question is owed (the words name only groupings) and that it is not owed beside a word that falls back. -- **`objectstack-ask` skill, step 2** (`@objectstack/skills`, and the copy `GET /mcp/skill` serves from `@objectstack/mcp`): the row "Only a dimension matches" becomes "No word for a thing measured, only grouping words", and the fallback row says the fallback is taken without asking, whatever a grouping word or another word matched. The sentence under the table that said the same about another word's matches is cut, since the row now holds it. +- **`list_datasets` `nextStep.note`** (`@objectstack/service-analytics`): the "which number is meant" sentence is written only when every word sent is a grouping (it equals a dimension, or has only dimensions among its candidates). With an unknown word beside it, the note carries that word's labelled fallback, then one closing sentence that leaves the question to the case only the client can see: "Only when the question has no word for a thing measured, ask the user which number they mean instead." (the unknown word may be a filter value, as in "break it down by stage for the west region"; the server sees words, not which of them names the number). `decision`, `terms`, `matches` and `candidates` are what they were. Unchanged: a word that equals several measures, and a word with a measure among its candidates (one candidate included), are still asked about and never selected. +- **`list_datasets` description**: the sentence "A dimension match alone picks a grouping, not a number: a measure must still match." now reads "A dimension match picks a grouping, not a number: when the question has no word for a thing measured, ask which number is meant; beside a word for a thing measured that falls back, ask nothing and take the fallback." +- **`objectstack-ask` skill, step 2** (`@objectstack/skills`, and the copy `GET /mcp/skill` serves from `@objectstack/mcp`): the row "Only a dimension matches" becomes "No word for a thing measured, only grouping or filter words", and the fallback row says the fallback is taken without asking, whatever a grouping word or another word matched. The sentence under the table that said the same about another word's matches is cut, since the row now holds it. - **`objectstack-ask` skill, step 1**: a term keeps its counting head ("number of deals", not "deals"), so a phrase the dataset's owner declared as a synonym is sent whole and can equal its one measure. -- Three eval cases (21 to 23) cover the fallback beside a grouping candidate, the fallback beside a dimension match, and the whole counting phrase. +- Four eval cases (21 to 24) cover the fallback beside a grouping candidate, the fallback beside a dimension match, the whole counting phrase, and a question with a grouping and a filter value but no word for a thing measured, which is asked which number is meant. -The skill file is 12 bytes shorter than before (1875 to 1872 tokens by the catalog's count). +The skill file is 2 bytes shorter than before (1875 tokens by the catalog's count, before and after). diff --git a/packages/mcp/src/ask-skill.generated.ts b/packages/mcp/src/ask-skill.generated.ts index 5750c0dd200..dbbad08c398 100644 --- a/packages/mcp/src/ask-skill.generated.ts +++ b/packages/mcp/src/ask-skill.generated.ts @@ -43,7 +43,7 @@ export const ASK_SKILL_DATA_LOOP: string = [ '| One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate\'s label, its dataset\'s label and its description. Do not pick one. |', '| A word with a measure among its `candidates` | Ask the same way; with one candidate, ask whether it is the one meant. |', '| A word whose `candidates` are all dimensions | At most a possible grouping: never ask about it, and it never stops a matched measure. |', - '| No word for a thing measured, only grouping words | A grouping is not a number: ask which number is meant. |', + '| No word for a thing measured, only grouping or filter words | A grouping is not a number: ask which number is meant. |', '| No match and no candidates for the word for a thing measured | Step 4, without asking: a grouping word\'s match, or another word\'s, is no reason to ask. |', '| `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. |', '', diff --git a/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts b/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts index 787cfbc6d9c..55a45986a99 100644 --- a/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts +++ b/packages/services/service-analytics/src/__tests__/dataset-tools.test.ts @@ -1291,12 +1291,23 @@ const ASK_FIRST: Record = { 'ja-JP': '使う前にどれを指しているかユーザーに確認してください。代わりに選ばないでください', }; const FOUR_LOCALES = [ADMIN, { ...ADMIN, locale: 'zh-CN' }, { ...ADMIN, locale: 'zh-TW' }, { ...ADMIN, locale: 'ja-JP' }] as ExecutionContext[]; -/** The question owed to a grouping that stands alone (D3 rule 5), by the locale the context names. */ -const WHICH_NUMBER: Record = { - en: 'ask the user which number they mean', - 'zh-CN': '问用户想看哪个数字', - 'zh-TW': '問使用者想看哪個數字', - 'ja-JP': 'どの数値を知りたいかユーザーに確認してください', +/** The question owed outright when every word sent is a grouping (D3 rule 5), by the locale the context names. */ +const GROUPING_ALONE: Record = { + en: 'A grouping alone is no answer: ask the user which number they mean.', + 'zh-CN': '只有分组维度还不能回答:问用户想看哪个数字。', + 'zh-TW': '只有分組維度還不能回答:問使用者想看哪個數字。', + 'ja-JP': 'グループ分けだけでは回答になりません:どの数値を知りたいかユーザーに確認してください。', +}; +/** + * The same question as a condition, after the fallback sentence of a note that + * also names a grouping: the executor cannot tell a word for a thing measured + * from a filter value, so the client, which read the question, judges it. + */ +const ONLY_IF_NO_NUMBER: Record = { + en: 'Only when the question has no word for a thing measured, ask the user which number they mean instead.', + 'zh-CN': '只有当问题本身没有说要看哪个数字时,才改为问用户想看哪个数字。', + 'zh-TW': '只有當問題本身沒有說要看哪個數字時,才改為問使用者想看哪個數字。', + 'ja-JP': '質問そのものがどの数値も指していない場合に限り、代わりにどの数値を知りたいかユーザーに確認してください。', }; type ListOut = Awaited['listDatasets']>>; @@ -1408,23 +1419,56 @@ describe('[#34919] list_datasets nextStep on examples/app-crm — the decision e }); // [#34996] One object answers "库存周转 by 销售阶段" through the fallback, so the - // note carries the fallback and no question: a note that said both was read as - // "ask". The grouping word is still named as the grouping it equals. - it('a mixed no_measure note falls back for the unknown word and asks nothing: the grouping does not stand alone', async () => { + // note carries the fallback and never the outright question: a note that said + // both was read as "ask". The grouping word is still named as the grouping it + // equals. The executor cannot know that 库存周转 is the word for the thing + // measured, so the question survives as ONE conditional sentence after the + // fallback, for the client to judge: only when the question names no number. + it('a mixed no_measure note falls back for the unknown word; the question is a condition, never outright', async () => { for (const ctx of FOUR_LOCALES) { const out = await ask(['库存周转', '销售阶段'], ctx); const where = String(ctx.locale ?? 'en'); expect(out.nextStep, where).toMatchObject({ decision: 'no_measure', terms: ['库存周转', '销售阶段'] }); - expect(out.nextStep!.note, where).toContain('query_records'); - expect(out.nextStep!.note, where).toContain('Stage'); - expect(out.nextStep!.note, `${where} ⇒ no question`).not.toContain(WHICH_NUMBER[where]); - // The control, same locale: alone, the grouping word still asks which number is meant, and sends nobody to the object tools. + const note = out.nextStep!.note; + expect(note, where).toContain('query_records'); + expect(note, where).toContain('Stage'); + expect(note, `${where} ⇒ no outright question`).not.toContain(GROUPING_ALONE[where]); + expect(note, `${where} ⇒ the condition`).toContain(ONLY_IF_NO_NUMBER[where]); + expect(note.indexOf('query_records'), `${where} ⇒ fallback first`).toBeLessThan(note.indexOf(ONLY_IF_NO_NUMBER[where])); + // The control, same locale: alone, the grouping word asks outright which number is meant, and sends nobody to the object tools. const alone = (await ask(['销售阶段'], ctx)).nextStep!.note; - expect(alone, `${where} ⇒ alone asks`).toContain(WHICH_NUMBER[where]); + expect(alone, `${where} ⇒ alone asks`).toContain(GROUPING_ALONE[where]); + expect(alone, where).not.toContain(ONLY_IF_NO_NUMBER[where]); expect(alone, where).not.toContain('query_records'); } }); + // [#34996] The same note serves a call with no word for a thing measured: a + // grouping and a filter value ("break it down by sales stage for the west + // region"). The words alone do not tell it from the case above, which is why + // the condition is written in the client's terms and is the last sentence. + it('a grouping beside a filter value gets the same note: the condition is what makes it right for a question with no number', async () => { + for (const ctx of FOUR_LOCALES) { + const where = String(ctx.locale ?? 'en'); + const out = await ask(['sales stage', 'west region'], ctx); + expect(out.nextStep, where).toMatchObject({ decision: 'no_measure', terms: ['sales stage', 'west region'] }); + expect(out.candidates ?? [], where).toEqual([]); + const note = out.nextStep!.note; + expect(note.endsWith(ONLY_IF_NO_NUMBER[where]), `${where} ⇒ the condition closes the note`).toBe(true); + expect(note, where).not.toContain(GROUPING_ALONE[where]); + // Controls. An unknown word with no grouping beside it has nothing to ask about: the fallback, no condition. + const unknown = (await ask(['west region'], ctx)).nextStep!; + expect(unknown, where).toMatchObject({ decision: 'no_measure', terms: ['west region'] }); + expect(unknown.note, where).toContain('query_records'); + expect(unknown.note, where).not.toContain(ONLY_IF_NO_NUMBER[where]); + // A matched measure beside both settles which number is meant: neither form of the question. + const measured = (await ask(['商机数', 'sales stage', 'west region'], ctx)).nextStep!; + expect(measured, where).toMatchObject({ decision: 'one_measure', terms: ['商机数'] }); + expect(measured.note, where).not.toContain(ONLY_IF_NO_NUMBER[where]); + expect(measured.note, where).not.toContain(GROUPING_ALONE[where]); + } + }); + it('a word with two matches ⇒ several_measures, the note naming each by its label and its dataset\'s label', async () => { const out = await ask(['deal value']); expect(out.nextStep).toMatchObject({ decision: 'several_measures', terms: ['deal value'] }); @@ -1643,8 +1687,9 @@ describe('[#35005] list_datasets nextStep — a grouping or time word with a can // [#34996] "How many sales orders this quarter?" with no order-count measure: // "sales orders" is unknown and "this quarter" is near a dimension. The object // tools answer the count, so the note offers the grouping, sends the unknown - // word to its labelled fallback and asks nothing. - it('a grouping candidate beside an unknown word: the unknown word falls back and nobody is asked which number', async () => { + // word to its labelled fallback and never asks outright; the question is left + // as the closing condition, for a question that names no number. + it('a grouping candidate beside an unknown word: the unknown word falls back and the question is only the closing condition', async () => { for (const ctx of FOUR_LOCALES) { const out = await ask(['sales orders', 'this quarter'], ctx); expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['this quarter'] }); @@ -1653,13 +1698,18 @@ describe('[#35005] list_datasets nextStep — a grouping or time word with a can expect(note, loc(ctx)).toContain(GROUPING_OFFER[loc(ctx)]); expect(note, loc(ctx)).toContain('sales orders'); expect(note, loc(ctx)).toContain('query_records'); - expect(note, `${loc(ctx)} ⇒ no question`).not.toContain(WHICH_NUMBER[loc(ctx)]); + expect(note, `${loc(ctx)} ⇒ no outright question`).not.toContain(GROUPING_ALONE[loc(ctx)]); + expect(note.endsWith(ONLY_IF_NO_NUMBER[loc(ctx)]), `${loc(ctx)} ⇒ the condition closes the note`).toBe(true); + expect(note.indexOf('query_records'), `${loc(ctx)} ⇒ fallback first`).toBeLessThan(note.indexOf(ONLY_IF_NO_NUMBER[loc(ctx)])); expect(note, loc(ctx)).not.toContain(ASK_BEFORE_COMPUTING[loc(ctx)]); - // The control, same locale: with no unknown word beside it, the grouping candidate still asks which number. - expect((await ask(['this quarter'], ctx)).nextStep!.note, `${loc(ctx)} ⇒ alone asks`).toContain(WHICH_NUMBER[loc(ctx)]); - // And a word that equals a dimension beside the candidate is a second grouping, not a fallback: still asked. + // The control, same locale: with no unknown word beside it, the grouping candidate still asks outright which number. + const alone = (await ask(['this quarter'], ctx)).nextStep!.note; + expect(alone, `${loc(ctx)} ⇒ alone asks`).toContain(GROUPING_ALONE[loc(ctx)]); + expect(alone, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]); + // And a word that equals a dimension beside the candidate is a second grouping, not a fallback: still asked outright. const groupings = (await ask(['this quarter', 'industry'], ctx)).nextStep!.note; - expect(groupings, `${loc(ctx)} ⇒ two groupings ask`).toContain(WHICH_NUMBER[loc(ctx)]); + expect(groupings, `${loc(ctx)} ⇒ two groupings ask`).toContain(GROUPING_ALONE[loc(ctx)]); + expect(groupings, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]); expect(groupings, loc(ctx)).not.toContain('query_records'); } }); @@ -1672,6 +1722,8 @@ describe('[#35005] list_datasets nextStep — a grouping or time word with a can expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['销售'] }); expect(out.nextStep!.note, loc(ctx)).toContain(ASK_BEFORE_COMPUTING[loc(ctx)]); expect(out.nextStep!.note, loc(ctx)).toContain('query_records'); + // No grouping in the call: the which-number condition has nothing to be about. + expect(out.nextStep!.note, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]); } }); }); diff --git a/packages/services/service-analytics/src/dataset-next-step.ts b/packages/services/service-analytics/src/dataset-next-step.ts index b241cbd65a5..9efe63e4f50 100644 --- a/packages/services/service-analytics/src/dataset-next-step.ts +++ b/packages/services/service-analytics/src/dataset-next-step.ts @@ -93,24 +93,34 @@ import type { PlatformLocaleTag } from '@objectstack/spec/system'; * its fallback. A reported `candidates_only` word whose candidates are all * dimensions is offered the same way, and when every word sent is a grouping * the note asks which number is meant, as a grouping word does (D3 rule 5; the - * next section says when). (`several_measures` asks before anything is computed, so its + * next section says when, and what an unknown word beside it changes). (`several_measures` asks before anything is computed, so its * note needs no such tail.) Two words that equal the same measure are one * metric, and the note says so. * - * ## A grouping beside a word that falls back asks nothing + * ## A grouping beside an unknown word: the fallback, and the question only for a question with no number * - * [#34996] "Which number is meant" (D3 rule 5) is the question for a grouping - * that stands alone: every word sent equals only a dimension, or has only - * dimensions among its candidates. An unknown word beside it (no measure, no - * dimension, no candidate) is in rule 4, the labelled fallback to the object - * query tools, and that fallback computes the number the user named: "sales - * orders" beside "status" is a count of sales orders by status, as it was - * before any dataset listed a `status` dimension (M2, ruled A: the fallback - * answers what the object tools answer today). So the note then carries the - * fallback sentence and no question: `["sales orders", "status"]` and - * `["库存周转", "销售阶段"]` fall back, and `["销售阶段"]` or `["this quarter"]` - * alone still ask which number is meant. One note never says both: a reader - * told to answer and to ask in one breath asks. + * [#34996] "Which number is meant" (D3 rule 5) is the question for a question + * that names no number. This file sees words, not which of them is the word + * for the thing measured, so it writes that question outright only where the + * words settle it: every word sent equals only a dimension, or has only + * dimensions among its candidates (`["销售阶段"]`, `["this quarter"]`). + * + * An unknown word beside a grouping (no measure, no dimension, no candidate) + * is read as the word for the thing measured, which is rule 4: the labelled + * fallback to the object query tools. `["sales orders", "status"]` is a count + * of sales orders by status, as it was before any dataset listed a `status` + * dimension (M2, ruled A: the fallback answers what the object tools answer + * today). That reading is a presumption, and it is wrong when the unknown + * word is a filter value or a second grouping and the question names no + * number at all (`["stage", "west region"]`, "break it down by stage for the + * west region"): rule 5 still governs there, and only the client, which read + * the question, can tell. So the note for a grouping beside an unknown word + * carries the fallback sentence and then ONE conditional sentence, in the + * client's terms: ask which number is meant only when the question itself + * names none (`noNumberTail`). The unconditional question (`groupingTail`) is + * never written beside a fallback sentence: a reader told to answer and to + * ask in one breath asks, which is what a question that named its number + * got until this section. * * ## An incomplete catalogue * @@ -165,6 +175,12 @@ interface DatasetToolCopy { readonly unknownHit: (term: string) => string; readonly fallbackTail: string; readonly groupingTail: string; + /** + * After the fallback sentence of a note that also names a grouping: the + * which-number question is owed only when the question itself names no + * number. The condition is the client's to judge; this file cannot. + */ + readonly noNumberTail: string; readonly partialTail: string; /** After a `one_measure` note: the left-out words with a measure among their candidates are asked about before use. */ readonly leftCandidateTail: string; @@ -192,6 +208,7 @@ const COPY: Readonly> = { unknownHit: (t) => `"${t}" equals no measure and has no possible reading.`, fallbackTail: 'Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used.', groupingTail: 'A grouping alone is no answer: ask the user which number they mean.', + noNumberTail: 'Only when the question has no word for a thing measured, ask the user which number they mean instead.', partialTail: 'The catalogue was incomplete (see warning): a measure missing from this answer may still exist, so repeat the warning in the answer.', leftCandidateTail: 'For each word above with possible readings, ask the user which one is meant before using it; do not pick one.', leftFallbackTail: 'For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them.', @@ -215,6 +232,7 @@ const COPY: Readonly> = { unknownHit: (t) => `「${t}」没有匹配任何指标,也没有可能的候选。`, fallbackTail: '改用对象查询工具(query_records、aggregate_records)回答,并在回答中注明未使用治理指标(非指标口径)。', groupingTail: '只有分组维度还不能回答:问用户想看哪个数字。', + noNumberTail: '只有当问题本身没有说要看哪个数字时,才改为问用户想看哪个数字。', partialTail: '数据集目录不完整(见 warning):这里没有列出的指标仍可能存在,请在回答中转述该警告。', leftCandidateTail: '上面有候选的词,先问用户指的是哪一个再使用;不要替用户选。', leftFallbackTail: '这些词改用对象查询工具(query_records、aggregate_records),并在回答中注明它们未使用治理指标(非指标口径)。', @@ -238,6 +256,7 @@ const COPY: Readonly> = { unknownHit: (t) => `「${t}」沒有符合任何指標,也沒有可能的候選。`, fallbackTail: '改用物件查詢工具(query_records、aggregate_records)回答,並在回答中註明未使用治理指標(非指標口徑)。', groupingTail: '只有分組維度還不能回答:問使用者想看哪個數字。', + noNumberTail: '只有當問題本身沒有說要看哪個數字時,才改為問使用者想看哪個數字。', partialTail: '資料集目錄不完整(見 warning):這裡沒有列出的指標仍可能存在,請在回答中轉述該警告。', leftCandidateTail: '上面有候選的詞,先問使用者指的是哪一個再使用;不要替使用者選。', leftFallbackTail: '這些詞改用物件查詢工具(query_records、aggregate_records),並在回答中註明它們未使用治理指標(非指標口徑)。', @@ -261,6 +280,7 @@ const COPY: Readonly> = { unknownHit: (t) => `「${t}」はどの指標にも一致せず、候補もありません。`, fallbackTail: 'オブジェクトのクエリツール(query_records、aggregate_records)で回答し、管理された指標を使っていないことを回答に明記してください。', groupingTail: 'グループ分けだけでは回答になりません:どの数値を知りたいかユーザーに確認してください。', + noNumberTail: '質問そのものがどの数値も指していない場合に限り、代わりにどの数値を知りたいかユーザーに確認してください。', partialTail: 'データセットのカタログは不完全です(warning を参照):ここにない指標が存在する可能性があるため、回答でその警告を伝えてください。', leftCandidateTail: '候補のある上記の語は、使う前にどれを指しているかユーザーに確認してください。代わりに選ばないでください。', leftFallbackTail: 'これらの語にはオブジェクトのクエリツール(query_records、aggregate_records)を使い、管理された指標を使っていないことを回答に明記してください。', @@ -463,23 +483,31 @@ export function composeDatasetNextStep(source: DatasetNextStepSource): DatasetNe // whose candidates are all dimensions is offered as a grouping, and // when every word sent is a grouping the note asks which number is // meant, as a grouping word does (D3 rule 5). An unknown word beside - // it falls back instead (rule 4), and the note asks nothing. + // it falls back instead (rule 4), and the question is left to the one + // case the client can see: a question that names no number. const asked = reported.filter((r) => !r.groupingOnly); + const beside = readings.some(fallsBack); for (const r of asked) sentences.push(copy.candidateHit(r.term, members(r.candidates))); if (asked.length > 0) sentences.push(copy.candidateTail); sentences.push(...groupingCandidateSentences(reported, copy, members)); - if (asked.length === 0 && !readings.some(fallsBack)) sentences.push(copy.groupingTail); + if (asked.length === 0 && !beside) sentences.push(copy.groupingTail); sentences.push(...leftOutSentences(decision, readings, copy, members)); + if (asked.length === 0 && beside) sentences.push(copy.noNumberTail); break; } case 'no_measure': { for (const r of reported) { sentences.push(r.dimensions.length > 0 ? copy.groupingHit(r.term, members(r.dimensions)) : copy.unknownHit(r.term)); } - // A word for a thing measured that names nothing falls back (D3 rule 4), - // grouping word beside it or not; only when every word is a grouping - // does the note ask which number is meant (rule 5). - sentences.push(reported.some(fallsBack) ? copy.fallbackTail : copy.groupingTail); + // An unknown word falls back (D3 rule 4), grouping word beside it or + // not; only when every word is a grouping does the note ask outright + // which number is meant (rule 5). Beside a grouping, the fallback is + // followed by that question as a condition the client judges. + if (!reported.some(fallsBack)) sentences.push(copy.groupingTail); + else { + sentences.push(copy.fallbackTail); + if (reported.some((r) => r.dimensions.length > 0)) sentences.push(copy.noNumberTail); + } break; } } diff --git a/packages/services/service-analytics/src/dataset-tools.ts b/packages/services/service-analytics/src/dataset-tools.ts index 463a979a6b7..c5cad6333ce 100644 --- a/packages/services/service-analytics/src/dataset-tools.ts +++ b/packages/services/service-analytics/src/dataset-tools.ts @@ -114,8 +114,9 @@ const LIST_DATASETS_DESCRIPTION = + 'No match and no candidates: fall back to the object query tools and ' + 'say in the answer that no governed metric was used (非指标口径); when the object you fall back to is a listed ' + 'dataset\'s `object`, add one line naming that dataset and its measures. A dimension match picks a ' - + 'grouping, not a number: when the words name only groupings, ask which number is meant; beside a word that ' - + 'falls back it asks nothing, and the fallback stands. `membersWithheld` means some members exist that this ' + + 'grouping, not a number: when the question has no word for a thing measured, ask which number is meant; beside ' + + 'a word for a thing measured that falls back, ask nothing and take the fallback. `membersWithheld` means some ' + + 'members exist that this ' + 'caller may not see. When `terms` were sent the answer carries `nextStep`: the case of this rule your words are ' + 'in (`decision`), the words it is about (`terms`) and what to do, already written (`note`); follow `note`, which ' + 'with one_measure also names the words left out with their candidates or possible groupings, and with ' diff --git a/skills/objectstack-ask/SKILL.md b/skills/objectstack-ask/SKILL.md index 46959212f43..f0d06ac017c 100644 --- a/skills/objectstack-ask/SKILL.md +++ b/skills/objectstack-ask/SKILL.md @@ -58,7 +58,7 @@ wrote its business definition) outranks a number you work out yourself. | One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate's label, its dataset's label and its description. Do not pick one. | | A word with a measure among its `candidates` | Ask the same way; with one candidate, ask whether it is the one meant. | | A word whose `candidates` are all dimensions | At most a possible grouping: never ask about it, and it never stops a matched measure. | -| No word for a thing measured, only grouping words | A grouping is not a number: ask which number is meant. | +| No word for a thing measured, only grouping or filter words | A grouping is not a number: ask which number is meant. | | No match and no candidates for the word for a thing measured | Step 4, without asking: a grouping word's match, or another word's, is no reason to ask. | | `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. | diff --git a/skills/objectstack-ask/evals/metric-selection-fallback.json b/skills/objectstack-ask/evals/metric-selection-fallback.json index 101b8194890..3fecb16dc3d 100644 --- a/skills/objectstack-ask/evals/metric-selection-fallback.json +++ b/skills/objectstack-ask/evals/metric-selection-fallback.json @@ -203,12 +203,12 @@ }, { "id": 21, - "prompt": "The user asks: \"How many sales orders are in each status?\" You called `list_datasets({ terms: ['sales orders', 'status'] })`. The answer lists one dataset, `order_book` (label Order Book, `object: 'sales_order'`), with `matches: []`; its one measure is `booked_amount`, labelled Booked Amount, and its one dimension is `order_status`, labelled Order Status. The answer carries `candidates: [{ term: 'status', dataset: 'order_book', member: 'dimensions.order_status' }]` and nothing for 'sales orders'. Its `nextStep` has `decision: 'candidates_only'`, `terms: ['status']` and this `note`: \"status\" matches no member exactly; it may name a grouping: Order Status (dataset: Order Book). A possible grouping is not a question: do not ask the user about it, and it does not stop a matched measure; group the answer only as the question asks. \"sales orders\" equals no measure and has no possible reading. For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them. `list_objects` shows `sales_order`. What do you do next, and how does the answer open?", - "expected_output": "The word for the thing measured, sales orders, has no match and no candidates, so this is the fallback, and nobody is asked anything: the user named the number (a count of sales orders), and one listed object holds those records. The word for the grouping has only a dimension among its candidates, which is at most a possible grouping and is no reason to ask; the `note` says the same. Calls `describe_object({ objectName: 'sales_order' })` and reads the fields, then `aggregate_records` once for a count grouped by the status field, instead of paging `query_records`. The reply carries no question back: it opens with one line saying the figures are not from a governed metric, computed from the Sales Order object's status field, then shows the count per status label. Because `sales_order` is the `object` of the listed dataset Order Book, it adds one line naming that dataset and its measure (Booked Amount), so the user can ask for the governed figure. No dataset query is made: no measure matched.", + "prompt": "The user asks: \"How many sales orders are in each status?\" You called `list_datasets({ terms: ['sales orders', 'status'] })`. The answer lists one dataset, `order_book` (label Order Book, `object: 'sales_order'`), with `matches: []`; its one measure is `booked_amount`, labelled Booked Amount, and its one dimension is `order_status`, labelled Order Status. The answer carries `candidates: [{ term: 'status', dataset: 'order_book', member: 'dimensions.order_status' }]` and nothing for 'sales orders'. Its `nextStep` has `decision: 'candidates_only'`, `terms: ['status']` and this `note`: \"status\" matches no member exactly; it may name a grouping: Order Status (dataset: Order Book). A possible grouping is not a question: do not ask the user about it, and it does not stop a matched measure; group the answer only as the question asks. \"sales orders\" equals no measure and has no possible reading. For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them. Only when the question has no word for a thing measured, ask the user which number they mean instead. `list_objects` shows `sales_order`. What do you do next, and how does the answer open?", + "expected_output": "The word for the thing measured, sales orders, has no match and no candidates, so this is the fallback, and nobody is asked anything: the user named the number (a count of sales orders), and one listed object holds those records. The word for the grouping has only a dimension among its candidates, which is at most a possible grouping and is no reason to ask; the `note` says the same, and its closing condition does not apply, because this question has a word for the thing measured. Calls `describe_object({ objectName: 'sales_order' })` and reads the fields, then `aggregate_records` once for a count grouped by the status field, instead of paging `query_records`. The reply carries no question back: it opens with one line saying the figures are not from a governed metric, computed from the Sales Order object's status field, then shows the count per status label. Because `sales_order` is the `object` of the listed dataset Order Book, it adds one line naming that dataset and its measure (Booked Amount), so the user can ask for the governed figure. No dataset query is made: no measure matched.", "files": [], "assertions": { "must_contain": ["describe_object", "aggregate_records", "status"], - "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number", "which number"] + "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number do you", "which number do you", "Which number would you", "which number would you"] } }, { @@ -218,7 +218,7 @@ "files": [], "assertions": { "must_contain": ["describe_object", "aggregate_records"], - "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number", "which number"] + "must_not_contain": ["query_dataset(", "Do you mean", "do you mean", "Which number do you", "which number do you", "Which number would you", "which number would you"] } }, { @@ -228,7 +228,17 @@ "files": [], "assertions": { "must_contain": ["list_datasets", "number of claims"], - "must_not_contain": ["'claims'", "\"claims\"", "list_objects(", "describe_object(", "aggregate_records("] + "must_not_contain": ["['claims'", "[\"claims\"", ", 'claims']", ", \"claims\"]", "list_objects(", "describe_object(", "aggregate_records("] + } + }, + { + "id": 24, + "prompt": "The user says: \"Break it down by stage for the west region.\" You called `list_datasets({ terms: ['stage', 'west region'] })`. The answer lists one dataset, `pipeline` (label Pipeline, `object: 'opportunity'`), with `matches: [{ term: 'stage', member: 'dimensions.stage', matchedOn: 'name' }]`; its measures are `open_amount`, labelled Open Amount, and `deal_count`, labelled Deals, and its dimensions are `stage`, labelled Stage, and `owner`, labelled Owner. 'west region' matched nothing in any dataset, and the answer has no `candidates`. Its `nextStep` has `decision: 'no_measure'`, `terms: ['stage', 'west region']` and this `note`: \"stage\" equals a grouping, not a number: Stage (dataset: Pipeline). \"west region\" equals no measure and has no possible reading. Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used. Only when the question has no word for a thing measured, ask the user which number they mean instead. `list_objects` shows `opportunity`. What do you do next?", + "expected_output": "The question has no word for a thing measured: stage is what to group by and the west region is what to filter by, and neither says which number to break down. The `note` sends the unmatched word to the object query tools, and then says that when the question has no word for a thing measured the user is asked which number they mean instead; that condition holds here, so the fallback is not taken. The skill's table says the same: no word for a thing measured, only grouping or filter words, is a question about the number, and a grouping is not a number. The reply is that question alone: it asks which number the user wants by Stage for the west region, as in \"Which number would you like broken down by Stage for the west region?\" No tool is called until the user answers: no object is described, nothing is aggregated, and no dataset is queried. No measure is picked for the user and no figure is stated; this is not the fallback, so the reply does not say that no governed metric was used.", + "files": [], + "assertions": { + "must_contain": ["?"], + "must_not_contain": ["describe_object(", "aggregate_records(", "query_records(", "query_dataset("] } } ]