JavaScript: From Closures to Autonomous Systems

Capítulo 18. A Runtime for a Nondeterministic Executor

Part V. An Executor That Can Be Wrong7 min · en inglés

18

A Runtime for a Nondeterministic Executor

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.

Gratis, solo falta un paso

El resto del libro es gratis

Deja tu correo y te mando un enlace para confirmarlo. Después del clic, todos los capítulos se abren aquí, en este dispositivo, durante un año. Cuando salga un libro nuevo, escribiré a esa dirección; responde “basta” a cualquier correo y no vuelvo a escribir.

¿Tienes cuenta INITE? Entra y el libro se abre sin correo.

No se cobra nada por el libro. Si quieres apoyarlo, puedes donar desde cualquier capítulo.

Cómo se guarda la dirección