dsh-tool-bandit-search
A DeepSeek Harness plugin that replaces the standard web_search tool with a search tool that learns which search strategy to use through a contextual multi-armed bandit, instead of relying on a single hardcoded approach.
Why
Every web search has a tradeoff: a fast, narrow query gets you an answer quickly, but a broader, multi-angle query gets you better coverage at the cost of latency. Hardcoding one strategy means always overpaying for simple questions or always underdelivering on complex ones. This plugin lets the tool discover, from real usage, which strategy tends to pay off — and keeps adapting as conditions change.
How it works
The search tool has two internal strategies ("arms"):
quick — a single search query, capped at 5 results. Fast, good for simple factual lookups.
thorough — three query variants (the original plus two reframed angles) run in parallel and merged/deduplicated, capped at 10 results. Slower, better for open-ended or multi-perspective questions.
On every call, the plugin uses Thompson sampling to pick an arm: each arm has a Beta(α, β) distribution representing its estimated reward, the plugin samples from both distributions, and whichever sample is higher gets used. This naturally balances exploration (trying the less-proven arm occasionally) against exploitation (favoring the arm that's performed better so far).
After the call, a continuous reward in [0, 1] is computed from two components, weighted equally:
- Quality — how many results came back, relative to that arm's own maximum (so a 5-of-5 "quick" result is scored the same as a 10-of-10 "thorough" result — neither arm is structurally favored by its own result cap).
- Speed — how fast the call completed, calibrated against realistic search latency.
That reward updates the chosen arm's Beta distribution (α += reward, β += 1 − reward), so the bandit's beliefs shift a little after every single call — no separate training phase, no manual tuning.
The model never sees the two arms directly. It just calls search(query); the plugin decides internally which strategy to run.
Example output