Skip to content

Commit 61b671f

Browse files
authored
Merge pull request #206 from PredicateSystems/fix_ext3
planner executor agent improvements
2 parents bf0b189 + 8f0ab0b commit 61b671f

10 files changed

Lines changed: 777 additions & 70 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agents/planner-executor/boundary-detection.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ function urlPredicateSignals(verify: PredicateSpec[] | undefined): string[] {
285285
return signals;
286286
}
287287

288+
function isProductNavigationIntent(step: {
289+
action?: string;
290+
intent?: string;
291+
input?: string;
292+
verify?: PredicateSpec[];
293+
}): boolean {
294+
const action = (step.action || '').toUpperCase();
295+
if (action !== 'CLICK') {
296+
return false;
297+
}
298+
const cues = `${normalizeIntentText(step.intent)} ${normalizeIntentText(step.input)}`;
299+
return /\b(product|result|details?|item|listing)\b/.test(cues);
300+
}
301+
288302
export function isSearchLikeTypeAndSubmit(
289303
step: { action?: string; intent?: string; input?: string; verify?: PredicateSpec[] },
290304
element?: Pick<SnapshotElement, 'role' | 'text' | 'name' | 'ariaLabel'> | null
@@ -330,6 +344,18 @@ export function isUrlChangeRelevantToIntent(
330344
return true;
331345
}
332346

347+
if (isProductNavigationIntent(step)) {
348+
const productUrlHints = ['/dp/', '/product/', '/item/', '/sku/', '/p/'];
349+
if (productUrlHints.some(hint => normalizeIntentText(nextUrl).includes(hint))) {
350+
return true;
351+
}
352+
const terms = [...queryTerms(step.input), ...queryTerms(step.intent)];
353+
if (terms.length > 0) {
354+
return terms.some(term => nextSignals.some(signal => signal.includes(term)));
355+
}
356+
return false;
357+
}
358+
333359
if (!isSearchLikeTypeAndSubmit(step, element)) {
334360
return true;
335361
}

src/agents/planner-executor/category-pruner.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ function nearbyTextOf(element: SnapshotElement): string {
1919
return String(element.nearbyText || '').toLowerCase();
2020
}
2121

22+
function combinedTextOf(element: SnapshotElement): string {
23+
return [element.text, element.name, element.ariaLabel, element.nearbyText, element.href]
24+
.filter((value): value is string => Boolean(value))
25+
.join(' ')
26+
.toLowerCase();
27+
}
28+
29+
function hasSearchCue(element: SnapshotElement): boolean {
30+
const combined = combinedTextOf(element);
31+
return (
32+
combined.includes('search') ||
33+
combined.includes('keyword') ||
34+
combined.includes('find') ||
35+
combined.includes('query')
36+
);
37+
}
38+
2239
function roleOf(element: SnapshotElement): string {
2340
return String(element.role || '').toLowerCase();
2441
}
@@ -62,7 +79,10 @@ function allowShopping(element: SnapshotElement): boolean {
6279
if (text.includes('$') || nearbyText.includes('price')) {
6380
return true;
6481
}
65-
if (['textbox', 'searchbox', 'combobox'].includes(role) && text.includes('search')) {
82+
if (role === 'searchbox') {
83+
return true;
84+
}
85+
if (['textbox', 'combobox', 'input', 'textarea'].includes(role) && hasSearchCue(element)) {
6686
return true;
6787
}
6888
return Boolean(element.inDominantGroup && text.trim().length >= 3);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ function normalizeStep(step: Record<string, unknown>): Record<string, unknown> {
362362
delete normalizedStep.url;
363363
}
364364

365+
if ('target' in normalizedStep && typeof normalizedStep.target === 'number') {
366+
normalizedStep.target = String(normalizedStep.target);
367+
}
368+
if ('target' in normalizedStep && normalizedStep.target === null) {
369+
delete normalizedStep.target;
370+
}
371+
365372
if ('id' in normalizedStep && typeof normalizedStep.id === 'string') {
366373
const parsed = parseInt(normalizedStep.id, 10);
367374
if (!isNaN(parsed)) {

0 commit comments

Comments
 (0)