Rewriting Prime Agent in Rust
TL;DR Highlight
An agent swarm ported its own TypeScript to Rust, cutting time-to-input about 14x.
Who Should Read
A backend or platform developer who wants to automate large code migrations with coding agents or multi-agent setups
Core Mechanics
- 2,000+ agents rewrote it in two weeks
- Prime Agent rewrote itself from TypeScript to Rust.
- It ran across 10,000+ Prime Sandboxes and used over 200B tokens from Prime Inference's GLM-5.3 endpoint.
- Humans only built the verification
- They built four parity checks: TUI, harness, protocol and feature.
- Each check gave agents an objective way to measure progress and catch regressions before merge.
- Four agents handled every task
- The Planner writes the spec and verifier, and the Implementer writes Rust in a dedicated worktree.
- The Reviewer attacks the PR using a different model and context, and the Verifier runs checks in a fresh sandbox.
- Generation and verification are separate because an agent that writes code is biased when judging it.
- Hillclimbing ran three days with no numeric target
- They built a benchmark harness and told agents to improve speed and resources without breaking parity.
- A fixed threshold tends to become a stopping point, so they left it out.
- The loop logged 144+ experiment and audit records and merged 69+ valid changes.
- Cold start went from 736.1ms to 51.9ms
- Input-ready latency is 14.18x faster than the TS version, and large-session memory is 4.76x smaller.
- Installed size dropped from 172.1MB to 59.6MB, 2.89x smaller.
- Three kinds of change drove most gains
- They moved work off the startup and render paths.
- They replaced polling loops with event-driven waits.
- They released memory as soon as large sessions finished loading.
Community Reactions
- Questions about the four-agent pipeline
- One commenter wanted to know how the Planner → Implementer → Reviewer → Verifier flow was actually implemented.
- Another asked how it could apply to greenfield coding rather than language copies or performance work.
- Token cost transparency
- A commenter said a 200B total token number does not help gauge cost.
- They wanted a split into input (cache hit), input (cache miss) and output.
- Single binary advantage
- One commenter said Rust rewrites get criticism, but a single copyable binary helps a lot when working with sandboxes.
- Question on Prime Agent's edge
- A commenter asked whether it can do anything that regular harnesses with a memory plugin cannot.
How to Apply
- Add a differential test to one CLI today
- Pick a CLI you plan to port or refactor and write a script that diffs old and new outputs on the same inputs.
- Give that diff to the agent as its pass criterion.
- Separate writer and reviewer agents
- Run the code-writing agent and the review agent on different models and contexts.
- Tell the reviewer prompt explicitly to look for reasons the change is wrong.
- Drop numeric targets from perf loops
- Profile first to build a backlog of hypotheses, then benchmark before and after in alternating order on the same environment.
- Set the goal as continued improvement without breaking parity, not a number.
Try It
# Paste into Claude Code or ChatGPT (simplified version of the article's reviewer agent)
You are an adversarial code reviewer. Find reasons the change below is wrong. Do not trust the implementer's explanation, look only at the code.
[Original behavior spec]
{{original behavior description or tests}}
[Change diff]
{{PR diff}}
Check the following:
1. Does any behavior differ from the original?
2. Does output differ where it should be identical?
3. Is there a regression on the model-facing interface?
List problems by severity, or answer pass with reasons if there are none.
Next step: run this prompt on a different model from the one that wrote the code and compare the results.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques