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
Guard policy: a plain arithmetic answer before the calculator ran ends as partial
Barack Sokulluc0daba5e4cab
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex c4ec3b583..775b0f6f3 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -14713,6 +14713,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn calculationResultInText(summary, result, fraction);}+ // A plain final accepted in a literal-arithmetic task before any+ // calculator attempt (the plan guard gives its notes first): WebBrain knows+ // its answer was not computed. As for a premature done(success), it ends+ // as partial with that caveat (pure-calculation-done-checks).+ _notePrematureCalculationFinal(tabId) {+ const policy = this._pureCalculationToolPolicy(tabId);+ if (!policy || policy.stale || policy.attempted || !policy.names.includes('calculate')) return;+ if (this._guardOutcome('pure-calculation-done-checks', { decided: true, tabId }) !== 'advise') return;+ const state = this._guardRunState(tabId);+ state.caveats.set('pure-calculation-done-checks', 'The result was not computed with the calculator.');+ (state.outcomeDowngrades ||= new Set()).add('pure-calculation-done-checks');+ }+_pureCalculationToolBlock(tabId, name, args, expectedScope) {const policy = this._pureCalculationToolPolicy(tabId, expectedScope);if (!policy) return null;@@ -53437,6 +53450,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout drunOptions,);finalResponse = this._withStandaloneUnverifiedNotice(finalResponse, standaloneGroundingGap, runOptions);+ this._notePrematureCalculationFinal(tabId);finalResponse = this._withCompletionCaveat(tabId, finalResponse);messages.push(this._withResponseItems({ role: 'assistant', content: finalResponse }, result.responseItems, result.reasoningContent, provider));onUpdate('text', { content: finalResponse, replace: true });@@ -54819,6 +54833,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dfullText = attributedFullText;onUpdate('text', { content: fullText, replace: true });}+ this._notePrematureCalculationFinal(tabId);const caveatedFullText = this._withCompletionCaveat(tabId, fullText);if (caveatedFullText !== fullText) {fullText = caveatedFullText;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 0a5278d29..cf1f3673d 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -13078,6 +13078,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn calculationResultInText(summary, result, fraction);}+ // A plain final accepted in a literal-arithmetic task before any+ // calculator attempt (the plan guard gives its notes first): WebBrain knows+ // its answer was not computed. As for a premature done(success), it ends+ // as partial with that caveat (pure-calculation-done-checks).+ _notePrematureCalculationFinal(tabId) {+ const policy = this._pureCalculationToolPolicy(tabId);+ if (!policy || policy.stale || policy.attempted || !policy.names.includes('calculate')) return;+ if (this._guardOutcome('pure-calculation-done-checks', { decided: true, tabId }) !== 'advise') return;+ const state = this._guardRunState(tabId);+ state.caveats.set('pure-calculation-done-checks', 'The result was not computed with the calculator.');+ (state.outcomeDowngrades ||= new Set()).add('pure-calculation-done-checks');+ }+_pureCalculationToolBlock(tabId, name, args, expectedScope) {const policy = this._pureCalculationToolPolicy(tabId, expectedScope);if (!policy) return null;@@ -45020,6 +45033,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dfinalResponse = result.costAllowanceMessage? `${repairedFinalContent}\n\n${result.costAllowanceMessage}`: repairedFinalContent;+ this._notePrematureCalculationFinal(tabId);finalResponse = this._withCompletionCaveat(tabId, finalResponse);messages.push(this._withResponseItems({ role: 'assistant', content: finalResponse }, result.responseItems, result.reasoningContent, provider));onUpdate('text', { content: finalResponse });@@ -46233,6 +46247,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout donUpdate('text_delta', { content: `\n\n${costStopMessage}` });fullText = `${fullText}\n\n${costStopMessage}`;}+ this._notePrematureCalculationFinal(tabId);const caveatedFullText = this._withCompletionCaveat(tabId, fullText);if (caveatedFullText !== fullText) {fullText = caveatedFullText;diff --git a/test/pure-calculation-reply.mjs b/test/pure-calculation-reply.mjsindex 6319c8830..1e2c58348 100644--- a/test/pure-calculation-reply.mjs+++ b/test/pure-calculation-reply.mjs@@ -344,6 +344,40 @@ for (const build of ['chrome', 'firefox']) {});}+ for (const streaming of [false, true]) {+ test(`${build}: ${streaming ? 'stream' : 'chat'} a plain arithmetic answer accepted before any calculation ends as partial`, async () => {+ // The model never calls calculate. By default the plan guard's notes are+ // given once each, then the plain answer is accepted, but not as a+ // success: WebBrain knows the result was not computed.+ const tab = nextTab++, updates = []; let agent, send, requests = 0;+ agent = makeAgent(Agent, async () => {+ requests++; send({});+ return { content: answer };+ });+ agent.maxSteps = 8;+ agent._enrichUserMessageWithCurrentPage = async (_tab, _messages, content) => {+ send = bind(agent, tab); return { role: 'user', content };+ };+ agent._runPlannerIntentGate = async () => ({ proceed: true, requestKind: 'execute',+ requiresStateChange: false, requiresSubmission: false,+ ...agent._plannerCompletionGateFields({ read_scope: 'none', deliverables: scope.deliverables }) });+ agent.executeTool = async (_tab, name) => {+ if (name === 'get_accessibility_tree') return { success: true, pageContent: 'text "Owned passive counter"' };+ assert.fail(`No tool runs in this task: ${name}`);+ };+ const update = (type, data) => updates.push({ type, data });+ const options = { detachedRequestId: `plain-before-calc-${tab}`, askStreamingEnabled: false };+ try {+ const result = streaming ? await agent.processMessageStream(tab, ORIGINAL_CALC_CORRECTION, update, 'act', options)+ : await agent.processMessage(tab, ORIGINAL_CALC_CORRECTION, update, 'act', [], options);+ assert.ok(requests >= 2, 'the plain answer gets a note before it is accepted');+ assert.equal(updates.some(e => e.type === 'tool_call' && e.data.name === 'calculate'), false);+ assert.match(result, /The result was not computed with the calculator\./);+ assert.ok(updates.some(e => e.type === 'run_status' && e.data?.status === 'partial'), 'the run ends as partial');+ } finally { documents.delete(tab); }+ });+ }+for (const beforeCalculation of [false, true]) for (const change of ['none', 'no_actual_receipt', 'mixed_task', 'no_literal_task', 'quoted_task', 'provider_config', 'same_text_new_task','new_completion_run', 'browser_action', 'verification_debt', 'iframe_debt', 'send_obligation','ledger', 'pending_send', 'queued_steering', 'human_input', 'unknown_intervention', 'navigation',