Skip to content

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

Tiny Ask screenshot gate: keep the head and tail of a long message

Claudeab00b4352ea2
diff --git a/src/chrome/src/agent/tiny-ask.js b/src/chrome/src/agent/tiny-ask.js
index 74d2da9fe..004afa71c 100644
--- a/src/chrome/src/agent/tiny-ask.js
+++ b/src/chrome/src/agent/tiny-ask.js
@@ -62,6 +62,16 @@ export const TINY_ASK_SCREENSHOT_GATE_QUESTION = 'To answer this message well, d
+ 'screenshot of the current page, because the answer depends on how something on it looks (an image, photo, '
+ 'chart, colour, logo, button or layout) or on what a page with almost no text shows?';
+// A long message keeps its opening and its end, where the actual request
+// usually is ("…compare this with the logo on the current page").
+export const TINY_ASK_SCREENSHOT_GATE_HEAD_CHARS = 600;
+export const TINY_ASK_SCREENSHOT_GATE_TAIL_CHARS = 1400;
+function gateExcerpt(text) {
+ const value = String(text || '');
+ if (value.length <= TINY_ASK_SCREENSHOT_GATE_HEAD_CHARS + TINY_ASK_SCREENSHOT_GATE_TAIL_CHARS) return value;
+ return `${value.slice(0, TINY_ASK_SCREENSHOT_GATE_HEAD_CHARS)} […] ${value.slice(-TINY_ASK_SCREENSHOT_GATE_TAIL_CHARS)}`;
+}
+
export function tinyAskScreenshotGate({ question = '', pageChars = 0, imageAttachment = false, linkedPage = false } = {}) {
const chars = Math.max(0, Number(pageChars) || 0);
const facts = [
@@ -70,7 +80,7 @@ export function tinyAskScreenshotGate({ question = '', pageChars = 0, imageAttac
`The message links another page: ${linkedPage ? 'yes' : 'no'}.`,
];
return {
- state: `The user's message to the browser assistant:\n${String(question || '').slice(0, 2000)}\n\n${facts.join('\n')}`,
+ state: `The user's message to the browser assistant:\n${gateExcerpt(question)}\n\n${facts.join('\n')}`,
questions: { needs_screenshot: { type: 'noul', instructions: TINY_ASK_SCREENSHOT_GATE_QUESTION } },
};
}
diff --git a/test/run.js b/test/run.js
index bdca2c421..d6429d671 100644
--- a/test/run.js
+++ b/test/run.js
@@ -41621,6 +41621,10 @@ test('tiny Ask shows a vision-capable in-browser model the visible page when its
assert.equal(tinyAskScreenshotGateProbability({ needs_screenshot: { type: 'noul', noul: 0.8 } }), 0.8);
assert.equal(tinyAskScreenshotGateProbability({}), null);
assert.match(tinyAskScreenshotGate({ question: 'x', pageChars: 12 }).state, /Current page text: almost none\./);
+ const long = tinyAskScreenshotGate({ question: `${'Background notes. '.repeat(300)}Compare this with the logo on the current page.` }).state;
+ assert.match(long, /Compare this with the logo on the current page\./, 'a long message keeps its end, where the request is');
+ assert.match(long, /^The user's message to the browser assistant:\nBackground notes\./, 'and its opening');
+ assert.ok(long.length < 2300, 'bounded');
assert.match(TINY_ASK_SYSTEM_PROMPT, /a screenshot of its visible part/);
assert.match(TINY_ASK_SYSTEM_PROMPT, /one-time codes that appear in page text or a screenshot/, 'the no-secrets rule covers screenshots');
assert.match(TINY_ASK_SCREENSHOT_NOTE, /never repeat passwords, keys, tokens or one-time codes/);