Skip to content
Optimal Lab

AI · interactive

The ReAct loop

An agent alternates between reasoning and acting: think about what's missing, call a tool, read the result, and think again. It stops when it can answer. Compare it with a model that just answers from memory.

search()weather()calculator()
  1. Question

    What's the temperature right now, in °F, in the city where the Eiffel Tower is?

The question goes in with a list of tools the model may use.

Agent

step 1 of 11
1

Think

The model reasons about what it knows and what it still needs.

Writing the plan down makes the next step better.

2

Act

It emits a tool call with arguments. Your code validates and runs it.

{ tool: "weather", args: { city: "Paris" } }

3

Observe

The tool output goes back into the context. The model now knows something it couldn't have guessed.

Errors are observations too: the model can retry.

4

Answer, or stop at a limit

When nothing is missing, it answers. Always cap the number of steps and the spend, or a confused agent loops forever.

max_steps = 10

In production

Tools and technologies

Most agent frameworks run a version of this loop.

Not tied to one language — use these names when you search docs or design a system.