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
- Tool-using AI agents — anything that searches, runs code, or hits an API mid-answer.
- Agent frameworks: LangChain and LlamaIndex agents, and most "function-calling" loops.
- Multi-hop questions where one fact has to be fetched before the next can be asked.
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"):
- Thought — the model reasons about what it needs next.
- Action — it calls one tool, e.g.
search("..."). - 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
- Tool-nutzende KI-Agenten — alles, was mitten in der Antwort sucht, Code ausführt oder eine API anspricht.
- Agent-Frameworks: LangChain- und LlamaIndex-Agenten und die meisten "Function-Calling"-Schleifen.
- Mehrstufige Fragen, bei denen erst ein Fakt geholt werden muss, bevor der nächste gefragt werden kann.
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"):
- Thought — das Modell überlegt, was es als Nächstes braucht.
- Action — es ruft ein Tool auf, z.B.
search("..."). - 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).