Context
AgenticPay processes payments across Stellar (Soroban) and EVM chains. Currently, the routing engine selects chains based on static configuration rather than real-time conditions, leading to suboptimal fee/speed tradeoffs.
Current Limitation/Problem
The routing system uses hardcoded chain priorities. It cannot dynamically adapt to network congestion, fluctuating gas prices, or historical reliability metrics.
Expected Outcome
An ML-driven routing engine that selects the optimal chain for each payment based on real-time and historical data, minimizing cost and latency while maximizing success rate.
Acceptance Criteria
- Implement feature extraction pipeline collecting gas prices, confirmation times, and success rates per chain
- Train a lightweight ranking model (XGBoost or similar) for chain selection
- Expose routing decision logs with rationale for auditability
- Achieve <50ms routing decision latency at p99
- Support manual override via admin API
- A/B test framework comparing static vs AI routing outcomes
Technical Scope
backend/src/services/routing/ - new routing engine module
backend/src/services/routing/ai-router.ts - ML inference wrapper
backend/src/queues/routing-evaluation.queue.ts - periodic feature collection
- Prisma schema additions for routing metrics table
- Redis sorted sets for real-time chain performance data
- Integration with existing PaymentService and ChainConnector interfaces
- Edge cases: chain outage fallback, stale data handling, model cold start
Context
AgenticPay processes payments across Stellar (Soroban) and EVM chains. Currently, the routing engine selects chains based on static configuration rather than real-time conditions, leading to suboptimal fee/speed tradeoffs.
Current Limitation/Problem
The routing system uses hardcoded chain priorities. It cannot dynamically adapt to network congestion, fluctuating gas prices, or historical reliability metrics.
Expected Outcome
An ML-driven routing engine that selects the optimal chain for each payment based on real-time and historical data, minimizing cost and latency while maximizing success rate.
Acceptance Criteria
Technical Scope
backend/src/services/routing/- new routing engine modulebackend/src/services/routing/ai-router.ts- ML inference wrapperbackend/src/queues/routing-evaluation.queue.ts- periodic feature collection