Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Key semantic answers by the whole request; translate incomplete copies

Emre Sokullu67dd8ccbb1d2
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 0609ef962..9ea18dc3c 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -9232,7 +9232,9 @@ export class Agent extends LoopDetector {
const requestText = String(request ?? '');
const trusted = kind === 'user_turn_kind' ? requestText : requestText.slice(0, 6000);
const data = boundedSemanticData(page);
- const keyFor = question => this._sha256TextSync(JSON.stringify([SEMANTIC_DECISION_VERSION, question, trusted, data]));
+ // Keyed by the whole request, not the part a model reads: two requests
+ // that share a cut-off start are different requests.
+ const keyFor = question => this._sha256TextSync(JSON.stringify([SEMANTIC_DECISION_VERSION, question, requestText, data]));
const cacheKey = keyFor(kind);
const extraKinds = [...new Set(Array.isArray(alongside) ? alongside : [])].filter(extra => extra !== kind && semanticQuestion(extra));
this._semanticDecisionCache ??= new Map();
diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.js
index dcebaac42..ca543699d 100644
--- a/src/chrome/src/agent/planner.js
+++ b/src/chrome/src/agent/planner.js
@@ -1192,6 +1192,10 @@ export function normalizePlan(obj, opts = {}) {
: [];
const requestedLocale = normalizePlannerLocale(opts.locale || localizedInput.locale);
const englishLocale = requestedLocale === 'en' || requestedLocale.startsWith('en-');
+ // The copy covers the summary, every step and every risk.
+ const localizedCopyComplete = Boolean(localizedSummary)
+ && 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;
@@ -1207,10 +1211,10 @@ export function normalizePlan(obj, opts = {}) {
risks: riskEntries.map(({ sourceIndex, text: risk }) => (
sanitizeText(providedLocalizedRisks[sourceIndex], 200) || risk
)),
- // No copy in the user's language, so the fields above are English. The
- // agent translates them when the user reads this plan
- // (agent._localizedPlanForDisplay).
- ...(!englishLocale && !localizedSummary ? { missing: true } : {}),
+ // No complete copy in the user's language, so some or all of the fields
+ // above are English. The agent translates them when the user reads this
+ // plan (agent._localizedPlanForDisplay).
+ ...(!englishLocale && !localizedCopyComplete ? { missing: true } : {}),
};
const responseLanguage = normalizeResponseLanguagePolicy(obj.response_language, requestedLocale);
const submissionBearingPlan = executablePlan || requestKind === 'clarify';
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 59c90ba63..f9bf46158 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -8941,7 +8941,9 @@ export class Agent extends LoopDetector {
const requestText = String(request ?? '');
const trusted = kind === 'user_turn_kind' ? requestText : requestText.slice(0, 6000);
const data = boundedSemanticData(page);
- const keyFor = question => this._sha256TextSync(JSON.stringify([SEMANTIC_DECISION_VERSION, question, trusted, data]));
+ // Keyed by the whole request, not the part a model reads: two requests
+ // that share a cut-off start are different requests.
+ const keyFor = question => this._sha256TextSync(JSON.stringify([SEMANTIC_DECISION_VERSION, question, requestText, data]));
const cacheKey = keyFor(kind);
const extraKinds = [...new Set(Array.isArray(alongside) ? alongside : [])].filter(extra => extra !== kind && semanticQuestion(extra));
this._semanticDecisionCache ??= new Map();
diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.js
index dcebaac42..ca543699d 100644
--- a/src/firefox/src/agent/planner.js
+++ b/src/firefox/src/agent/planner.js
@@ -1192,6 +1192,10 @@ export function normalizePlan(obj, opts = {}) {
: [];
const requestedLocale = normalizePlannerLocale(opts.locale || localizedInput.locale);
const englishLocale = requestedLocale === 'en' || requestedLocale.startsWith('en-');
+ // The copy covers the summary, every step and every risk.
+ const localizedCopyComplete = Boolean(localizedSummary)
+ && 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;
@@ -1207,10 +1211,10 @@ export function normalizePlan(obj, opts = {}) {
risks: riskEntries.map(({ sourceIndex, text: risk }) => (
sanitizeText(providedLocalizedRisks[sourceIndex], 200) || risk
)),
- // No copy in the user's language, so the fields above are English. The
- // agent translates them when the user reads this plan
- // (agent._localizedPlanForDisplay).
- ...(!englishLocale && !localizedSummary ? { missing: true } : {}),
+ // No complete copy in the user's language, so some or all of the fields
+ // above are English. The agent translates them when the user reads this
+ // plan (agent._localizedPlanForDisplay).
+ ...(!englishLocale && !localizedCopyComplete ? { missing: true } : {}),
};
const responseLanguage = normalizeResponseLanguagePolicy(obj.response_language, requestedLocale);
const submissionBearingPlan = executablePlan || requestKind === 'clarify';
diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjs
index 090bbfd31..b737600c4 100644
--- a/test/plan-when-needed.mjs
+++ b/test/plan-when-needed.mjs
@@ -126,6 +126,15 @@ for (const build of BUILDS) {
assert.equal('plan' in await wide.agent._routeAutoRunMode(6, { ...question, request: 'あ'.repeat(4500) }), false);
});
+ test(`${build}: a remembered answer belongs to the whole request, not to its first 6,000 characters`, async () => {
+ const start = 'Read this paragraph. '.repeat(300).slice(0, 6000);
+ const { agent, requests } = decisionAgent({ run_mode: sure('act'), plan_need: sure('direct') });
+ assert.equal((await agent._routeAutoRunMode(7, { ...question, request: start })).plan, 'direct', 'a request read whole');
+ const longer = await agent._routeAutoRunMode(7, { ...question, request: `${start} Then pay the open invoice.` });
+ assert.equal(requests.length, 2, 'the longer request is a new question');
+ assert.equal('plan' in longer, false);
+ });
+
// ── The gate ──────────────────────────────────────────────────────────
function gateFixture({ planMode = 'try', review = 'confidence' } = {}) {
@@ -271,8 +280,13 @@ for (const build of BUILDS) {
assert.equal('missing' in parse(englishPlan(), { locale: 'en' }).localized, false);
const planOnly = englishPlan({ request_kind: 'plan_only', read_scope: 'none' });
assert.equal('missing' in parse(planOnly, { locale: 'en-GB' }).localized, false);
- const written = parse(englishPlan({ localized: { locale: 'tr', summary: 'Abone ol.', steps: [], risks: [] } }), { locale: 'tr' });
- assert.equal('missing' in written.localized, false, 'a copy the planner wrote is kept');
+ const copy = { locale: 'tr', summary: 'Abone ol.', steps: [{ id: '1', action: 'Doldur.' }, { id: '2', action: 'GΓΆnder.' }], risks: [] };
+ const written = parse(englishPlan({ localized: copy }), { locale: 'tr' });
+ assert.equal('missing' in written.localized, false, 'a complete copy the planner wrote is kept');
+ // A copy that leaves out a step or a risk is incomplete: the plan the user reads is translated.
+ assert.equal(parse(englishPlan({ localized: { ...copy, steps: copy.steps.slice(0, 1) } }), { locale: 'tr' }).localized.missing, true);
+ assert.equal(parse(englishPlan({ risks: ['The form is submitted.'], localized: copy }), { locale: 'tr' }).localized.missing, true);
+ assert.equal('missing' in parse(englishPlan({ risks: ['The form is submitted.'], localized: { ...copy, risks: ['Form gΓΆnderilir.'] } }), { locale: 'tr' }).localized, false);
});
test(`${build}: the translation request carries only the display fields, and its answer replaces them`, () => {
@@ -344,7 +358,8 @@ for (const build of BUILDS) {
['English', { locale: 'en' }],
['not reviewed', { review: 'never' }],
['confident enough', { review: 'confidence', plan: englishPlan({ confidence: 0.95 }) }],
- ['copy written', { plan: englishPlan({ confidence: 0.5, localized: { locale: 'tr', summary: 'Abone ol.', steps: [], risks: [] } }) }],
+ ['copy written', { plan: englishPlan({ confidence: 0.5, localized: { locale: 'tr', summary: 'Abone ol.',
+ steps: [{ id: '1', action: 'Doldur.' }, { id: '2', action: 'GΓΆnder.' }], risks: [] } }) }],
]) {
const f = displayFixture(options);
const gate = await f.gate();
diff --git a/test/planner-repair-authority.mjs b/test/planner-repair-authority.mjs
index 71182f518..c89b35e2a 100644
--- a/test/planner-repair-authority.mjs
+++ b/test/planner-repair-authority.mjs
@@ -761,9 +761,11 @@ for (const browser of ['chrome', 'firefox']) {
steps: [{ id: '2', action: 'Doğrulamadan sonra bitir.' }], risks: ['Yeni ileti gânderme.'] } });
const original = JSON.stringify(raw);
const plan = planner.normalizePlan(raw, { requireIntent: true, locale: 'tr-TR' });
+ // The step the copy left out shows in English, and the copy is marked
+ // incomplete so a plan the user reads is translated first.
assert.deepEqual(plan.localized, { locale: 'tr-tr', summary: raw.localized.summary,
steps: [{ id: '1', action: plan.steps[0].action }, { id: '2', action: raw.localized.steps[0].action }],
- risks: raw.localized.risks });
+ risks: raw.localized.risks, missing: true });
assert.equal(JSON.stringify(raw), original);
});