Skip to content

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

Mark the runtime's Ask limitation wherever it is substituted

Claude303e6af8ad89
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index bc7553757..c7368954d 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -2045,10 +2045,15 @@ export class Agent extends LoopDetector {
}
_readCompletenessLimitation(tabId) {
- return readCompletenessLimitation(
+ const limitation = readCompletenessLimitation(
this.readCompletenessStates.get(tabId),
this._effectiveRunMode(tabId),
);
+ // 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);
+ return limitation;
}
// The status texts an observation showed after a submit: the accessibility
@@ -27262,7 +27267,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 !== ''
- && this._runtimeAskLimitations?.get(tabId) === finalResponse;
+ && finalResponse.includes(this._runtimeAskLimitations?.get(tabId) ?? '\0');
if (mode !== 'ask'
|| (runOptions?.autoModeRouting && !runtimeLimitation)
|| runOptions?.cloudRun
@@ -55653,7 +55658,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
finalResponse = readFinalLimitation;
- (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
_traceStatus = 'read_scope_limited';
messages.push({ role: 'assistant', content: finalResponse });
onUpdate('text', { content: finalResponse, replace: true });
@@ -57027,7 +57031,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
- (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
messages.push({ role: 'assistant', content: readFinalLimitation });
onUpdate('text', { content: readFinalLimitation, replace: true });
onUpdate('warning', { message: 'Ask mode could not verify that every Gmail message was expanded.' });
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 6e28c2bb6..016bee0d9 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1602,10 +1602,15 @@ export class Agent extends LoopDetector {
}
_readCompletenessLimitation(tabId) {
- return readCompletenessLimitation(
+ const limitation = readCompletenessLimitation(
this.readCompletenessStates.get(tabId),
this._effectiveRunMode(tabId),
);
+ // 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);
+ return limitation;
}
// The status texts an observation showed after a submit: the accessibility
@@ -24297,7 +24302,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 !== ''
- && this._runtimeAskLimitations?.get(tabId) === finalResponse;
+ && finalResponse.includes(this._runtimeAskLimitations?.get(tabId) ?? '\0');
if (mode !== 'ask'
|| (runOptions?.autoModeRouting && !runtimeLimitation)
|| runOptions?.cloudRun
@@ -47053,7 +47058,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
finalResponse = readFinalLimitation;
- (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
_traceStatus = 'read_scope_limited';
messages.push({ role: 'assistant', content: finalResponse });
onUpdate('text', { content: finalResponse, replace: true });
@@ -48266,7 +48270,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const readFinalLimitation = this._readCompletenessLimitation(tabId);
if (readFinalLimitation && !this._guardAdvises('read-coverage-ask-limitation', { tabId, decided: false })) {
- (this._runtimeAskLimitations ||= new Map()).set(tabId, readFinalLimitation);
messages.push({ role: 'assistant', content: readFinalLimitation });
onUpdate('text', { content: readFinalLimitation, replace: true });
onUpdate('warning', { message: 'Ask mode could not verify that every Gmail message was expanded.' });
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index e88e57ffe..954a90a8b 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -727,16 +727,20 @@ for (const build of BUILDS) {
test(`${build}: a routed turn keeps the one-click switch for the runtime's own Ask limitation`, async () => {
// The runtime replaces the model's reply with a fixed "switch to Act" text
- // (a Gmail thread it could not expand); the model cannot hand that off.
- const limitation = 'I could not expand every message in this thread in Ask mode. Switch to Act mode to expand them.';
+ // when it could not expand a Gmail thread; the model cannot hand that off.
+ // The text comes from the runtime's own function, whichever branch (the
+ // done tool or a plain final answer) substitutes it.
const settle = () => new Promise(resolve => setImmediate(resolve));
const f = fixture(Agent, { replies: [done('Unused.')] });
delete f.agent._maybeEmitAskModeHandoff;
f.agent._jevClassify = async () => 'act';
- f.agent._runtimeAskLimitations = new Map([[f.tab, limitation]]);
+ f.agent.readCompletenessStates.set(f.tab, { required: true, complete: false, requiresExpansionEvidence: true, treeCoverageComplete: true });
+ const limitation = f.agent._readCompletenessLimitation(f.tab);
+ assert.match(limitation, /Ask mode cannot expand them/);
+ const emit = (type, data) => f.updates.push({ type, data });
const routed = { autoModeRouting: { previousMode: null } };
- await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', limitation, f.onUpdate || ((type, data) => f.updates.push({ type, data })), routed);
- await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', 'Would you like me to open it for you?', (type, data) => f.updates.push({ type, data }), routed);
+ await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', limitation, emit, routed);
+ await f.agent._maybeEmitAskModeHandoff(f.tab, 'ask', 'Summarize this thread', 'Would you like me to open it for you?', emit, routed);
await settle();
assert.deepEqual(f.updates.filter(update => update.type === 'ask_mode_handoff').map(update => update.data), [{ value: 'act' }],
'only the runtime limitation is offered the switch');