Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Translate a clarify question without its copy instead of rejecting it
Emre Sokullu8c5ed662f0d3
diff --git a/docs/architecture.md b/docs/architecture.mdindex d02f1005d..949a8bacc 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -354,7 +354,7 @@ Manual action-mode runs (Act or Dev) call the active provider once before the toIn Try, a turn that automatic mode routed to Act or Dev with a sure `plan_need: direct` answer also uses the compact intent schema (`_routedDirectTask`), and the trace records a `planner_skipped` note with `reason: 'direct_task'`. `direct` is an authorizing choice, so it needs the 0.85 threshold, and its description leaves out risky work (payments, purchases, bookings, deletion, bulk changes, credentials, messages to several people) as well as work with several goals, many items, several sites or pages, conditions, schedules or facts to carry across many steps: those answer `plan`. Strict, plan review set to Always, a steering revision, and any action turn without a sure `direct` answer, such as one in a mode the user chose, keep the full planner. So does a turn whose task the decision model could not read whole. That covers a request over 6,000 characters, an earlier task cut at 600, a decision state over its 12,000-byte budget, and text that redaction changed (a credential line, a URL query). It also covers a turn with attached files and the continuation of a read-only run, whose task lies partly outside the question. A `direct` answer is not used for these turns.-Planner latency grows with the tokens the model writes, so both prompts ask for little. `summary`, `steps` and `risks` are English; `localized` is `null` for an English `wbLocale`, and for another locale it is required only when the user reads the plan: `clarify`, `plan_only`, and an `execute` plan shown for review, whose rule the full prompt states from the current review settings (`plannerReviewRule()`). An English `clarify` uses its summary as the question. When a plan the user reads arrives without its copy (`normalizePlan()` marks it `localized.missing`), `_localizedPlanForDisplay()` translates the display fields in one small request (trace phase `planner_localize`) before the review card or the plan-only answer is shown. Execution keeps the English plan. A translation that fails or leaves out a step or risk is not used, so the user sees the English text rather than a mix. A non-English `clarify` without its copy is still rejected and repaired like other invalid planner output. `memory: null` turns off the scratchpad and the progress ledger together, and `normalizePlan()` reads it as a declared `disabled` ledger, so no progress-classifier call follows. The compact intent check writes no steps for `execute` (its plan-only steps stay), and full-plan steps are one short sentence each.+Planner latency grows with the tokens the model writes, so both prompts ask for little. `summary`, `steps` and `risks` are English; `localized` is `null` for an English `wbLocale`, and for another locale it is required only when the user reads the plan: `clarify`, `plan_only`, and an `execute` plan shown for review, whose rule the full prompt states from the current review settings (`plannerReviewRule()`). An English `clarify` uses its summary as the question. When a plan the user reads arrives without its copy (`normalizePlan()` marks it `localized.missing`), `_localizedPlanForDisplay()` translates the display fields in one small request (trace phase `planner_localize`) before the review card or the plan-only answer is shown. Execution keeps the English plan. A translation that fails or leaves out a step or risk is not used, so the user sees the English text rather than a mix. A non-English `clarify` without its copy is handled the same way: its English question is translated before it is asked. `memory: null` turns off the scratchpad and the progress ledger together, and `normalizePlan()` reads it as a declared `disabled` ledger, so no progress-classifier call follows. The compact intent check writes no steps for `execute` (its plan-only steps stay), and full-plan steps are one short sentence each.When the active site adapter has a validated `webbrain-adapter-workflow/2`profile, both planner variants also receive its bounded app-owned job IDs anddiff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.jsindex 5e087cf0a..e9f894c1e 100644--- a/src/chrome/src/agent/planner.js+++ b/src/chrome/src/agent/planner.js@@ -1206,8 +1206,9 @@ export function normalizePlan(obj, opts = {}) {&& steps.every(step => localizedStepsById.get(step.id)?.action)&& riskEntries.every(entry => sanitizeText(providedLocalizedRisks[entry.sourceIndex], 200));if (opts.requireIntent) {- // English needs no localized copy: summary is the question.- if (requestKind === 'clarify' && !localizedSummary && !englishLocale) return null;+ // A clarify question needs no localized copy here: summary is the+ // question, and one the user reads in another language is translated+ // before it is asked (localized.missing below).// The compact intent check writes no steps for execute work.const stepsRequired = requestKind === 'plan_only'|| (requestKind === 'execute' && opts.compactIntent !== true);diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.jsindex 5e087cf0a..e9f894c1e 100644--- a/src/firefox/src/agent/planner.js+++ b/src/firefox/src/agent/planner.js@@ -1206,8 +1206,9 @@ export function normalizePlan(obj, opts = {}) {&& steps.every(step => localizedStepsById.get(step.id)?.action)&& riskEntries.every(entry => sanitizeText(providedLocalizedRisks[entry.sourceIndex], 200));if (opts.requireIntent) {- // English needs no localized copy: summary is the question.- if (requestKind === 'clarify' && !localizedSummary && !englishLocale) return null;+ // A clarify question needs no localized copy here: summary is the+ // question, and one the user reads in another language is translated+ // before it is asked (localized.missing below).// The compact intent check writes no steps for execute work.const stepsRequired = requestKind === 'plan_only'|| (requestKind === 'execute' && opts.compactIntent !== true);diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjsindex ce2b5f3f8..15e6fb09d 100644--- a/test/plan-when-needed.mjs+++ b/test/plan-when-needed.mjs@@ -284,7 +284,7 @@ for (const build of BUILDS) {// An English clarify question is the summary itself; another language needs its copy.const clarify = { ...intent, request_kind: 'clarify', read_scope: 'none', summary: 'Which day should I book?' };assert.equal(parse(clarify, { locale: 'en', compactIntent: true }).localized.summary, 'Which day should I book?');- assert.equal(parse(clarify, { locale: 'tr', compactIntent: true }), null);+ assert.equal(parse(clarify, { locale: 'tr', compactIntent: true }).localized.missing, true, 'translated before it is asked');assert.equal(parse({ ...clarify, localized: { locale: 'tr', summary: 'Hangi gün?', steps: [], risks: [] } }, { locale: 'tr', compactIntent: true }).localized.summary, 'Hangi gün?');// The old long form still parses: a declared ledger and a full copy.const long = parse(englishPlan({@@ -426,6 +426,19 @@ for (const build of BUILDS) {}});+ test(`${build}: a clarify question without its copy is translated and asked, not run as Act`, async () => {+ const clarify = englishPlan({ request_kind: 'clarify', read_scope: 'none', requires_state_change: false, requires_submission: false,+ summary: 'Which email address should I use?', steps: [], risks: [] });+ const translation = JSON.stringify({ locale: 'tr', summary: 'Hangi e-posta adresini kullanayım?', steps: [], risks: [] });+ for (const gate of ['gate', 'intent']) {+ const f = displayFixture({ review: 'never', plan: gate === 'gate' ? clarify : { ...clarify, confidence: undefined }, translation });+ const result = await f[gate]();+ assert.deepEqual([result.proceed, result.requestKind, result.plannerClarification], [false, 'clarify', true], gate);+ assert.deepEqual(f.calls, [gate === 'gate' ? 'planner' : 'planner_intent', 'planner_localize'], gate);+ assert.equal(result.message, 'Hangi e-posta adresini kullanayım?', gate);+ }+ });+test(`${build}: a plan-only answer is translated before it is shown`, async () => {const planOnly = englishPlan({ request_kind: 'plan_only', read_scope: 'none', requires_state_change: false, requires_submission: false,steps: [{ id: '1', action: 'Fill in the newsletter email field.' }, { id: '2', action: 'Submit and read the confirmation.' }] });diff --git a/test/planner-repair-authority.mjs b/test/planner-repair-authority.mjsindex c89b35e2a..b25d4186f 100644--- a/test/planner-repair-authority.mjs+++ b/test/planner-repair-authority.mjs@@ -793,11 +793,15 @@ for (const browser of ['chrome', 'firefox']) {assert.equal(plan.request_kind, request_kind);assert.equal(plan.requires_submission, false);if (request_kind === 'clarify') {- // English needs no localized copy: the English summary is the question.+ // The summary is the question. English needs no localized copy; in+ // another language the question is marked for translation before it+ // is asked, rather than rejected.for (const localized of [null, {}]) {const english = planner.normalizePlan({ ...raw, localized }, { requireIntent: true, locale: 'en' });assert.equal(english.localized.summary, english.summary);- assert.equal(planner.normalizePlan({ ...raw, localized }, { requireIntent: true, locale: 'tr' }), null);+ const turkish = planner.normalizePlan({ ...raw, localized }, { requireIntent: true, locale: 'tr' });+ assert.equal(turkish.request_kind, 'clarify');+ assert.equal(turkish.localized.missing, true);}assert.equal(planner.normalizePlan({ ...raw, read_scope: 'visible_page' }, { requireIntent: true, locale: 'en' }), null);}diff --git a/test/run.js b/test/run.jsindex acd96b6cd..19528f530 100644--- a/test/run.js+++ b/test/run.js@@ -114152,7 +114152,11 @@ test('planner: canonical fields recover missing and partial localization withoutsteps: [],risks: [],}), { requireIntent: true, locale: 'tr' });- assert.equal(malformedClarification, null, `${label}: clarification without the actual localized question bypassed repair`);+ // Kept and marked for translation: the agent translates the question+ // before asking it (agent._localizedPlanForDisplay), instead of failing+ // the plan and continuing in Act.+ assert.equal(malformedClarification?.request_kind, 'clarify', `${label}: clarification without its localized question was discarded`);+ assert.equal(malformedClarification?.localized.missing, true, `${label}: clarification without its localized question is not marked for translation`);}});