Refactoring Hermes with 1,393 agents
NOUS RESEARCH
Hermes Agent cleaned up about a million lines of its own code with 1,393 subagents. It saved months of manual refactoring and exposed some bugs the tests had missed.
Based on reporting by NOUS RESEARCH — read the original for the full story.
Summary, retelling and take written by AI under human oversight; images are AI-generated illustrations. How we work · Report an error
Teknium’s team finally sent Hermes Agent after a job they had been putting off for months: a brutal cleanup of their open-source codebase. By September, the repository had more than a million lines of non-test Python, and one file alone, gateway/run.py, had swollen to 34,847 lines. The goal was simple to say and hard to staff: shrink the mess, cut the bloat, and make the code easier to understand without stealing engineers from features and bug fixes.
On September 2, Teknium asked Hermes to do the refactor. The main run went for about nineteen active hours, launched 1,393 subagents, and peaked at 218 running at once. After a restart, a continuation session, and two rounds of community review and fixes, the PR landed on September 4. The result was a 34.4% reduction in non-test Python source. The estimated model cost was about $19,300 for the main run, or roughly $25,000 with follow-up sessions, before human review time.
The work was not just a giant search-and-replace. Hermes split gateway/run.py into separate modules for message dispatch, streaming, RPC, and lifecycle handling. Elsewhere, it merged duplicate helpers and replaced long if/elif chains with dispatch tables. Reviewers also caught public names that had been removed even though outside plugins could still import them, and an automated rewrite of suppress() calls changed exception handling at roughly 65 sites. Those were real regressions that existing tests had missed.
The team measured the before-and-after shape of the codebase and the effect on lookups. Non-test Python lines fell from 1,063,826 to 698,363. Files over 5,000 lines dropped from 376 to 6, and functions over 300 lines fell from 192 to 22. The longest if/elif chain went from 92 branches to 9, and gateway/run.py shrank from 34,847 lines to 5,512.
There was a catch, though. Splitting files made the code easier to read, but it also increased module count and import dependencies, and some entry points took longer to import. Hermes also spent worker time badly at first, starting roughly thirty copies of Pyright and burning about 8.7 GB, which led to a later fix so worktrees could share one server. The broader lesson is less about magic and more about leverage: the agent learned from the refactor, updated its skills, and carried those rules into future work.
My take — AI-written commentary, not fact-checked reporting
This is the rare AI refactor story that feels useful instead of ceremonial. The real win isn’t that Hermes wrote code; it’s that it absorbed the cleanup rules and turned them into reusable procedure. That’s the pattern worth watching: agents get interesting when they start reducing the boring work humans keep postponing.
Read more about this at: NOUS RESEARCH
Related stories
DeployHermes
Product Hunt · 3 weeks ago ·
33
Nous Research Ships Bot Mode for Hermes Agent, Turning Agent Profiles Into a Roster of Named Bots
MarkTechPost · 1 month ago ·
33