Skip to content

Commit aca3ebf

Browse files
authored
Merge pull request #217 from PredicateSystems/read_task
Expand extraction detection and add SCROLL_AND_COUNT action for count…
2 parents 9d7a1d5 + 3c7418d commit aca3ebf

5 files changed

Lines changed: 282 additions & 23 deletions

File tree

src/agents/planner-executor/extraction-keywords.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ const AMBIGUOUS_VERBS: readonly string[] = [
4949
'gather',
5050
'return',
5151
'output',
52+
'note',
53+
'record',
54+
'summarize',
55+
'outline',
56+
'compare',
57+
'calculate',
5258
];
5359

5460
/**
@@ -59,12 +65,15 @@ const EXTRACTION_PHRASES: readonly string[] = [
5965
'what is',
6066
'what are',
6167
"what's",
68+
'what does',
6269
'show me',
6370
'tell me',
6471
'find the',
6572
'get the',
6673
'read the',
6774
'list the',
75+
'note down',
76+
'write down',
6877
'title of',
6978
'price of',
7079
'name of',
@@ -104,6 +113,7 @@ const CONTENT_NOUNS: readonly string[] = [
104113
'summary',
105114
'excerpt',
106115
'price',
116+
'pricing',
107117
'cost',
108118
'amount',
109119
'name',
@@ -140,6 +150,22 @@ const CONTENT_NOUNS: readonly string[] = [
140150
'product',
141151
'results',
142152
'listings',
153+
'benefits',
154+
'services',
155+
'courses',
156+
'games',
157+
'guidelines',
158+
'steps',
159+
'tips',
160+
'events',
161+
'options',
162+
'perks',
163+
'faqs',
164+
'specifications',
165+
'features',
166+
'formats',
167+
'cities',
168+
'countries',
143169
];
144170

145171
/**
@@ -342,7 +368,55 @@ Example - product price on listing page:
342368
Goal: "find the price of the first laptop"
343369
Current URL: store.com/laptops (correct page, prices visible)
344370
{"action":"EXTRACT","target":"price of first laptop","goal":"Extract the price of the first laptop listing","verify":[],"reasoning":"prices are visible in listing elements"}
345-
`;
371+
372+
STEP 3 - COUNTING ACROSS FULL PAGE:
373+
If the task asks to COUNT items ("how many", "number of", "count", "total"):
374+
- Use SCROLL_AND_COUNT instead of EXTRACT
375+
- Set "countTarget" to describe what to count (e.g., "listings", "products", "articles")
376+
- The system will scroll through the entire page and sum up counts
377+
- Do NOT use EXTRACT for counting tasks — EXTRACT only sees the current viewport
378+
379+
Example - count all listings:
380+
Goal: "note how many listings are available"
381+
Current URL: alibaba.com/search?SearchText=smartphones (correct page)
382+
{"action":"SCROLL_AND_COUNT","countTarget":"product listings","goal":"Count total product listings","verify":[]}
383+
`;
384+
}
385+
386+
// ---------------------------------------------------------------------------
387+
// Counting Task Detection
388+
// ---------------------------------------------------------------------------
389+
390+
const COUNTING_PHRASES: readonly string[] = [
391+
'how many',
392+
'how much',
393+
'number of',
394+
'count the',
395+
'count of',
396+
'total number',
397+
'total count',
398+
'how numerous',
399+
];
400+
401+
const COUNTING_VERBS: readonly string[] = ['count', 'tally', 'enumerate'];
402+
403+
export function isCountingTask(task: string): boolean {
404+
if (!task) return false;
405+
const taskLower = task.toLowerCase();
406+
407+
if (COUNTING_PHRASES.some(phrase => taskLower.includes(phrase))) {
408+
return true;
409+
}
410+
411+
if (
412+
COUNTING_VERBS.some(verb =>
413+
new RegExp(`\\b${escapeRegExp(verb)}(s|ed|ing)?\\b`).test(taskLower)
414+
)
415+
) {
416+
return true;
417+
}
418+
419+
return false;
346420
}
347421

348422
// ---------------------------------------------------------------------------

src/agents/planner-executor/plan-models.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const ActionType = z.enum([
4545
'TYPE',
4646
'TYPE_AND_SUBMIT',
4747
'SCROLL',
48+
'SCROLL_AND_COUNT',
4849
'PRESS',
4950
'WAIT',
5051
'EXTRACT',
@@ -90,7 +91,7 @@ export const PlanStepSchema = z.lazy(() =>
9091
id: z.number().optional().describe('Step ID (1-indexed, contiguous)'),
9192
goal: z.string().optional().describe('Human-readable goal for this step'),
9293
action: ActionType.describe(
93-
'Action type: NAVIGATE, CLICK, TYPE, TYPE_AND_SUBMIT, SCROLL, PRESS, WAIT, EXTRACT, STUCK, DONE'
94+
'Action type: NAVIGATE, CLICK, TYPE, TYPE_AND_SUBMIT, SCROLL, SCROLL_AND_COUNT, PRESS, WAIT, EXTRACT, STUCK, DONE'
9495
),
9596
target: z
9697
.union([z.string(), z.record(z.string(), z.unknown())])

src/agents/planner-executor/plan-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ const ACTION_ALIASES: Record<string, string> = {
362362
SCROLL_UP: 'SCROLL',
363363
SCROLL_TO: 'SCROLL',
364364
SCROLL_INTO_VIEW: 'SCROLL',
365+
COUNT: 'SCROLL_AND_COUNT',
366+
SCROLL_COUNT: 'SCROLL_AND_COUNT',
365367
};
366368

367369
/**

0 commit comments

Comments
 (0)