Rui: a hundred agents in 6 MB


Updated
divyanshgolyan.com/posts/hundred-agents/

I believe most agents will soon be started by other agents. A few weeks ago, OpenAI pointed about 10,000 agents at the Navier–Stokes Millennium Prize problem and solved it. I expect runs like that to become routine, with models trained to work alongside hundreds, if not thousands, of other agents.

That makes memory a scarce resource on a machine running agents. Most of the time an agent is just waiting for the model, so what matters is what a waiting agent costs. Today that cost is high. 100 waiting agents take 168 MB in Codex app-server and 187 MB in pi. Jarred Sumner’s Bun AOT build of Claude Code takes 267 MB with 67 active subagents. At the rate Codex app-server and pi add per agent, 10,000 would need about 13 GB and 5.5 GB.

In Rui, my agent harness, the same 100 waiting agents cost 6 MB, and 10,000 need about 30 MB.रुई · cotton. Light, and you can pack a lot of it.

रुई · cotton. Light, and you can pack a lot of it.
Memory with 100 waiting agents: Rui 6 MB, Codex app-server 168 MB, pi 187 MB, fx 633 MB, OpenCode 702 MB.
Rui holds 100 waiting agents in 6 MB. The next lightest harness needs 168 MB, about 28 times as much.

A fleet pays for memory in three ways

A fleet costs the harness’s starting memory, plus what each waiting agent adds times the number of agents. Over a day of my own work in Rui, about 80% of turn time went to waiting on the model.

Where turn time went, summed over 1,904 turns, to scale: waiting on the model 80%, Bash alone 15%, everything else 5%.
Where turn time went, to scale.
Numbers
Stage Share Timing
Waiting on the model 80% median 9.7 s per model call
Bash alone, no model call open 15% median under 1 s, 90th percentile 8 s
Everything else 5%

1,904 turns, 25,395 model calls, 16,255 Bash commands, 112 hours in total.

So an agent mostly holds a conversation open while the model thinks. A harness can make a fleet expensive in three ways.

The first is keeping each agent’s state in memory while it waits. Some harnesses run every agent in one process. Codex app-server adds about 1.3 MB for each agent, and pi about 560 KB.

The second is giving every agent its own process. Each process brings its own copy of everything: a heap, threads, a connection to the model. fx does this, at about 6.3 MB per agent. Many harnesses do, because they were built for one person driving one agent in a terminal.

The third is loading a heavy runtime before any agent starts. OpenCode’s server takes 333 MB before its first agent.

Here is how the five harnesses compare as agents are added.

Memory at 0, 1, 10 and 100 waiting agents, on linear scales: Rui 5.2 MB, 6 MB, 5.9 MB, 6 MB; Codex app-server 19.4 MB, 27.9 MB, 47.1 MB, 168 MB; pi 108 MB, 126 MB, 137 MB, 187 MB; fx 0 MB, 6 MB, 63.4 MB, 633 MB; OpenCode 333 MB, 539 MB, 681 MB, 702 MB.
Where a line starts is what a harness costs before any agent. How steeply it climbs is what each agent adds. Rui starts at 5.2 MB, and its first 100 agents add less than 1 MB, nearly all of it with the first one. Past 100, each agent adds about 1 KB.
Numbers
Harness 0 agents 1 10 100 Added per agent
Rui 5.2 MB 6.0 MB 5.9 MB 6.0 MB about 1 KB
Codex app-server 19.4 MB 27.9 MB 47.1 MB 167.6 MB 1,371 KB
pi 108.0 MB 125.7 MB 137.3 MB 186.5 MB 559 KB
fx 0 MB 6.0 MB 63.4 MB 632.6 MB 6,476 KB
OpenCode 333.3 MB 538.9 MB 681.1 MB 702.1 MB 239 KB

Physical footprint on a Mac, median of 3 runs. Added per agent is the growth from 10 to 100 agents, divided by 90. For Rui that growth is too small to measure, so its figure comes from 100 to 2,000 agents. OpenCode’s runs vary by more than its 100 agents add, so read its figure loosely. fx starts no process until its first agent.

One process runs every agent’s loop

Simplified, an agent is a loop. It sends the user’s input to a model API, then shows the answer to the user or acts on it. It repeats until the environment, the user or the model stops it. It needs little memory: a network stack, a storage stack and a little state for coordination.

Every agent runs the same loop, so one process can run it for all of them, holding their state and sharing one network stack.

In Rui that process is the Host. Rui is a compiled Zig program, so there is no runtime to load first, and the Host starts at 5.2 MB. It loads its network stack and SQLite once. Many agents’ requests share one connection, as many as the server allows, and one event loop watches them all, so no agent needs its own thread.

A waiting agent’s request is one stream on a shared connection, and everything else about it is rows in SQLite, so memory doesn’t grow with conversation length.

Left: 100 agents as 100 separate processes, each with its own heap, threads and connection (fx: 1,000 threads). Right: one Host process with one heap and shared connections, holding the 100 agents as rows in SQLite (Rui: 5 threads).
With a process per agent, 100 agents mean 100 heaps, sets of threads and connections. The Host has one heap and 5 threads, and its requests share connections.

One turn costs about 1 KB

Here is one turn for one agent, fleet/42.

Past the first 100 agents, each waiting agent adds about 1 KB. The first one costs about 0.8 MB, and I haven’t broken that start-up cost down. The Host also reserves its slots when it starts, at about 0.8 KB each, so going from 100 slots to 10,000 adds about 8 MB before any agent runs.

What one process costs you

Running every agent in one process has two costs: a shared limit on running work, and a single point of failure.

The limit is the number of slots. Say you start Rui with the default 100 slots. A slot holds one piece of running work, either a model call or a Bash command, so up to 100 agents can be working at once. Agent 101 waits as a row until a slot frees up. It has no request built and costs no memory while it waits. Past the point where the provider rate-limits you, more slots only buy more retries.

If the Host crashes, every agent stops with it. The agents lose no work, because the Host writes every message and result to SQLite before it acts on them. When the Host restarts, it picks up from what’s in SQLite.

Start a fleet

Rui runs on Apple Silicon Macs and x86-64 Linux. Install Rui:

curl -fsSL https://ruicode.com/install | sh

Then open a new terminal, run rui in your project, sign in with ChatGPT or an OpenAI-compatible API key, and ask for a fleet:

Split this repo into areas, start one agent per area to look for bugs, and give me one list of what they find.

To start agents from your own TypeScript program instead, install the client from npm with npm install ruicode.

How I measured

I measured memory on 26 November 2026 on one MacBook Pro (M1 Pro, 16 GB, macOS 15.8.3). Each harness talked to a fake model that accepts every request and never answers, so every agent stays waiting on the model with its request open. Rui talked to it over TLS and HTTP/2, the others over plain HTTP, which costs Rui a little extra. Rui’s requests carried one tool, Bash, and the others carried their default tools, so part of their memory pays for features Rui doesn’t have. With all its built-in tools, 100 agents took Rui 7 MB. Rui’s figures are for the Host, the process that runs the agents; an open terminal view adds roughly 9 to 12 MB. Rui is release 0.97.1. The others were Codex app-server 0.172.0, pi 1.6.1 (its SDK, every agent in one Node process), fx 0.0.18 and OpenCode 1.19.6. I count the physical footprint, the number Activity Monitor shows as Memory, summed over every process a harness starts, 10 seconds after all agents are waiting; 1 MB is 1,024 KB. I don’t use RSS, because it counts shared program code once per process and inflates any harness that runs a process per agent. Rui’s 1 KB per agent is the growth from 100 to 2,000 agents, median of 5 runs with 2,100 slots; macOS’s count of the Host’s live heap memory grows by about the same. For 10,000 agents, Rui needs 10,000 slots. In a single run with that many, 9,818 agents waiting at once took 29 MB. Not all 10,000 waited at once, because the earliest requests started closing about five minutes in. The turn timings come from my own work in Rui, nearly all of it on 24 November 2026. Many turns ran at the same time, so the 112 hours are summed across them. I left out one turn that spent 20.5 hours retrying after rate limits.