← CS Lab AI & Machine Learning / ReAct Loop Open standalone ↗

The ReAct loop lets a language model reason and act in turns — instead of answering in one shot. It interleaves a thought, an action (calling a tool), and an observation (the result), repeating until it can give a final answer. This is ReAct as in Reason + Act — nothing to do with React.js.

Where you meet it

What it does

A bare model only has its training data; it can't look anything up. ReAct closes that gap by turning a single question into a loop: the model writes its reasoning out loud, picks an action, and gets a real result back before deciding the next move. Reasoning steers the actions; observations keep the reasoning honest.

The growing transcript is the model's memory — every observation it reads is one it just wrote down itself.

How it works

Each round is three moves on a growing transcript (the "scratchpad"):

  1. Thought — the model reasons about what it needs next.
  2. Action — it calls one tool, e.g. search("...").
  3. Observation — the tool's result is appended back into the context.

Then it loops: the new observation feeds the next thought. The loop ends when the model decides it has enough and emits a final answer (often a finish(...) action). A short trace:

Question: population of France's capital?
Thought 1: I need the capital first.
Action 1:  search("capital of France")
Observation 1: Paris
Thought 2: Now its population.
Action 2:  search("population of Paris")
Observation 2: ~2.1 million
Thought 3: I have the answer.
Action 3:  finish("~2.1 million")

Because every thought, action and observation is appended to the same transcript, that transcript is the model's working memory — it re-reads the whole thing before each step.

Watch out

  • Infinite loops. A confused agent can keep acting forever — cap it with a step limit and a fallback.
  • Context and cost grow every step. The scratchpad only gets longer, so each round adds tokens, latency and money.
  • Error observations must come back cleanly. A failed tool call has to return a readable error the model can react to, not crash the loop.
  • Tool descriptions decide everything. The model picks actions from your tool docs alone — vague descriptions cause wrong or hallucinated actions (calling a tool that doesn't exist, or with made-up arguments).

Go deeper

Die ReAct-Schleife lässt ein Sprachmodell abwechselnd denken und handeln — statt in einem Zug zu antworten. Sie verschränkt einen Thought (Gedanke), eine Action (Tool-Aufruf) und eine Observation (Ergebnis) und wiederholt das, bis eine finale Antwort steht. ReAct steht für Reason + Act — nichts mit React.js zu tun.

Wo es vorkommt

Was es tut

Ein nacktes Modell hat nur seine Trainingsdaten und kann nichts nachschlagen. ReAct schließt diese Lücke, indem es aus einer Frage eine Schleife macht: Das Modell schreibt sein Reasoning aus, wählt eine Aktion und bekommt ein echtes Ergebnis zurück, bevor es den nächsten Zug entscheidet. Das Reasoning lenkt die Aktionen; die Beobachtungen erden das Reasoning.

Das wachsende Transkript ist das Gedächtnis des Modells — jede Observation, die es liest, hat es eben selbst notiert.

Wie es funktioniert

Jede Runde sind drei Züge auf einem wachsenden Transkript (dem "Scratchpad"):

  1. Thought — das Modell überlegt, was es als Nächstes braucht.
  2. Action — es ruft ein Tool auf, z.B. search("...").
  3. Observation — das Tool-Ergebnis wird zurück in den Kontext gehängt.

Dann wiederholt sich das: Die neue Beobachtung speist den nächsten Gedanken. Die Schleife endet, wenn das Modell genug hat und eine finale Antwort ausgibt (oft als finish(...)-Aktion). Ein kurzer Trace:

Frage: Einwohner der Hauptstadt Frankreichs?
Thought 1: Erst brauche ich die Hauptstadt.
Action 1:  search("capital of France")
Observation 1: Paris
Thought 2: Jetzt die Einwohnerzahl.
Action 2:  search("population of Paris")
Observation 2: ~2,1 Millionen
Thought 3: Ich habe die Antwort.
Action 3:  finish("~2,1 Millionen")

Weil jeder Gedanke, jede Aktion und Beobachtung an dasselbe Transkript angehängt wird, ist dieses Transkript das Arbeitsgedächtnis des Modells — vor jedem Schritt liest es alles erneut.

Worauf achten

  • Endlosschleifen. Ein verwirrter Agent kann ewig weiterhandeln — mit Schrittlimit und Fallback deckeln.
  • Kontext und Kosten wachsen mit jedem Schritt. Der Scratchpad wird nur länger, also kostet jede Runde mehr Tokens, Latenz und Geld.
  • Fehler-Observations müssen sauber zurück. Ein fehlgeschlagener Tool-Aufruf muss einen lesbaren Fehler liefern, auf den das Modell reagieren kann — nicht die Schleife sprengen.
  • Tool-Beschreibungen entscheiden alles. Das Modell wählt Aktionen allein aus deinen Tool-Docs — vage Beschreibungen führen zu falschen oder halluzinierten Aktionen (ein Tool aufrufen, das es nicht gibt, oder mit erfundenen Argumenten).

Mehr dazu

Next up
AI & Machine LearningTool Calling AI & Machine LearningMulti-Agent Routing All concepts →