---
title: "Chapter 18. A Runtime for a Nondeterministic Executor"
url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch18"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-18T12:24:57.879Z"
book: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
access: "lead-in"
purchase: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
alternates:
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch18"
    markdown: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch18.md"
  - locale: "en"
    url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch18"
    markdown: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch18.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch18"
    markdown: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch18.md"
---

# Chapter 18. A Runtime for a Nondeterministic Executor

*[JavaScript: From Closures to Autonomous Systems](https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems)*

In all the previous chapters the runtime placed bets on a program written by a human. V8 guessed what shape of objects would come into a function, Meteor guessed what the server would answer, Temporal required the code to behave on replay the same way as the first time. The program itself was known in advance. You could read it, check its types, run tests, and everything it could do was written in its text.

With an agent, things are different. In 2022 Shunyu Yao and his co-authors described a scheme they called ReAct: a language model alternately reasons and acts. It receives a task, writes what it is going to do, calls a tool, receives the result, reasons again and decides what to do next. In JavaScript such a loop fits into a dozen lines:

```
while (true) {
  const reply = await model(messages, tools);
  messages.push(reply);
  if (reply.stop_reason !== 'tool_use') break;
  const results = await runTools(reply.toolCalls);
  messages.push({ role: 'user', content: results });
}
```

The model answers either with text, and then the work is done, or with a request to call a tool with such-and-such arguments. The code calls the tool, puts the result into the conversation and calls the model again. Which tool it will ask for on the fifth step and with which arguments cannot be learned from this code. The program’s next action is chosen at run time, and it is chosen by an executor that can be wrong.

* * *

Usually, what lies between the text of a program and its execution is checked for the programmer by someone else. Syntax is checked by the parser, types by the TypeScript compiler, process permissions by the operating system. In an agent loop all these checks have to be done anew at every step, because the program is written anew at every step. The code around the model that does this has come to be called the harness.

---

The rest of this chapter is free on the site once the reader confirms an email address: https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch18
