Playwright to AI Agent Migration (Part 2): Dual-Mode API Design and Gradual Rollout

Same API interface, can route to either scripts or AI. Config switch, A/B comparison, gradual traffic increase — migration doesn't require downtime.

16Yun Engineering TeamMay 8, 20261 min read

Migration Doesn't Require Downtime

Traditional system migration: one-shot switch, high rollback cost.

AI browser automation migration doesn't need this. Scripts and AI agents both operate on the same browser API (CDP). They can run in parallel behind the same interface.

Dual-Mode Interface

class ExtractionEngine:
    """Same interface, two implementations"""
    async def extract_product_info(self, url, fields, mode="auto"):
        if mode == "script":
            return await self.script_engine.extract(url, fields)
        elif mode == "ai":
            return await self.ai_engine.extract(url, fields)
        elif mode == "compare":
            script_result, ai_result = await asyncio.gather(
                self.script_engine.extract(url, fields),
                self.ai_engine.extract(url, fields),
            )
            return self.compare_results(script_result, ai_result)
        else:
            if self.should_use_ai(url):
                return await self.ai_engine.extract(url, fields)
            return await self.script_engine.extract(url, fields)

Gradual Traffic Control

Day 1: AI traffic = 1%  → observe: any errors?
Day 2: AI traffic = 5%  → observe: success rate dropping?
Day 3: AI traffic = 10% → observe: latency increasing?
Day 4-7: +10-20% daily
Day 8: AI traffic = 100%

Auto-Rollback

class AutoRollback:
    def should_rollback(self, metrics):
        reasons = []
        if metrics["success_rate"] < self.baseline["success_rate"] - 0.02:
            reasons.append("Success rate dropped")
        if metrics["avg_duration_ms"] > self.baseline["avg_duration_ms"] * 2:
            reasons.append("Duration doubled")
        return reasons

Summary

Migration from Playwright to AI agents doesn't require downtime. Core design:

  1. Dual-mode interface — same API, can route to scripts or AI
  2. Comparison mode — run both implementations simultaneously
  3. Gradual rollout — start at 1%, increase progressively
  4. Auto-rollback — success rate drop or latency increase triggers automatic fallback

Need an enterprise proxy plan?

We can tailor architecture to your target domains, concurrency, and reliability goals.