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
Skip the planner only when the decision model read the whole request
Emre Sokulluc3438b42a41a
diff --git a/docs/architecture.md b/docs/architecture.mdindex 6a5ea042f..ae3594d76 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -352,7 +352,7 @@ Raw page-source access through `read_page_source` is available only in Dev mode.Manual action-mode runs (Act or Dev) call the active provider once before the tool loop with `planner.js`'s structured JSON prompt. Off uses the compact intent schema; Try and Strict use the full plan schema. Unset storage defaults to Try, while explicit Off remains Off. The planner sees the user task, sanitized URL/title, and a short recent-history digest; page context is wrapped as untrusted data and image blocks are dropped.-In 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.+In 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 request the decision model could not read whole (over 6,000 characters, or over the decision state's 12,000-byte budget): a `direct` answer about part of it is not used.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.diff --git a/docs/security-model.md b/docs/security-model.mdindex 127dd8b74..890bd6f1c 100644--- a/docs/security-model.md+++ b/docs/security-model.md@@ -215,7 +215,7 @@ The primary threat: a malicious page crafts content that, when read by the agent| **Ask/Act/Dev mode** | Ask mode exposes only semantic read-only tools. Clicks/types/navigation need an action mode, which only the user's own request grants (see **Automatic mode selection**). Act exposes the selected provider tier's normal tools. Dev requires Mid/Full tier and adds source/style/page-inspection tools for developer debugging. || **Automatic mode selection** | Always on; the side panel has no mode toggle. The user's own request takes the place of the toggle as the action authorization: a turn enters Act or Dev only on a sure decision-model answer to `run_mode` about the user's words and run state, or on a `request_action_mode` call from a read-only Ask turn that quotes the user's latest message exactly (for Retry or Continue of a read-only run, the continued task's own words; WebBrain's continuation text never counts) and that the page-free `run_mode` question, asked again, confirms. Page text, titles and addresses never reach the route, and an unsure, slow or failed route starts read-only. A selected-text scope, the standalone window, Cloud runs, context-menu prompts and messages that carry page text always stay in Ask. The action run's planner gate, permission gates and confirmation cards apply as in a mode the user chose, except that in Try planning a turn that the same decision request is sure is a short, direct task (`plan_need`) runs the gate's compact intent check instead of the full planner. || **Tiered tool exposure** | Provider tiers (`compact | mid | full`) limit the normal browser-agent surface for smaller models. Compact gets the smallest action surface; Mid adds common task tools; Full adds advanced UI/DOM fallbacks. Compact Dev is blocked. |-| **Plan before Act** | When enabled, action-mode runs first produce a structured plan and wait for side-panel approval before any browser tool executes. In Try mode, planner JSON that remains invalid after repair degrades that turn to Ask/read-only; Strict stops. Also in Try, a turn that automatic mode routed with a sure `plan_need: direct` answer runs only the compact intent check and shows no plan card: `direct` is an authorizing choice (0.85 threshold) for a short, single-purpose job, and risky work (payments, purchases, bookings, deletion, bulk changes, credentials, messages to several people) answers `plan`. Strict, and plan review set to Always, plan every turn. Scheduled runs can auto-approve the plan only through scheduler policy. |+| **Plan before Act** | When enabled, action-mode runs first produce a structured plan and wait for side-panel approval before any browser tool executes. In Try mode, planner JSON that remains invalid after repair degrades that turn to Ask/read-only; Strict stops. Also in Try, a turn that automatic mode routed with a sure `plan_need: direct` answer runs only the compact intent check and shows no plan card: `direct` is an authorizing choice (0.85 threshold) for a short, single-purpose job, and risky work (payments, purchases, bookings, deletion, bulk changes, credentials, messages to several people) answers `plan`. A `direct` answer about a request cut to fit the decision model is not used. Strict, and plan review set to Always, plan every turn. Scheduled runs can auto-approve the plan only through scheduler policy. || **Skill import boundary** | Skills can expose read-only HTTP tools and download-job tools through a `webbrain-tools` manifest. Importing or keeping the skill enabled is the trust decision for the declared HTTPS endpoint; declared skill tools use `credentials: "omit"` and should mark third-party results `resultPolicy: "untrusted"`. Download-job skill tools still require an action mode and the normal Downloads permission gate before saving files. || **WebMCP boundary** | Experimental WebMCP is on by default, so its tools and prompt guidance enter ordinary model requests unless the user opts out under Settings β Bridge. Chrome page-registered names, descriptions, schemas, frame URLs, annotations, outputs, and errors are page-controlled and always use the untrusted-content wrapper. Calls use opaque IDs. Ask may list tools but cannot invoke them. Because a callback can run arbitrary page logic, every invocation requires Act/Dev, fresh per-call confirmation, and a permission grant for the actual registration-frame origin; a page-authored `readOnly` hint never bypasses those gates. Missing/opaque frame identity fails closed, and the frame plus effective HTTP(S) security origin are revalidated immediately before dispatch to prevent navigation races from borrowing an old grant. || **API mutation override** | A per-conversation `/allow-api` flag, or the default-on persistent setting under Settings β Advanced, *waives* the permission prompt for write-method network egress (`fetch_url`/`research_url` with POST/PUT/PATCH/DELETE) in Act and Dev. Ask stays read-only: an Ask run, including a turn that automatic mode starts in Ask, refuses a write-method request whatever these say. Neither option waives GET egress or any other capability. Conversation reset clears only the slash-command override. |diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 3d7ceadc8..0609ef962 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -9221,13 +9221,16 @@ export class Agent extends LoopDetector {* `alongside` lists other questions about the same request and data, asked* in the same decision-model request (run_mode with plan_need). Their sure* answers come back as `alongside: { kind: choice | null }` and are- * remembered on their own; the active model never answers them.+ * remembered on their own; the active model never answers them. An+ * authorizing answer among them needs the whole request: when the request+ * was cut to fit the decision model, it is not used.*/async _semanticDecision(tabId, kind, { request = '', page = {} } = {}, { provider = this._activeProvider(tabId), signal = null, mainModel = true, retryChoices = [], alongside = [] } = {}) {const spec = semanticQuestion(kind);// Relationship decisions must read the entire latest user message. A// prefix-only verdict can mistake a correction or a new task at its end.- const trusted = kind === 'user_turn_kind' ? String(request ?? '') : String(request ?? '').slice(0, 6000);+ 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]));const cacheKey = keyFor(kind);@@ -9258,6 +9261,9 @@ export class Agent extends LoopDetector {const settings = await this._jevSettings(tabId, provider);decisionKey = this._semanticDecisionKey(settings);const decisionText = redactSystemOneText(JSON.stringify({ request: trusted, page: data }));+ // What the decision model reads of the request: cut to 6,000 characters+ // above, then to the decision state's budget below.+ const partialRequest = trusted.length < requestText.length || systemOneStateBytes(decisionText) > 12000;// Keep the existing bounded fast route, but use the full-text main// model directly when a relationship question cannot fit in it.const decisionFits = kind !== 'user_turn_kind' || systemOneStateBytes(decisionText) <= 12000;@@ -9269,7 +9275,11 @@ export class Agent extends LoopDetector {}, context);for (const extra of extraKinds) {const extraAnswer = verdict.answers?.[extra];- const extraChoice = confidentChoice(extraAnswer, semanticQuestion(extra).authorizing.includes(extraAnswer?.choice) ? 0.85 : 0.7);+ const authorizing = semanticQuestion(extra).authorizing.includes(extraAnswer?.choice);+ // A part of the request cannot authorize skipping anything the rest+ // of it might need (plan_need: a payment after the cut).+ if (authorizing && partialRequest) continue;+ const extraChoice = confidentChoice(extraAnswer, authorizing ? 0.85 : 0.7);if (extraChoice) {extraAnswers[extra] = extraChoice;store(keyFor(extra), { choice: extraChoice, evidence: '', source: 'decision_model' });diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex eaf2780e8..59c90ba63 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -8930,13 +8930,16 @@ export class Agent extends LoopDetector {* `alongside` lists other questions about the same request and data, asked* in the same decision-model request (run_mode with plan_need). Their sure* answers come back as `alongside: { kind: choice | null }` and are- * remembered on their own; the active model never answers them.+ * remembered on their own; the active model never answers them. An+ * authorizing answer among them needs the whole request: when the request+ * was cut to fit the decision model, it is not used.*/async _semanticDecision(tabId, kind, { request = '', page = {} } = {}, { provider = this._activeProvider(tabId), signal = null, mainModel = true, retryChoices = [], alongside = [] } = {}) {const spec = semanticQuestion(kind);// Relationship decisions must read the entire latest user message. A// prefix-only verdict can mistake a correction or a new task at its end.- const trusted = kind === 'user_turn_kind' ? String(request ?? '') : String(request ?? '').slice(0, 6000);+ 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]));const cacheKey = keyFor(kind);@@ -8967,6 +8970,9 @@ export class Agent extends LoopDetector {const settings = await this._jevSettings(tabId, provider);decisionKey = this._semanticDecisionKey(settings);const decisionText = redactSystemOneText(JSON.stringify({ request: trusted, page: data }));+ // What the decision model reads of the request: cut to 6,000 characters+ // above, then to the decision state's budget below.+ const partialRequest = trusted.length < requestText.length || systemOneStateBytes(decisionText) > 12000;// Keep the existing bounded fast route, but use the full-text main// model directly when a relationship question cannot fit in it.const decisionFits = kind !== 'user_turn_kind' || systemOneStateBytes(decisionText) <= 12000;@@ -8978,7 +8984,11 @@ export class Agent extends LoopDetector {}, context);for (const extra of extraKinds) {const extraAnswer = verdict.answers?.[extra];- const extraChoice = confidentChoice(extraAnswer, semanticQuestion(extra).authorizing.includes(extraAnswer?.choice) ? 0.85 : 0.7);+ const authorizing = semanticQuestion(extra).authorizing.includes(extraAnswer?.choice);+ // A part of the request cannot authorize skipping anything the rest+ // of it might need (plan_need: a payment after the cut).+ if (authorizing && partialRequest) continue;+ const extraChoice = confidentChoice(extraAnswer, authorizing ? 0.85 : 0.7);if (extraChoice) {extraAnswers[extra] = extraChoice;store(keyFor(extra), { choice: extraChoice, evidence: '', source: 'decision_model' });diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjsindex 4083ec2c5..090bbfd31 100644--- a/test/plan-when-needed.mjs+++ b/test/plan-when-needed.mjs@@ -110,6 +110,22 @@ for (const build of BUILDS) {assert.equal(other.alongside.plan_need, 'direct');});+ test(`${build}: a request cut to fit the decision model never skips the planner`, async () => {+ // More than the 6,000 characters it reads, with the payment after the cut.+ const long = { ...question, request: `${'Read this paragraph. '.repeat(300)}Then pay the open invoice.` };+ const direct = decisionAgent({ run_mode: sure('act'), plan_need: sure('direct') });+ const routed = await direct.agent._routeAutoRunMode(6, long);+ assert.equal(routed.mode, 'act');+ assert.equal('plan' in routed, false);+ const again = await direct.agent._semanticDecision(6, 'run_mode', long, { mainModel: false, alongside: ['plan_need'] });+ assert.equal(again.alongside.plan_need, null, 'a cut answer is not remembered either');+ const planned = decisionAgent({ run_mode: sure('act'), plan_need: sure('plan') });+ assert.equal((await planned.agent._routeAutoRunMode(6, long)).plan, 'plan', 'a plan answer still counts');+ // Bytes count too: 4,500 three-byte characters exceed the decision state's budget.+ const wide = decisionAgent({ run_mode: sure('act'), plan_need: sure('direct') });+ assert.equal('plan' in await wide.agent._routeAutoRunMode(6, { ...question, request: 'γ'.repeat(4500) }), false);+ });+// ββ The gate ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction gateFixture({ planMode = 'try', review = 'confidence' } = {}) {