Then I ran it against a 20-line bandit and the bandit won.
tl;dr: I built a tool router for an AI agent that learns like an ant colony: tools that pay off get “pheromone”, unused ones fade. It learns the right route from rewards alone and reaches 81% of the best possible score on 60 real recorded API calls. But in a comparison I committed to before running it, a plain ε-greedy bandit matched or beat it in 2 of 3 settings, including the real one.
This project started with a movie. In Signal One, one of the characters says: “We learn a lot from ants. We study them to solve traffic problems… all sorts of things.” I couldn’t let that line go.
An ant colony has no planner. No ant knows where the food is or which path is shortest. Foragers wander, and when one finds food it lays a chemical trail on the way back. Other ants tend to follow stronger trails, and they reinforce them when the trail pays off. Trails that stop paying off evaporate. Good routes come out of that loop without anyone choosing them.
If we study ants to solve traffic problems, why not to route an AI agent’s tools? That question sent me down the rabbit hole. An agent answering a question usually chains a few tools together: search, then scrape; retrieve, then summarize. Which tools it uses is mostly decided from their descriptions, and descriptions are just claims. A tool can say it’s great at something it’s bad at. A tool that worked yesterday can break today.
So I asked a narrow question: can an agent learn its tool routes the way a colony learns its paths, from nothing but the rewards it actually gets?
I built the router before reading the ant colony optimization (ACO) literature, on purpose. This post covers what it learned, what happened when I broke one of its tools, and what happened when I finally compared it to the boring baseline I should have tried first.
The router: every query is an ant
Searchy sends each query through two steps: pick a tool to fetch information, then a tool to process it. At each step, a tool’s chance of being picked depends on two numbers:
- τ (pheromone): how well this tool has actually paid off so far. It starts equal for every tool and only changes from observed rewards.
- η (the tool’s ad): how good the tool claims to be at this kind of query. Ads can lie.
The pick is weighted by τ × η², and 10% of picks are random, so nothing is ever completely ruled out. After each query, the tools it used get pheromone in proportion to the reward (answer quality minus cost and latency). Every 10 queries, all pheromone evaporates a little. That’s the whole algorithm, and I didn’t tune any of its settings.

Each tool flies a flag as tall as its ad (η) next to a mound as tall as the pheromone it has earned (τ). Real traces from the router on the synthetic stream.
To check that it could see through bad ads, I built a world with six simulated tools and planted two lies:
knowledge_baseoversells itself at summarizing (claims 0.90, really 0.50).calculatorundersells itself at math (claims 0.30, really 0.98, the best math tool there is).
The good part: it adapts
The first result looked like the story I wanted. Over 100 queries the router beat the policy that simply trusts the ads (17.70 vs 16.88 cumulative reward, winning 4 of 5 seeds).
Then I broke something. Halfway through the stream, at query 50, I made web_search almost useless (quality down to 0.05, latency tripled) without changing its ad. The trust-the-ads policy kept using it and its average reward went negative (−0.129 per query after the break). The router kept its average positive (+0.035) by moving traffic elsewhere.
Traffic share per tool and reward around the sabotage at query 50.
Next I wanted something less made up than tools I had invented myself. I wrote 60 real questions (docs lookups, news, product data, facts) and an answer rule for each. Each route through a real web-scraping API (fetch with /search or /map, output as markdown or json) was called once per question: 240 real API calls, recorded once and replayed in every experiment. Grading is a fixed answer key, with no LLM judge.
On that real data, over 30 seeds:
| Policy | Cumulative reward | % of best possible |
|---|---|---|
| Oracle (knows the best route per query) | 49.95 | 100% |
Right fixed route (/search with markdown) | 47.11 | 94% |
| Pheromone router | 40.49 | 81% |
| Trust the tool descriptions | 35.23 | 71% |
| Random | 28.06 | 56% |
Wrong fixed route (/map with json) | 9.08 | 18% |
The router beat the wrong fixed route on all 30 seeds. Without ever being told the answer, its pheromone settled on the best route: /search ended with τ 29.5 against 7.7 for /map, and markdown 34.2 against 3.0 for json.
It also lost to the right fixed route on all 30 seeds. One route was best for 52 of the 60 questions, and on a stream that short, 10% random exploration costs more than learning gains back. I could live with that. The claim still holds up: if you don’t know in advance which route is right, the router gets you most of the way there on its own.
At this point I could have written a pretty nice blog post.
The boring baseline
There was a question I’d been avoiding. With two steps and two or three choices each, a “route” is just one of a handful of options. That makes it a multi-armed bandit problem, and bandits are among the most studied problems in the field. The simplest bandit, ε-greedy, keeps a running average reward for each option, picks the best one 90% of the time, and picks at random the other 10%. You can write it in about 20 lines.
So before running anything, I committed the comparison and the rule for passing: the router has to beat the best of four textbook bandits (ε-greedy, UCB1, Thompson sampling, sliding-window UCB) in at least two of three worlds. 30 seeds each.
| World | Router | Best bandit (ε-greedy) | Result |
|---|---|---|---|
| Synthetic (lying ads) | 18.18 | 14.18 | Router wins (p = 1e-6) |
| Sabotage | 11.69 | 13.09 | No real difference (p = 0.2) |
| Real recorded calls | 40.49 | 43.20 | Bandit wins (p = 2e-6, router better on 3/30 seeds) |
The router failed its own test: it won in 1 world out of 3.
The one win also isn’t what it looks like. The bandits never get to see the tool ads; they learn from rewards only. The trust-the-ads policy, which never learns anything, scores 16.67 in the synthetic world and beats every bandit too. So most of the router’s win there comes from the ads being roughly right, not from the pheromone.

Cumulative regret against the oracle (lower is better), mean over 30 seeds, in all three worlds. Click the chart to see it full size.
Where the colony breaks
Comparing the two side by side showed three specific failures.
1. It locks in early. In the synthetic world, the learning curve is flat from about query 5. The first route that pays off gets pheromone, gets picked more, gets more pheromone, and the colony stops looking. Ant colony researchers named this stagnation decades ago, and fixes like MAX–MIN Ant System’s pheromone bounds were designed against it.
2. It can’t let go. After the sabotage, over the last 20 queries the broken tool still got 22% of the router’s traffic but only 3% of ε-greedy’s. The reason is in two of my own design choices. A bad outcome deposits zero pheromone rather than removing any, so only evaporation can bring a trail down, and my evaporation is slow. A bandit’s average drops the moment bad news arrives. Pheromone mostly listens to good news.

After web_search breaks, each pad’s pillar shows its share of recent traffic: the router (anthill, back) keeps sending 22% to the broken tool; the bandit (lever, front) drops it to 3%.
I tried the textbook fix, MAX–MIN pheromone bounds plus restarts. Recovery went from 1 of 5 seeds to 2 of 5, but the broken tool’s traffic share got worse, because the lower bound keeps every tool reachable by design. It’s a trade-off, not a fix.
3. One shared trail can’t fix a lie about one kind of query. Both planted lies survived 100 queries:
- The underselling
calculatorwas almost never tried, only 1–2 times out of 25 math queries, always by random exploration. Those few deposits couldn’t keep up with evaporation, so its pheromone ended below where it started. At the end it got 2% of math traffic despite being the best math tool. Experience can only correct claims about tools that get tried. - The overselling
knowledge_basereally is good at factual questions, so it earned plenty of pheromone there. Because there’s one pheromone table for every query type, its fake summarization skill rode on that trail and it ended up with 47% of summarization traffic, while a tool that summarizes much better (0.75 vs 0.50) sat idle.
What this does not show
- Scale. Routes here have two steps and at most nine options, and streams are 60–100 queries. This says nothing about ACO in general.
- I built the synthetic world, including which ads lie. It shows how things fail, not how often real tools lie.
- One real API, one recording session. Seed-to-seed variation comes only from the policies’ own randomness.
- Nothing was tuned, for the router or the bandits. Other settings (faster evaporation, a weaker η) might change the router’s numbers. A fair tuned comparison would give every method the same tuning budget.
- The early synthetic and sabotage runs used 5 seeds; the bandit comparison and the real-data results use 30.
What I take from this
On short tool routes, a pheromone router is a weak bandit: a softmax-like preference that updates slowly and ignores bad news. ACO’s real strengths are building long solutions one piece at a time and letting many agents share one trail. A two-step route gives neither of them anything to work with.
I also checked whether the problem was my ACO code. The same core, pointed at classic traveling-salesman benchmarks, gets within 0.0%, 0.0% and 1.1% of the known optimal tours (with 2-opt local search, which honestly does most of that work). The implementation is fine. The match between algorithm and problem isn’t.
So the questions I actually care about now are the ones where ACO could earn its complexity:
- Long tool chains (4–8 steps), where building a route step by step should finally matter.
- Many agents sharing one pheromone table, the thing real colonies do, and that a single bandit can’t.
Those are the next experiments. And the lesson I’ll carry into every one of them: commit to the baseline and the pass rule before you run anything. Without that, this would’ve been a post about an ant colony that learns to route around broken tools, and it would have been true and misleading at the same time.
Try it
Everything runs on a laptop CPU, deterministically, with no API key. The real calls are recorded and committed.
git clone https://github.com/pyjeebz/searchy && cd searchy
uv sync
uv run python -m searchy.live --demo # a 5-query walkthrough on the recorded real calls
uv run python -m searchy.e1_experiment experiments/configs/e1-bandits.yaml # the bandit showdown The full write-up, with the protocol, statistics, and every anomaly I logged along the way, is in the paper: Can Ant Colony Optimization Route an AI Agent’s Tools?