Skip to main content
An agent types into one shell, and a machine runs its programs. Without a route, each program goes to the first machine whose captures name it. A route picks by what the line does instead: a quick Python snippet stays on Monty inside Mirage, a training job goes to the GPU, and each agent gets its own container. The agent types the same commands either way. The Multi-machine Terminal example routes each Python command across four machines by the library its code uses.

Route a line

pre_execute places a whole line. Here the jobs under /jobs/ run on a CPU container, the GPU jobs on a GPU container, and everything else on Monty:
route.py
python3 /jobs/gpu/train.py runs in my-gpu, python3 /jobs/train.py in my-box, and cat data.csv | python3 -c "..." stays on Monty. A line that names no machine runs where captures sends it. route_policy answers for every session. To give each agent its own machine, route by the session:
route.py

Route a command

pre_command places one command, so the rest of the line stays where it is: in ls; python3 train.py, only python3 moves. As a profile’s program, it routes that profile’s sessions:
route.py
The Multi-machine Terminal’s route.py also reads the script a command runs, to route python3 train.py by its imports.

In code

route_policy also takes a function, which returns a machine name or nothing:
A policy class returns Route(machine=...) from pre_execute or pre_command, and a caller can name the machine for one line: ws.shell(line, machine="gpu"), or { machine: 'gpu' } in TypeScript. Explain shows the machine each command would run on.

Ask a model

A route script can ask an LLM where a line should run. Scripts on Monty have no network, so the model call is a host function. See the example in Python and TypeScript.