# Bayesian Bandit Experimentation

> Replace fixed-split A/B tests with a bandit that dynamically shifts traffic toward better-performing agent variants in real time — minimizing exposure to the losers.

- **Category**: Agentic AI
- **Subcategory**: Governance & Observability
- **Canonical URL**: https://designpattern.fyi/patterns/bayesian_bandit_experimentation/

---

## Description
**Intent**: Replace fixed-split A/B tests between agent variants with a bandit that dynamically reallocates traffic toward better-performing variants based on observed reward, bounding regret from bad variants.
**Context**: You have multiple variants in play — two prompt templates, three model choices, two retrieval strategies. Classical A/B testing exposes many users to worse variants for the full test window. You want to learn *and* ship the winner faster.
**Solution**: Treat each variant as a bandit arm. After each request, record the variant chosen and (when available) the reward (task success, satisfaction, cost). A Thompson sampler or UCB policy decides the next allocation. Run until posterior separation crosses a threshold or a request budget is exhausted; promote the winner. Surface posterior means and credible intervals in the experiment dashboard.



## Use Cases
- Multiple variants are live and reward can be observed online with reasonable delay.
- Exposing users to losing variants for a full fixed test window is a real cost.
- Operators want a live posterior — not a fixed test window — to make promotion decisions.






## Trade-offs


### Advantages

- Regret from losing variants is bounded; allocation tracks evidence in real time.

- Many simultaneous variants can be explored without combinatorial regret.

- Operators see a live posterior and can promote early when evidence is clear.




### Considerations & Drawbacks

- Variants the bandit prunes early can be slow-burn winners — tune exploration carefully.

- Delayed reward complicates updates; naive bandits over-allocate to fast-responding variants.

- Optional-stopping at posterior-separation introduces bias if not disciplined.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/bayesian-bandit-experimentation/)

