Skip to content
nonconvexcard

Tool Selection and Regret

An agent choosing among tools is running a bandit — and the logarithmic regret of UCB tells you exactly what exploration is worth.

AgentsGraduate⏱ 3 hours10 min readbanditsucbregretexplorationtool use
1 problem →

Setup

DefinitionCumulative regret

There are KK arms (tools). Arm ii yields i.i.d. rewards in [0,1][0,1] with unknown mean μi\mu_i. Let μ⋆=max⁡iμi\mu^\star = \max_i \mu_i and Δi=μ⋆−μi\Delta_i = \mu^\star - \mu_i be arm ii's gap. An algorithm choosing arm ItI_t at round tt has cumulative regret

RT=Tμ⋆−E[∑t=1TμIt]=∑i=1KΔi E[ni(T)],R_T = T\mu^\star - \E\left[\sum_{t=1}^T \mu_{I_t}\right] = \sum_{i=1}^K \Delta_i\,\E\big[n_i(T)\big],

where ni(T)n_i(T) counts pulls of arm ii in TT rounds.

The second equality is just bookkeeping: each pull of arm ii costs exactly Δi\Delta_i against the benchmark, so total regret is the gap-weighted pull count. Bounding regret therefore means bounding how often a suboptimal arm is pulled.

Algorithm — UCB1
  1. Pull each arm once.
  2. For t > K, pull the arm maximising UCBi(t)=μ^i(t)+2log⁡tni(t),\mathrm{UCB}_i(t) = \hat\mu_i(t) + \sqrt{\frac{2\log t}{n_i(t)}}, where μ^i(t)\hat\mu_i(t) is the empirical mean of arm ii's rewards so far.
  3. Update μ^\hat\mu and nn and repeat.

The second term is a confidence radius: wide for rarely-pulled arms, shrinking like 1/ni1/\sqrt{n_i}. Acting on the upper end of the interval is "optimism in the face of uncertainty" — an arm is played either because it looks good or because you do not yet know that it is not.

The pull bound

TheoremUCB1 pulls a suboptimal arm O(log T / Δ²) times

For rewards in [0,1][0,1] and any arm ii with \Delta_i > 0, UCB1 satisfies

E[ni(T)] ≤ 8log⁡TΔi2  +  1+π23.\E\big[n_i(T)\big] \ \le\ \frac{8\log T}{\Delta_i^2} \;+\; 1 + \frac{\pi^2}{3}.

Assumptions

Rewards i.i.d. per arm, bounded in [0,1][0,1], independent across arms and rounds, and stationary. The last is the assumption most often violated in agent settings and is discussed at the end.

CorollaryLogarithmic regret for UCB1
R_T \ \le\ \sum_{i:\Delta_i>0}\left(\frac{8\log T}{\Delta_i} + \left(1+\frac{\pi^2}{3}\right)\Delta_i\right) \qquad\text{and}\qquad R_T = O\big(\sqrt{KT\log T}\big).

Key idea

Two readings of the same result:

  • Per-instance: regret grows like log⁡T\log T, not TT. The fraction of rounds spent on the wrong tool tends to zero. Exploration is nearly free in the long run.
  • Small gaps are expensive. The 1/Δi21/\Delta_i^2 in the pull bound says arms that are nearly as good as the best get pulled a lot — which is fine, because each such pull costs only Δi\Delta_i. That is exactly why the regret bound carries 1/Δi1/\Delta_i rather than 1/Δi21/\Delta_i^2.
TheoremNo algorithm beats logarithmic regret

For any algorithm whose regret is o(Ta)o(T^a) for every a > 0 on every instance, and for a broad class of reward families, there are instances on which

\liminf_{T\to\infty}\frac{R_T}{\log T} \ \ge\ \sum_{i:\Delta_i>0}\frac{\Delta_i}{\mathrm{KL}(\nu_i\,\|\,\nu^\star)},

where KL(νi∥ν⋆)\mathrm{KL}(\nu_i\|\nu^\star) is the divergence between arm ii's reward distribution and the optimal arm's.

What this does not say

The gap between this theory and an actual agent is wide, and each gap is a genuine modelling failure rather than a technicality:

  • Tool quality is context-dependent. The right tool depends on the query, which makes this a contextual bandit; the analysis above is for a single fixed distribution per arm. Contextual algorithms exist with their own guarantees and different assumptions.
  • Rewards are not stationary. Tools change, indexes go stale, APIs degrade. UCB's confidence radius shrinks monotonically, so it becomes progressively less willing to re-explore an arm that has gone bad — the wrong behaviour under drift. Discounted or sliding-window variants exist.
  • Calls are not free or equal. Arms have different latencies and costs; the reward-per-round model prices them identically.
  • Feedback is delayed and partial. Whether a tool call helped is often only apparent at the end of a trajectory, if at all — the credit-assignment problem the bandit formulation assumes away.

Use the bandit framing to reason about exploration budgets and to recognise that a small persistent exploration rate is cheap. Do not read the regret bound as a guarantee about a deployed agent.

References

These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.

Results stated on this page

Problems (1)

All problems