Blog · Thinking

The queen does not give orders: what ant colonies teach us about building with AI agents

By Kalpak Kale ·

A line of ants carrying leaf pieces along a branch
Photo by Kirsten C. Staring on Pexels

Near my home there is a line of black ants that crosses the compound wall every evening. I have watched it for years without thinking about it. This month, while debugging a swarm of coding agents that kept stepping on each other's work, I started thinking about it a lot.

A mature leafcutter colony runs to several million workers and has no manager (Hölldobler and Wilson, 1990). The queen does not plan, does not assign tasks, does not review anyone's work. She lays eggs. Everything else, from finding food to building bridges out of their own bodies, happens without a single ant knowing the whole picture. And it has worked for well over a hundred million years (Moreau et al., 2006).

In one line: Ant colonies solve routing, scheduling, consensus and load-sharing with no central controller, and the mechanisms they use, each documented in the studies cited below, translate almost directly into rules for running teams of AI agents.

First, the uncomfortable correction: the queen is not the orchestrator

Most diagrams of multi-agent AI systems have an orchestrator at the top handing out subtasks, the way we imagine a queen ruling her colony. Ant biologists gave up that picture decades ago. Deborah Gordon at Stanford has spent thirty years showing that harvester ants decide what to do from the rate at which they bump into other ants, and what those ants smell like, not from any instruction (Gordon, Paul and Thorpe, 1993), (Gordon, 2010). The queen's only job is to be the reason the colony exists.

That maps neatly onto how I actually use agents. I am the queen: I set the purpose, I write the brief, I define what "done" means, and then I get out of the way. The moment I try to be the orchestrator as well, dictating every step to every agent, the whole thing slows down to the speed of my attention. The ants' lesson is that the person who gives the colony its reason should not also be its traffic controller.

Rule 1: communicate through the environment, not through messages

Ants rarely talk to each other directly. A forager who finds food lays a chemical trail on the way home, and other ants follow the trail, laying more chemical as they go. The information lives in the ground, not in any ant. Biologists call this stigmergy, a term coined for termites in 1959 and since applied across social insects (Theraulaz and Bonabeau, 1999).

In an agent system the ground is the shared workspace: the repository, the task board, the test results, the scratch files. When I stopped routing everything through a central chat and instead had each agent leave its findings in a shared notes file that every other agent reads before starting, the duplicated work fell away. The trail was in the environment. Nobody had to be told.

Rule 2: let good paths get stronger and let every path fade

In 1989 Jean-Louis Deneubourg's group in Brussels gave Argentine ants a bridge with two branches to the same food, one twice as long as the other. Within minutes almost all traffic was on the short branch. No ant measured anything. Ants on the short path simply returned sooner, so their trail was reinforced sooner, so more ants chose it (Goss et al., 1989). Marco Dorigo turned this into Ant Colony Optimization in the early 1990s (Dorigo, Maniezzo and Colorni, 1996), and it is still used for vehicle routing and job scheduling (Dorigo and Stützle, 2004).

The part people forget is that pheromone evaporates, and the evaporation rate is a core parameter of every ant algorithm for exactly that reason (Dorigo and Stützle, 2004). If trails did not fade, the first path found would be the path forever, however bad. In agent systems the equivalent is a success score on each route, tool or prompt that decays with time. A tool that worked last month but fails now should lose its pull. Without evaporation you get lock-in; with it you get a system that keeps re-discovering the current best route.

Rule 3: assign work by threshold, not by dispatcher

Ants do not have fixed jobs handed out from above. The fixed-threshold model, tested on real colonies, says each ant has a threshold for each kind of signal (Bonabeau, Theraulaz and Deneubourg, 1996). When the pile of uncollected larvae grows past an ant's threshold for brood care, that ant starts nursing. When enough ants are nursing, the pile shrinks, the signal drops, and ants with higher thresholds never join. Division of labour emerges from a population of slightly different thresholds reacting to a shared signal.

I now run coding agents the same way. A test-writer agent watches for untested functions, a reviewer watches for unreviewed diffs, a documentation agent watches for public functions without a docstring. Nobody assigns the work; the backlog is the signal. The only thing I tune is the threshold: how large the pile must be before a given agent starts.

Rule 4: decide by quorum, not by a single judge

When a Temnothorax colony needs a new nest, scouts explore candidates independently. A scout that likes a site returns and leads one other ant to it. Once the number of ants at a site crosses a quorum, the scouts switch from slow one-at-a-time leading to simply carrying nestmates there in bulk. Stephen Pratt, Nigel Franks and colleagues showed in 2002 that this lets a colony choose the better of two sites without any ant having visited both (Pratt et al., 2002).

The habit I took from this: when an agent produces an answer that matters, I do not rely on one judge agent. I have three independent reviewers look at it, and the result only moves forward when enough of them agree. Independent assessment plus a quorum beats a single clever evaluator, because the single evaluator shares the author's blind spots.

Rule 5: when carrying something heavy, most follow and one briefly steers

Longhorn crazy ants carry food items far heavier than any one of them. In 2015 Ofer Feinerman's group at the Weizmann Institute filmed how. The group mostly conforms, pulling the way the majority already pulls, which gives strength. Every so often a newly arrived ant that knows where the nest is joins, steers for a short while, then falls in line with the group (Gelblum et al., 2015). Fresh knowledge gets a brief steering role and then surrenders it.

This is the best description I know of a good handover between agents. When one agent has fresh context, a failing test it just saw, a user comment it just read, it should get to steer briefly and then merge back into the shared plan. What fails is the opposite: every agent steering all the time, which is the swarm of agents I was debugging when I started watching the ants.

Rule 6: build bridges, and tear them down when the cost rises

Army ants build living bridges out of their own bodies to shorten the foraging path. In 2015 Chris Reid's team, working in Panama, showed the bridges are not built to maximise the shortcut. The ants stop extending a bridge when it locks up too many workers who would otherwise be foraging (Reid et al., 2015). The colony is trading travel time against labour, continuously, with no accountant.

Agent systems need the same accounting. A planning step, a verification loop or a search phase is a bridge: it shortens the path but it costs tokens and time. The rule I now apply is to measure what each extra step saves against what it spends, and to pull agents off a bridge the moment the saving drops below the cost. Most of my runaway bills came from bridges nobody dismantled.

Rule 7: never jam, and scale by return rate

Audrey Dussutour's lab showed in 2019 that Argentine ants on a crowded trail never form a traffic jam, even at eighty percent occupancy, because ants simply stop entering the trail when it is busy (Poissonnier et al., 2019). Gordon's harvester ants go further: the colony sends out new foragers at a rate set by how fast foragers are returning with food, which Balaji Prabhakar recognised as the same algorithm TCP uses to manage internet congestion (Prabhakar, Dektar and Gordon, 2012). Stanford's write-up called it the anternet (Stanford News, 2012).

For agents: spawn by return rate. If verified results are coming back quickly, allow more parallel agents; if they slow down or start failing, stop adding agents rather than queueing more work onto a jam. Back-pressure is not a nice-to-have in a swarm. The ants have it built in.

Rule 8: keep a reserve, and watch for the death spiral

Two cautionary facts. Daniel Charbonneau and Anna Dornhaus found that a large share of workers, around forty percent in the colonies they tracked, are inactive at any moment, and it is largely the same individuals (Charbonneau and Dornhaus, 2015): a standing reserve that fills gaps when active workers are lost. Agent systems that run every worker at full capacity have no slack to absorb a failure, and they fail at the worst moment.

And then the ant mill. When army ants lose the trail, they can start following each other in a circle. The circle reinforces itself with pheromone, and the ants march until they die; Theodore Schneirla documented one such mill in 1944 (Schneirla, 1944). Any system where the only signal is "others are doing it" can spiral. The protection is the same evaporation from rule two plus a hard timeout: a loop that has not produced a verified result in a set number of steps gets broken from outside, whatever the agents inside it believe.

Why the strength is real, and what it means for size

Ants carry many times their body weight, and in tests at Ohio State the neck joint of the Allegheny mound ant withstood loads of up to five thousand times the ant's weight (Nguyen, Lilly and Castro, 2014). There is no miracle in it. Strength scales with the cross-section of a muscle, which grows with the square of size, while weight grows with the cube, a point J. B. S. Haldane made in 1926 (Haldane, 1926). Shrink an animal and its strength-to-weight ratio climbs. A human the size of an ant would lift cars too.

The same square-cube logic applies to agents. A small agent with a narrow brief and a short context lifts far more than its share, because almost everything it holds is relevant. A giant agent with the whole project in its context carries mostly dead weight. The colony's strength comes from many small, specialised, disposable units, not from one large one.

The colony I am building now

Here is how the rules landed in practice. The user or developer is the queen: they give the system its purpose, its constraints and its definition of done, and nothing else. The shared workspace is the ground: every agent reads it before acting and writes to it after. Routes and tools carry success scores that decay. Agents pick up work by threshold from the backlog, not from a dispatcher. Anything important passes a quorum of independent reviewers. Fresh context gets to steer briefly, then conforms. Every expensive step is a bridge with a cost check. New agents spawn by return rate, not by ambition. A reserve stays idle on purpose, and every loop has a timeout.

None of this needs a new framework. It needs the discipline to stop playing orchestrator and to start designing the ground the agents walk on. The ants on my compound wall have been showing me that every evening. It took a broken swarm to make me look.

Sources

  • Hölldobler and Wilson, "The Ants", Harvard University Press, 1990: https://www.hup.harvard.edu/books/9780674040755
  • Moreau, Bell, Vila, Archibald and Pierce, "Phylogeny of the ants: diversification in the age of angiosperms", Science, 2006: https://doi.org/10.1126/science.1124891
  • Gordon, Paul and Thorpe, "What is the function of encounter patterns in ant colonies?", Animal Behaviour, 1993: https://doi.org/10.1006/anbe.1993.1127
  • Gordon, "Ant Encounters: Interaction Networks and Colony Behavior", Princeton University Press, 2010: https://press.princeton.edu/books/paperback/9780691138794/ant-encounters
  • Theraulaz and Bonabeau, "A brief history of stigmergy", Artificial Life, 1999: https://doi.org/10.1162/106454699568700
  • Goss, Aron, Deneubourg and Pasteels, "Self-organized shortcuts in the Argentine ant", Naturwissenschaften, 1989: https://doi.org/10.1007/BF00462870
  • Dorigo, Maniezzo and Colorni, "Ant System: optimization by a colony of cooperating agents", IEEE Transactions on Systems, Man and Cybernetics, 1996: https://doi.org/10.1109/3477.484436
  • Dorigo and Stützle, "Ant Colony Optimization", MIT Press, 2004: https://mitpress.mit.edu/9780262042192/ant-colony-optimization/
  • Bonabeau, Theraulaz and Deneubourg, "Quantitative study of the fixed threshold model for the regulation of division of labour in insect societies", Proceedings of the Royal Society B, 1996: https://doi.org/10.1098/rspb.1996.0229
  • Pratt, Mallon, Sumpter and Franks, "Quorum sensing, recruitment, and collective decision-making during colony emigration by the ant Leptothorax albipennis", Behavioral Ecology and Sociobiology, 2002: https://doi.org/10.1007/s00265-002-0487-x
  • Gelblum, Pinkoviezky, Fonio, Ghosh, Gov and Feinerman, "Ant groups optimally amplify the effect of transiently informed individuals", Nature Communications, 2015: https://doi.org/10.1038/ncomms8729
  • Reid, Lutz, Powell, Kao, Couzin and Garnier, "Army ants dynamically adjust living bridges in response to a cost-benefit trade-off", PNAS, 2015: https://doi.org/10.1073/pnas.1512241112
  • Poissonnier, Motsch, Gautrais, Buhl and Dussutour, "Experimental investigation of ant traffic under crowding conditions", eLife, 2019: https://doi.org/10.7554/eLife.48945
  • Prabhakar, Dektar and Gordon, "The regulation of ant colony foraging activity without spatial information", PLoS Computational Biology, 2012: https://doi.org/10.1371/journal.pcbi.1002670
  • Stanford News, "Stanford biologist, computer scientist team up to discover the 'anternet'", 2012 (archived copy): https://web.archive.org/web/20131225121139/http://news.stanford.edu/news/2012/august/ants-mimic-internet-082312.html
  • Charbonneau and Dornhaus, "Workers 'specialized' on inactivity: behavioral consistency of inactive workers and their role in task allocation", Behavioral Ecology and Sociobiology, 2015: https://doi.org/10.1007/s00265-015-1958-1
  • Schneirla, "A unique case of circular milling in ants, considered in relation to trail following and the general problem of orientation", American Museum Novitates, 1944: https://digitallibrary.amnh.org/handle/2246/3733
  • Nguyen, Lilly and Castro, "The exoskeletal structure and tensile loading behavior of an ant neck joint", Journal of Biomechanics, 2014: https://doi.org/10.1016/j.jbiomech.2013.10.053
  • Haldane, "On Being the Right Size", Harper's Magazine, 1926 (summary and text references): https://en.wikipedia.org/wiki/On_Being_the_Right_Size