Grok Build with TypeSafe Jev in front of tool selection. The command is nitro.
Once per turn, before the first model call, Nitro asks Jev one question per tool: "will finishing this request need this tool at any step?" All the questions go in one request and come back in about 350 ms. The tools Jev says no to are left out of the chat model's request, and that shorter list is held for every step of the turn. The chat model still writes every command, path, and patch. Jev only decides which tools are in play.
On a coding task Jev keeps 8 of Grok Build's 25 tools. That cuts the tool schemas in every request from about 11K tokens to about 2.9K.
Same model (grok-4.6), same prompts, same outputs, stock grok 1.0.36 against nitro. Two runs per cell, means shown. Every run produced the files asked for and a passing test suite.
| Task | Cost | Total tokens | Uncached input | Wall clock |
|---|---|---|---|---|
| Calculator, short prompt | 14% cheaper | 34% fewer | about the same | tie |
| Calculator, longer prompt | 40% cheaper | 43% fewer | 43% fewer | tie |
| Todo app (API, CLI, store, 3 test files) | 22% cheaper | 23% fewer | 44% fewer | tie |
| Task | Stock grok | Nitro |
|---|---|---|
| Calculator, short prompt | $0.061, 57.4K tokens | $0.052, 37.7K tokens |
| Calculator, longer prompt | $0.062, 58.3K tokens | $0.037, 33.4K tokens |
| Todo app | $0.216, 116.0K tokens | $0.168, 89.6K tokens |
The first version of this harness asked Jev before every model step and was 70% more expensive than stock. Changing the tool list between steps breaks the chat model's prompt cache. The whole story, including how that was found and fixed, is in research.md. The design is in TYPESAFE.md.
You need a Rust toolchain, a Grok Build login or XAI_API_KEY, and a TypeSafe key from console.typesafe.ai (or an OpenRouter key).
git clone https://github.com/daniel-farina/nitro
cd nitro
./install.sh
nitroinstall.sh builds the release binary and installs it like the Grok installer does: the binary goes in ~/.grok/downloads, linked from ~/.grok/bin/nitro, which is already on PATH next to grok. It does not touch the grok command. Re-run it after you pull. NITRO_DEBUG=1 ./install.sh installs a debug build.
The first interactive launch asks whether to enable TypeSafe and for a provider and key. The key is saved mode 0600 at $GROK_HOME/typesafe.json (normally ~/.grok/typesafe.json). Saying no is remembered; delete the file or set TYPESAFE_REASK=1 to be asked again.
| Provider | Key | Endpoint |
|---|---|---|
| TypeSafe | console.typesafe.ai | POST https://api.typesafe.ai/v1/systemone (jev-latest) |
| OpenRouter | openrouter.ai/keys | POST https://openrouter.ai/api/alpha/decisions (typesafe/jev-latest) |
Headless runs (nitro -p, CI) do not prompt. They use the saved file, or TYPESAFE_API_KEY, or OPENROUTER_API_KEY with TYPESAFE_PROVIDER=openrouter. GROK_TYPESAFE=off disables routing for a run.
Inside the TUI: /nitro typesafe or /nitro openrouter takes a new key on the next line (that line is not sent to the model). /nitro off turns routing off. A JEV line in the chat shows each decision as it happens.
- One Jev call on the first model step of each turn. State: the user request and the previous assistant reply. Questions: one
noulper tool, with the tool's name and description. - Tools that clear a 0.30 probability stay. The workspace primitives (
read_file,write,search_replace,run_terminal_command,list_dir,grep) always stay. Keepingrun_terminal_commandorspawn_subagentkeeps the tools that read and kill what they start. - The keep-set is re-applied on every later step of the turn without another call, so the tool schemas stay identical and the prompt cache keeps working.
- A failed call, a timeout (4 s), or a response missing an answer leaves the full list in place. Nothing is forced with
tool_choice. The list is never emptied.StructuredOutputis never removed.
| Path | What it is |
|---|---|
grok-build/ |
Grok Build source (Apache-2.0, from xai-org/grok-build) with the Nitro changes applied. Upstream commit in patches/UPSTREAM_COMMIT. |
grok-build/crates/codegen/xai-grok-typesafe/ |
The router: Jev client, config, questions, keep rules, tests. |
grok-build/crates/codegen/xai-grok-shell/src/typesafe_route.rs |
The hook that applies a decision to a turn's tool list. |
patches/nitro-vs-upstream.patch |
The diff against upstream for the files that already existed. New files are listed in patches/NEW_FILES. |
bench/calc/, bench/todo/ |
The two benchmarks: prompt, runner, summarizer. |
docs/typesafe/ |
The TypeSafe docs, downloaded from docs.typesafe.ai/llms.txt. |
research.md |
Everything measured, including the failures. |
TYPESAFE.md |
The design write-up. |
cd bench/calc
./bench.sh grok grok 1 # stock grok
./bench.sh nitro nitro 1 # nitro
./bench.sh nitro nitro 2 "$PWD/prompt-long.txt"
python3 summarize.py # table, per-step cached/uncached input, tool calls
cd ../todo
MAX_TURNS=30 ./bench.sh grok grok 1
MAX_TURNS=30 ./bench.sh nitro nitro 1
python3 summarize.pybench.sh runs the prompt headless with --output-format streaming-json, web search off, and reads the xAI key from the macOS Keychain (service xai-api-key) into an isolated GROK_HOME at ~/.grok-apikey. Edit those two lines for another setup. NITRO_DUMP_REQUESTS=<dir> writes every request body the sampler sends, one file per call, for diffing.
cd grok-build
cargo test -p xai-grok-typesafe
cargo build -p xai-grok-pager-bin --release- Jev cannot write arguments. The chat model still produces every command, path, and patch.
- One Jev call per turn adds about 350 ms to the first step.
- If a task needs a long-tail tool that Jev scored under 0.30, that tool is gone for the turn. The core floor and the dependency rules cover the coding path.
- Two runs per cell is a small sample. The numbers are consistent across three tasks, but they are not a distribution.