Simulation
Adversarial buyer persona simulation engine
@guardrail-sim/simulation
Stress-test your pricing policies by running adversarial buyer personas through multi-round negotiation loops.
Installation
Quick Start
Buyer Personas
Five built-in personas cover the full spectrum of buyer behavior:
| Persona | Strategy | Behavior |
|---|---|---|
| Budget Buyer | Cooperative | Requests modest discounts (3-8%), backs off quickly |
| Strategic Buyer | Strategic | Starts mid-high, negotiates down incrementally |
| Margin Hunter | Adversarial | Probes the margin floor with low-margin orders |
| Volume Gamer | Adversarial | Games volume tier boundaries (orders near qty 100) |
| Code Stacker | Adversarial | Attempts maximum discounts (20-30%), barely concedes |
Custom Personas
Negotiation Loop
Each session follows this flow:
- Persona generates an initial discount request based on its strategy
- Policy engine evaluates the request
- If approved: session ends with acceptance
- If rejected: persona adapts based on
adaptationRateand tries again - If all rounds exhausted: session ends with rejection
The adaptationRate controls how much a persona concedes after rejection:
- Cooperative (0.5): Large concessions, quick resolution
- Strategic (0.3): Moderate concessions, gradual negotiation
- Adversarial (0.1-0.15): Minimal concessions, boundary probing
Reproducibility
All simulations are deterministic given the same seed:
Uses a seeded PRNG (mulberry32) — never Math.random().
Metrics
The SimulationMetrics object contains:
totalSessions— Number of negotiation sessionsapprovalRate— Fraction of sessions that ended in acceptanceaverageDiscountApproved— Mean discount for approved sessionsaverageDiscountRequested— Mean discount across all requestsaverageMarginAfterDiscount— Mean margin for approved discountsviolationsByRule— Count of violations per rule nameoutcomesByPersona— Accepted/rejected/abandoned per personalimitingFactors— Which rule limited most oftenedgeCasesFound— Boundary conditions detected
Edge Case Detection
The engine automatically detects:
- Discounts approved near the margin floor (<17% margin)
- Orders at volume tier boundaries (qty 95-105 with 10-15% discount)
- High discounts approved (>20%)
For targeted boundary testing:
Insights Bridge
Convert results to feed the @guardrail-sim/insights analysis engine:
This enables 8 built-in simulation insight checks including coverage analysis, segment distribution, unused rule detection, and limiting factor analysis.
PersonaProvider Interface
The simulation uses a PersonaProvider interface for generating requests:
The built-in implementation is fully deterministic. The interface is designed for future LLM-backed persona providers without requiring changes to the runner.