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
Preserve bare acknowledgments after planner questions
Emre Sokullu2aa34c30bc40
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 919938ffa..3ec7a558d 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -33500,11 +33500,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| this._isScheduledResumeTurn(value) || this._activeTaskBinding(messages || []).index < 0) return 'request';const reference = this._userTurnReference(messages);const verdict = await this._semanticDecision(tabId, 'user_turn_kind', { request: value, page: reference });- // A reply to the planner's own question answers it ("ok" there is consent- // or a choice), so it never ends the turn as a bare acknowledgment.- if (verdict.choice === 'acknowledge' && this._plannerClarificationIndexBefore(messages || [], (messages || []).length) >= 0) {- return 'update';- }+ // A bare acknowledgment ("thanks") stays terminal even right after a+ // planner question: confirmations that answer it already read as `update`+ // per the semantic choice definition, so converting `acknowledge` would+ // resume the prior task with "thanks" as its answer.return ['continue', 'update', 'acknowledge', 'request'].includes(verdict.choice) ? verdict.choice : null;}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 24618f78e..547e7b0d3 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -30779,11 +30779,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| this._isScheduledResumeTurn(value) || this._activeTaskBinding(messages || []).index < 0) return 'request';const reference = this._userTurnReference(messages);const verdict = await this._semanticDecision(tabId, 'user_turn_kind', { request: value, page: reference });- // A reply to the planner's own question answers it ("ok" there is consent- // or a choice), so it never ends the turn as a bare acknowledgment.- if (verdict.choice === 'acknowledge' && this._plannerClarificationIndexBefore(messages || [], (messages || []).length) >= 0) {- return 'update';- }+ // A bare acknowledgment ("thanks") stays terminal even right after a+ // planner question: confirmations that answer it already read as `update`+ // per the semantic choice definition, so converting `acknowledge` would+ // resume the prior task with "thanks" as its answer.return ['continue', 'update', 'acknowledge', 'request'].includes(verdict.choice) ? verdict.choice : null;}diff --git a/test/follow-up-task-context.mjs b/test/follow-up-task-context.mjsindex c157e1474..9fcfb4f8c 100644--- a/test/follow-up-task-context.mjs+++ b/test/follow-up-task-context.mjs@@ -277,44 +277,71 @@ for (const build of ['chrome', 'firefox']) {assert.equal(agent._plannerAuthenticTaskText(messages), 'Instead explain this article.');});- // An unavailable reading must not turn the answer into a new task, and "ok"- // to the planner's own question must not end the turn as an acknowledgment.- for (const reading of [null, 'acknowledge']) {- test(`${build}: a reply to the planner question answers it when the reading is ${reading || 'unavailable'}`, async () => {- const { agent, messages } = fixture();- const question = 'Which email should I use?';- messages.push({ role: 'assistant', content: question, webbrainPlannerClarification: {- taskText: root, taskKey: agent._progressTaskKeyForText(root), requiresSubmission: true } });- const answer = reading ? 'ok, the one already filled in' : 'use [email protected]';- const calls = installModelStub(agent, { decide: (_kind, { request, page }) => {- assert.equal(page.last_question, question);- return reading ? { choice: reading, evidence: request } : null;- } });- const turn = user(answer);- await agent._markUserTurnKind(tab, messages, turn, answer, 'act');- assert.equal(calls.length, 1);- assert.equal(turn.webbrainTurnKind, reading ? 'update' : undefined);- const view = [...messages, turn];- const binding = agent._activeTaskBinding(view);- assert.equal(binding.taskIndex, 1);- assert.equal(binding.clarificationIndex, 2);- const task = agent._plannerAuthenticTaskText(view);- const parsed = JSON.parse(task.slice(task.indexOf('{')));- assert.equal(parsed.request, root);- assert.equal(parsed.latest_request, answer);- assert.equal(parsed.relationship, reading ? 'update' : 'clarification');- let planned = null;- agent._runPlannerGate = async (_tab, _enriched, _update, _cost, _run, _history, _info, _plannerMode, _mode, _options, follow) => {- planned = follow.authenticTaskText;- return { proceed: true, requestKind: 'execute', requiresStateChange: true };- };- const result = await agent._maybeRunPlannerGate(tab, messages, turn, () => {}, 'act', {}, null,- { tabUrl: 'https://owned.test/form', tabTitle: 'Form' });- assert.equal(result.proceed, true, JSON.stringify(result));- assert.equal(planned, task, 'The planner receives the answer with the task it clarifies.');- assert.equal(agent._progressTaskAnchorText(tab), binding.text);- });- }+ // An unavailable reading must not turn the answer into a new task. A bare+ // acknowledgment ("thanks") after the planner's own question stays terminal+ // instead of resuming the prior task with "thanks" as its answer; a reply+ // that answers the question already reads as `update` per the semantic+ // choice definition.+ test(`${build}: a reply to the planner question answers it when the reading is unavailable`, async () => {+ const { agent, messages } = fixture();+ const question = 'Which email should I use?';+ messages.push({ role: 'assistant', content: question, webbrainPlannerClarification: {+ taskText: root, taskKey: agent._progressTaskKeyForText(root), requiresSubmission: true } });+ const answer = 'use [email protected]';+ const calls = installModelStub(agent, { decide: (_kind, { request, page }) => {+ assert.equal(page.last_question, question);+ return null;+ } });+ const turn = user(answer);+ await agent._markUserTurnKind(tab, messages, turn, answer, 'act');+ assert.equal(calls.length, 1);+ assert.equal(turn.webbrainTurnKind, undefined);+ const view = [...messages, turn];+ const binding = agent._activeTaskBinding(view);+ assert.equal(binding.taskIndex, 1);+ assert.equal(binding.clarificationIndex, 2);+ const task = agent._plannerAuthenticTaskText(view);+ const parsed = JSON.parse(task.slice(task.indexOf('{')));+ assert.equal(parsed.request, root);+ assert.equal(parsed.latest_request, answer);+ assert.equal(parsed.relationship, 'clarification');+ let planned = null;+ agent._runPlannerGate = async (_tab, _enriched, _update, _cost, _run, _history, _info, _plannerMode, _mode, _options, follow) => {+ planned = follow.authenticTaskText;+ return { proceed: true, requestKind: 'execute', requiresStateChange: true };+ };+ const result = await agent._maybeRunPlannerGate(tab, messages, turn, () => {}, 'act', {}, null,+ { tabUrl: 'https://owned.test/form', tabTitle: 'Form' });+ assert.equal(result.proceed, true, JSON.stringify(result));+ assert.equal(planned, task, 'The planner receives the answer with the task it clarifies.');+ assert.equal(agent._progressTaskAnchorText(tab), binding.text);+ });++ test(`${build}: a bare acknowledgment after the planner question stays terminal`, async () => {+ const { agent, messages } = fixture();+ const question = 'Which email should I use?';+ messages.push({ role: 'assistant', content: question, webbrainPlannerClarification: {+ taskText: root, taskKey: agent._progressTaskKeyForText(root), requiresSubmission: true } });+ const answer = 'Thanks!';+ const calls = installModelStub(agent, { decide: (_kind, { request, page }) => {+ assert.equal(page.last_question, question);+ return { choice: 'acknowledge', evidence: request };+ } });+ const turn = user(answer);+ await agent._markUserTurnKind(tab, messages, turn, answer, 'act');+ assert.equal(calls.length, 1);+ assert.equal(turn.webbrainTurnKind, 'acknowledge');+ const view = [...messages, turn];+ const binding = agent._activeTaskBinding(view);+ assert.equal(binding.taskIndex, 1);+ assert.equal(binding.clarificationIndex, -1, 'A bare acknowledgment is not a clarification answer.');+ agent._runPlannerGate = agent._runPlannerIntentGate = async () => { throw new Error('Acknowledgment must not resume execution'); };+ const result = await agent._maybeRunPlannerGate(tab, messages, turn, () => {}, 'act', {}, null,+ { tabUrl: 'https://owned.test/form', tabTitle: 'Form' });+ assert.equal(result.proceed, false, JSON.stringify(result));+ assert.equal(result.reason, 'acknowledged');+ assert.equal(agent._progressTaskAnchorText(tab), root);+ });test(`${build}: corrections keep task history while later no-send overrides earlier send intent`, async () => {const { agent, messages } = fixture();