Skip to content

Commit 90ae63c

Browse files
author
SentienceDEV
committed
make agent categorize tasks
1 parent d1a1084 commit 90ae63c

18 files changed

+2645
-30
lines changed

predicate/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@
119119
from .ordinal import OrdinalIntent, boost_ordinal_elements, detect_ordinal_intent, select_by_ordinal
120120
from .overlay import clear_overlay, show_overlay
121121
from .permissions import PermissionPolicy
122+
from .pruning import (
123+
CategoryDetectionResult,
124+
PrunedSnapshotContext,
125+
PruningTaskCategory,
126+
SkeletonDomNode,
127+
classify_task_category,
128+
prune_snapshot_for_task,
129+
serialize_pruned_snapshot,
130+
)
122131
from .query import find, query
123132
from .read import extract, extract_async, read, read_best_effort
124133
from .recorder import Recorder, Trace, TraceStep, record
@@ -313,6 +322,13 @@
313322
"save_storage_state",
314323
# Formatting (v0.12.0+)
315324
"format_snapshot_for_llm",
325+
"CategoryDetectionResult",
326+
"PrunedSnapshotContext",
327+
"PruningTaskCategory",
328+
"SkeletonDomNode",
329+
"classify_task_category",
330+
"prune_snapshot_for_task",
331+
"serialize_pruned_snapshot",
316332
# Agent Config (v0.12.0+)
317333
"AgentConfig",
318334
# Enums

predicate/agent_runtime.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,23 @@ async def click(self, element_id: int) -> None:
398398

399399
await self.record_action(f"CLICK({element_id})")
400400

401-
async def type(self, element_id: int, text: str) -> None:
401+
async def type(self, element_id: int, text: str, *, delay_ms: float | None = None) -> None:
402402
"""
403403
Type text into an element.
404404
405405
Args:
406406
element_id: Element ID from snapshot
407407
text: Text to type
408+
delay_ms: Optional delay between keystrokes in milliseconds
408409
"""
409410
# First click to focus
410411
await self.click(element_id)
411412

412413
# Then type
413-
await self.backend.type_text(text)
414+
if delay_ms is None:
415+
await self.backend.type_text(text)
416+
else:
417+
await self.backend.type_text(text, delay_ms=delay_ms)
414418
await self.record_action(f"TYPE({element_id}, '{text[:20]}...')" if len(text) > 20 else f"TYPE({element_id}, '{text}')")
415419

416420
async def press(self, key: str) -> None:

predicate/agents/automation_task.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,32 @@ class AutomationTask:
179179
# Domain hints for heuristics (e.g., ["ecommerce", "amazon"])
180180
domain_hints: tuple[str, ...] = field(default_factory=tuple)
181181

182+
# Force a specific pruning category (overrides auto-detection)
183+
force_pruning_category: str | None = None
184+
185+
def pruning_category_hint(self):
186+
"""
187+
Return the pruning-oriented category for this task.
188+
189+
If force_pruning_category is set, returns that category directly.
190+
Otherwise, uses rule-based normalization from task text and hints.
191+
"""
192+
from ..pruning import PruningTaskCategory, classify_task_category
193+
194+
# If a category is forced, return it directly
195+
if self.force_pruning_category:
196+
try:
197+
return PruningTaskCategory(self.force_pruning_category)
198+
except ValueError:
199+
pass # Invalid category, fall through to auto-detection
200+
201+
return classify_task_category(
202+
task_text=self.task,
203+
current_url=self.starting_url,
204+
domain_hints=self.domain_hints,
205+
task_category=self.category,
206+
).category
207+
182208
@classmethod
183209
def from_webbench_task(cls, task: Any) -> "AutomationTask":
184210
"""

0 commit comments

Comments
 (0)