Skip to content

Proposal: UCB-based library suggestion selection (explore/exploit) #1

Description

@ianphil

Context

Right now, when the planner builds a graph, library suggestions that succeed get promoted and reused. The selection is greedy — first match wins, and there's no mechanism to discover that an untried approach might be better. This is the multi-armed bandit problem (Kochenderfer Ch. 15).

The Idea

Add Upper Confidence Bound (UCB) scoring to library suggestion selection. Each library entry tracks successes and attempts. When the planner selects a suggestion, instead of picking the first/best match, it picks the one with the highest UCB score:

score = (successes / attempts) + C * sqrt(ln(total_attempts) / attempts)

The second term is an uncertainty bonus — large when an option hasn't been tried much, shrinking as it gets more attempts. This naturally balances explore (try uncertain options) vs. exploit (use proven ones).

Concrete Example

  • mail search --from jake -> 8/10 successes, well-tested, small bonus -> score ~ 0.85
  • mail search --filter "from/emailAddress/address eq 'jake@microsoft.com'" -> never tried, huge uncertainty bonus -> score ~ 1.0+
  • System tries the untried option once. If it works (1/1), it competes on merit. If it fails (0/1), system goes back to the known option.

Questions to answer before implementing

  1. How does library promotion currently work? Where are suggestions stored, how are they matched to planner context, and how are they surfaced to the LLM?
  2. Would adding attempts and successes fields to the library model be straightforward?
  3. How to feed UCB scores into the planner prompt? Options: (a) rank suggestions by UCB before including them, (b) include the scores and let the LLM factor them in, (c) filter to top-N by UCB score.
  4. Where does "success" get recorded? After graph.Ok, or per-task?
  5. Interaction with the repair loop — if a suggestion fails on first attempt but succeeds after repair, is that a success or failure for the bandit?
  6. The exploration constant C needs tuning. What should it be given typical library size and usage frequency?

Estimated scope

~30 lines of scoring logic if the data model cooperates. The hard part is deciding the success signal and repair loop interaction, not the math.

References

  • Kochenderfer, Wheeler, Wray — Algorithms for Decision Making, Ch. 15 (Exploration and Exploitation)
  • Related to the capability system collapse (commit bbd4ada) and prompt consolidation (commit 6610034) from the recent refactor

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions