Skip to content

Commit ebc67ef

Browse files
author
SentienceDEV
committed
improve agent with retries2
1 parent 037f118 commit ebc67ef

File tree

3 files changed

+592
-34
lines changed

3 files changed

+592
-34
lines changed

examples/planner-executor/custom_config_example.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from predicate import AsyncPredicateBrowser
2525
from predicate.agent_runtime import AgentRuntime
2626
from predicate.agents import (
27+
CheckoutDetectionConfig,
2728
ModalDismissalConfig,
2829
PlannerExecutorAgent,
2930
PlannerExecutorConfig,
@@ -309,9 +310,55 @@ async def example_modal_dismissal() -> None:
309310
print(f" Multilingual: {len(config_multilingual.modal.dismiss_patterns)} patterns")
310311

311312

313+
async def example_checkout_detection() -> None:
314+
"""Checkout page detection configuration."""
315+
print("\n--- Example 10: Checkout Detection ---")
316+
print("Auto-detect checkout pages and trigger continuation replanning")
317+
318+
# Default: enabled with common checkout patterns
319+
config_default = PlannerExecutorConfig()
320+
print(f" Default enabled: {config_default.checkout.enabled}")
321+
print(f" Default URL patterns: {config_default.checkout.url_patterns[:5]}...")
322+
323+
# Disable checkout detection
324+
config_disabled = PlannerExecutorConfig(
325+
checkout=CheckoutDetectionConfig(enabled=False),
326+
)
327+
print(f" Disabled: checkout.enabled={config_disabled.checkout.enabled}")
328+
329+
# Custom patterns for German e-commerce sites
330+
config_german = PlannerExecutorConfig(
331+
checkout=CheckoutDetectionConfig(
332+
url_patterns=(
333+
"/warenkorb", # Cart
334+
"/kasse", # Checkout
335+
"/zahlung", # Payment
336+
"/bestellung", # Order
337+
"/anmelden", # Sign-in
338+
),
339+
element_patterns=(
340+
"zur kasse", # To checkout
341+
"warenkorb", # Shopping cart
342+
"jetzt kaufen", # Buy now
343+
"anmelden", # Sign in
344+
),
345+
),
346+
)
347+
print(f" German URL patterns: {config_german.checkout.url_patterns[:3]}...")
348+
349+
# Disable replan trigger (just detect, don't act)
350+
config_detect_only = PlannerExecutorConfig(
351+
checkout=CheckoutDetectionConfig(
352+
enabled=True,
353+
trigger_replan=False, # Only detect, don't trigger continuation
354+
),
355+
)
356+
print(f" Detect-only: trigger_replan={config_detect_only.checkout.trigger_replan}")
357+
358+
312359
async def example_full_custom() -> None:
313360
"""Full custom configuration with all options."""
314-
print("\n--- Example 10: Full Custom Config ---")
361+
print("\n--- Example 11: Full Custom Config ---")
315362

316363
config = PlannerExecutorConfig(
317364
# Snapshot escalation with scroll-after-escalation
@@ -347,6 +394,11 @@ async def example_full_custom() -> None:
347394
enabled=True,
348395
max_attempts=2,
349396
),
397+
# Checkout detection (continue workflow on checkout pages)
398+
checkout=CheckoutDetectionConfig(
399+
enabled=True,
400+
trigger_replan=True,
401+
),
350402
# Pre-step verification
351403
pre_step_verification=True,
352404
# Planner settings
@@ -369,11 +421,12 @@ async def example_full_custom() -> None:
369421
print(f" Pre-step verification: {config.pre_step_verification}")
370422
print(f" Recovery enabled: {config.recovery.enabled}")
371423
print(f" Modal dismissal: {config.modal.enabled}")
424+
print(f" Checkout detection: {config.checkout.enabled}")
372425

373426

374427
async def example_run_with_config() -> None:
375428
"""Run agent with custom config."""
376-
print("\n--- Example 11: Run Agent with Custom Config ---")
429+
print("\n--- Example 12: Run Agent with Custom Config ---")
377430

378431
openai_key = os.getenv("OPENAI_API_KEY")
379432
if not openai_key:
@@ -438,6 +491,7 @@ async def main() -> None:
438491
await example_pre_step_verification()
439492
await example_recovery_navigation()
440493
await example_modal_dismissal()
494+
await example_checkout_detection()
441495
await example_full_custom()
442496
await example_run_with_config()
443497

predicate/agents/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from .composable_heuristics import ComposableHeuristics
3939
from .heuristic_spec import COMMON_HINTS, HeuristicHint, get_common_hint
4040
from .planner_executor_agent import (
41+
AuthBoundaryConfig,
42+
CheckoutDetectionConfig,
4143
ExecutorOverride,
4244
IntentHeuristics,
4345
ModalDismissalConfig,
@@ -76,6 +78,8 @@
7678
"HeuristicHint",
7779
"get_common_hint",
7880
# Planner + Executor Agent
81+
"AuthBoundaryConfig",
82+
"CheckoutDetectionConfig",
7983
"ExecutorOverride",
8084
"IntentHeuristics",
8185
"ModalDismissalConfig",

0 commit comments

Comments
 (0)