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
Recognize the advisory coverage caveat as the runtime's own Ask limitation
Claudef1ae380eea5a
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex de04acc59..ab5071bff 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -2055,10 +2055,19 @@ export class Agent extends LoopDetector {// Every path that substitutes this fixed text for the model's answer (the// done tool and the plain-final branches alike) asks here first, so it is// remembered once, for _maybeEmitAskModeHandoff.- if (limitation) (this._runtimeAskLimitations ||= new Map()).set(tabId, limitation);+ if (limitation) this._rememberRuntimeAskLimitation(tabId, limitation);return limitation;}+ // The texts the runtime itself puts in an Ask answer for a limit only Act+ // mode lifts, as a set: the fixed limitation and the advisory caveat.+ _rememberRuntimeAskLimitation(tabId, text) {+ if (!text) return;+ const known = (this._runtimeAskLimitations ||= new Map());+ if (!known.has(tabId)) known.set(tabId, new Set());+ known.get(tabId).add(text);+ }+// The status texts an observation showed after a submit: the accessibility// tree's status, alert and log lines, a page read short enough to be one// message, a screenshot's short description, and, once the submit led to@@ -5872,12 +5881,16 @@ export class Agent extends LoopDetector {const state = this.readCompletenessStates.get(tabId);const expansionUnverified = state?.requiresExpansionEvidence === true&& state.treeCoverageComplete === true && state.expansionConfirmed !== true;+ const caveat = !expansionUnverified ? 'Not every part of the conversation was confirmed as read.'+ : this._isActionMode(this._effectiveRunMode(tabId))+ ? 'Some Gmail messages may have stayed collapsed, so the whole conversation was not confirmed as read.'+ : 'Ask mode cannot expand collapsed Gmail messages, so some messages in the conversation may be missing.';+ // Only Act mode expands the messages, so an automatic Ask turn that ends+ // with this caveat is offered the switch (see _maybeEmitAskModeHandoff).+ if (expansionUnverified && !this._isActionMode(this._effectiveRunMode(tabId))) this._rememberRuntimeAskLimitation(tabId, caveat);return this._guardRefusesOnce(tabId, 'read-coverage-incomplete', {decided: !expansionUnverified,- caveat: !expansionUnverified ? 'Not every part of the conversation was confirmed as read.'- : this._isActionMode(this._effectiveRunMode(tabId))- ? 'Some Gmail messages may have stayed collapsed, so the whole conversation was not confirmed as read.'- : 'Ask mode cannot expand collapsed Gmail messages, so some messages in the conversation may be missing.',+ caveat,});}@@ -27308,7 +27321,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// is not a conversational offer: the model cannot hand it off, and a retry// in Act is the recovery, so a routed turn keeps the one-click switch for it.const runtimeLimitation = typeof finalResponse === 'string' && finalResponse !== ''- && finalResponse.includes(this._runtimeAskLimitations?.get(tabId) ?? '\0');+ && [...(this._runtimeAskLimitations?.get(tabId) || [])].some(text => finalResponse.includes(text));if (mode !== 'ask'|| (runOptions?.autoModeRouting && !runtimeLimitation)|| runOptions?.cloudRundiff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex fdc5a58a8..035e1b15a 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -1612,10 +1612,19 @@ export class Agent extends LoopDetector {// Every path that substitutes this fixed text for the model's answer (the// done tool and the plain-final branches alike) asks here first, so it is// remembered once, for _maybeEmitAskModeHandoff.- if (limitation) (this._runtimeAskLimitations ||= new Map()).set(tabId, limitation);+ if (limitation) this._rememberRuntimeAskLimitation(tabId, limitation);return limitation;}+ // The texts the runtime itself puts in an Ask answer for a limit only Act+ // mode lifts, as a set: the fixed limitation and the advisory caveat.+ _rememberRuntimeAskLimitation(tabId, text) {+ if (!text) return;+ const known = (this._runtimeAskLimitations ||= new Map());+ if (!known.has(tabId)) known.set(tabId, new Set());+ known.get(tabId).add(text);+ }+// The status texts an observation showed after a submit: the accessibility// tree's status, alert and log lines, a page read short enough to be one// message, a screenshot's short description, and, once the submit led to@@ -5419,12 +5428,16 @@ export class Agent extends LoopDetector {const state = this.readCompletenessStates.get(tabId);const expansionUnverified = state?.requiresExpansionEvidence === true&& state.treeCoverageComplete === true && state.expansionConfirmed !== true;+ const caveat = !expansionUnverified ? 'Not every part of the conversation was confirmed as read.'+ : this._isActionMode(this._effectiveRunMode(tabId))+ ? 'Some Gmail messages may have stayed collapsed, so the whole conversation was not confirmed as read.'+ : 'Ask mode cannot expand collapsed Gmail messages, so some messages in the conversation may be missing.';+ // Only Act mode expands the messages, so an automatic Ask turn that ends+ // with this caveat is offered the switch (see _maybeEmitAskModeHandoff).+ if (expansionUnverified && !this._isActionMode(this._effectiveRunMode(tabId))) this._rememberRuntimeAskLimitation(tabId, caveat);return this._guardRefusesOnce(tabId, 'read-coverage-incomplete', {decided: !expansionUnverified,- caveat: !expansionUnverified ? 'Not every part of the conversation was confirmed as read.'- : this._isActionMode(this._effectiveRunMode(tabId))- ? 'Some Gmail messages may have stayed collapsed, so the whole conversation was not confirmed as read.'- : 'Ask mode cannot expand collapsed Gmail messages, so some messages in the conversation may be missing.',+ caveat,});}@@ -24343,7 +24356,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// is not a conversational offer: the model cannot hand it off, and a retry// in Act is the recovery, so a routed turn keeps the one-click switch for it.const runtimeLimitation = typeof finalResponse === 'string' && finalResponse !== ''- && finalResponse.includes(this._runtimeAskLimitations?.get(tabId) ?? '\0');+ && [...(this._runtimeAskLimitations?.get(tabId) || [])].some(text => finalResponse.includes(text));if (mode !== 'ask'|| (runOptions?.autoModeRouting && !runtimeLimitation)|| runOptions?.cloudRundiff --git a/test/auto-mode.mjs b/test/auto-mode.mjsindex 5463a3c68..18aedcae0 100644--- a/test/auto-mode.mjs+++ b/test/auto-mode.mjs@@ -843,12 +843,28 @@ for (const build of BUILDS) {assert.equal(classified, 0, 'the runtime limitation is offered without asking the classifier');});+ test(`${build}: the advisory coverage caveat of a collapsed Gmail thread is offered the switch too`, async () => {+ // By default the limitation reaches the user as a caveat appended to the+ // model's own summary, not as the fixed text.+ const f = fixture(Agent, { replies: [done('Unused.')] });+ delete f.agent._maybeEmitAskModeHandoff;+ let classified = 0;+ f.agent._jevClassify = async () => { classified += 1; return 'none'; };+ f.agent.readCompletenessStates.set(f.tab, { required: true, complete: false, requiresExpansionEvidence: true, treeCoverageComplete: true, expansionConfirmed: false });+ f.agent._readCoverageGuardRefuses(f.tab);+ const answer = 'The visible messages discuss the launch date.\n\nNote: Ask mode cannot expand collapsed Gmail messages, so some messages in the conversation may be missing.';+ const emit = (type, data) => f.updates.push({ type, data });+ await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', answer, emit, { autoModeRouting: { previousMode: null } });+ assert.deepEqual(f.updates.filter(update => update.type === 'ask_mode_handoff').map(update => update.data), [{ value: 'act' }]);+ assert.equal(classified, 0);+ });+test(`${build}: the runtime's Ask limitation text is forgotten when its run ends or the next begins`, async () => {const f = fixture(Agent, { replies: [done('Unused.')] });const state = { required: true, complete: false, requiresExpansionEvidence: true, treeCoverageComplete: true };f.agent.readCompletenessStates.set(f.tab, state);const limitation = f.agent._readCompletenessLimitation(f.tab);- assert.equal(f.agent._runtimeAskLimitations.get(f.tab), limitation);+ assert.ok(f.agent._runtimeAskLimitations.get(f.tab).has(limitation));f.agent._clearReadCompleteness(f.tab);assert.equal(f.agent._runtimeAskLimitations.has(f.tab), false, 'cleared with the read state');f.agent.readCompletenessStates.set(f.tab, state);