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
20 changes: 20 additions & 0 deletions .changeset/34996-ask-fallback-beside-grouping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/service-analytics': patch
'@objectstack/mcp': patch
'@objectstack/skills': patch
---

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, 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.
- 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 2 bytes shorter than before (1875 tokens by the catalog's count, before and after).
11 changes: 5 additions & 6 deletions packages/mcp/src/ask-skill.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 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. |',
'',
'When the answer has `nextStep`, follow its `decision` and `note`. If `note`',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,24 @@ const ASK_FIRST: Record<string, string> = {
'ja-JP': '使う前にどれを指しているかユーザーに確認してください。代わりに選ばないでください',
};
const FOUR_LOCALES = [ADMIN, { ...ADMIN, locale: 'zh-CN' }, { ...ADMIN, locale: 'zh-TW' }, { ...ADMIN, locale: 'ja-JP' }] as ExecutionContext[];
/** The question owed outright when every word sent is a grouping (D3 rule 5), by the locale the context names. */
const GROUPING_ALONE: Record<string, string> = {
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<string, string> = {
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<ReturnType<ReturnType<AnalyticsService['datasetTools']>['listDatasets']>>;

Expand Down Expand Up @@ -1400,11 +1418,55 @@ 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 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: ['库存周转', '销售阶段'] });
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(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 () => {
Expand Down Expand Up @@ -1621,6 +1683,49 @@ 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 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'] });
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 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 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(GROUPING_ALONE[loc(ctx)]);
expect(groupings, loc(ctx)).not.toContain(ONLY_IF_NO_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');
// 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)]);
}
});
});

describe('[#34919] list_datasets nextStep — an incomplete catalogue says so (N4)', () => {
Expand Down
Loading
Loading