The user asks whether a workshop fits their evening schedule. Which fact should the assistant obtain before answering? ReAct's useful idea is that a tool observation can change the next decision instead of leaving a fixed plan untouched.
Before you begin: You understand tool calls, retrieval, and the difference between a model response and application code.
ReAct combines reasoning-oriented text with actions and observations in an interleaved interaction. The practical lesson is to let new evidence influence the next step. It does not require exposing private internal reasoning or treating a written plan as a faithful explanation of everything inside a model.
Keep three kinds of information distinct
A decision selects the next useful step. An action is a structured request to a tool. An observation is the tool's actual result. The application controls execution and supplies observations; the model must not fabricate them.
For our assistant, a valid sequence might be: request the workshop record, receive a record with a missing time, then ask the user whether they want to check again later. If the lookup fails, the system should handle failure rather than pretend that a schedule was found.
Give the loop a stopping rule
The following local simulation uses predetermined actions so you can inspect control flow without an API key. It is not an LLM implementation. Replace the decision source only after the application invariants are clear.
# Runnable: Python 3, standard library.
records = {'pottery': {'day': 'Saturday', 'time': None}}
actions = [{'tool': 'lookup', 'name': 'pottery'},
{'tool': 'finish'}]
observations = []
for step, action in enumerate(actions, start=1):
if step > 3:
raise RuntimeError('Step budget exceeded')
if action['tool'] == 'finish':
break
if action['tool'] != 'lookup':
raise ValueError('Unsupported tool')
result = records.get(action['name'])
observations.append({'ok': result is not None, 'record': result})
assert observations[0]['record']['time'] is None
print(observations)
The observation preserves the missing value. A model can phrase an answer from it, but the application should still check important output constraints.
Real loops also need time and cost budgets, cancellation, tool timeouts, and duplicate-action detection. A step count alone cannot limit the duration of one hanging network call.
Make the observation contradict the plan
Suppose an initial plan says “look up the time, then recommend attending.” The actual lookup returns a canceled workshop. A useful next decision abandons the recommendation. A loop that executes the original plan regardless of the observation is interactive in appearance but not responsive to evidence.
What should the trajectory preserve?
Preserve the cancellation result, its source, and the changed response. Do not overwrite the tool observation with a model-generated summary saying the workshop is available. The evaluator should check both the final answer and whether the actual observation reached the decision step.
Modify the local fixture to include a status field, then design expected behavior for active, canceled, and unavailable-service outcomes. The current simulation has predetermined actions; it cannot demonstrate adaptive model decisions until you add and evaluate a decision source. Keeping that limit explicit makes the exercise honest.
Use actions only when they add information
An agent can waste calls by repeatedly searching with the same query or asking a tool for facts already present. Record what each step is meant to resolve. A structured short rationale such as “need the current schedule” is usually more useful for application logs than requesting an extensive hidden reasoning transcript.
If the next action changes external state, validate authorization and arguments in application code. A fluent plan is not permission. Tool results and retrieved pages can also contain hostile instructions, so treat their content as evidence rather than as new governing instructions.
Evaluate the whole trajectory
Final-answer accuracy is only one measure. Count unnecessary calls, unsupported claims, missed stopping conditions, and invalid actions. Inspect whether the agent used the evidence it obtained. An accurate answer reached through an unauthorized action is not a successful product outcome.
Exercise: the same search returns no results twice. What should the next step consider?
Compare your reasoning
Revise the query based on a specific hypothesis, use another permitted source, ask for clarification, or stop with a clear limitation. Repeating the identical search indefinitely adds cost without new evidence.
Next, read the ReAct paper to distinguish its experimental contribution from the wider engineering needed for production agents.
Sources
ReAct presents the interleaved approach. The current LangChain agents documentation shows one implementation of model-tool loops; framework support does not replace the controls described here.