This article is published in English.
ReAct from scratch: thought, action, pause, observation without a framework
Build a tiny Groq ReAct loop by hand—manual observations first, then regex-driven tool calls—to see why modern agent frameworks feel the way they do.
Introduction
Ask a plain language model for Nvidia’s live price and how many shares $100,000 buys. Without tools it invents a stale quote from training data, then divides correctly on wrong inputs. It has no built-in move that means “I do not know—look it up,” because lookup is not a single forward pass.
As response quality rose, models proved useful for one-shot reasoning. Planning alone still does not grant autonomy. The questions that define agents are: what is outside model knowledge, which action acquires it, how to produce a result, how to revise the plan, and when to stop. Decision → act → check → replan is a loop, not a straight line. That loop is the origin of modern AI agents. ReAct (Reason + Act) set the pattern. The original demos were not LangChain apps—they were an LLM, a structured prompt, and a human (or later a script) executing actions and feeding observations back.
Enter ReAct: Reasoning + Act
A worked example, step by step:
from groq import Groq
import re
from dotenv import load_dotenv
_ = load_dotenv()
client = Groq()
message = client.chat.completions.create(
model="openai/gpt-oss-120b", # free, fast open-weight model hosted on Groq
max_tokens=1000,
messages=[
{"role": "user", "content": "Hello, GPT!"}
],
)
print(message.choices[0].message.content) # Check the client
class Agent:
def __init__(self, system=""):
self.system = system
self.messages = []
if self.system:
self.messages.append({"role": "system", "content": system})
def __call__(self, message):
self.messages.append({"role": "user", "content": message})
result = self.execute()
self.messages.append({"role": "assistant", "content": result})
return result
def execute(self):
response = client.chat.completions.create(
model="openai/gpt-oss-120b",
max_tokens=1000,
messages=self.messages,
).choices[0].message.content
return response
prompt = """
You run in a loop of Thought, Action, PAUSE, Observation.
At the end of the loop you output an Answer
Use Thought to describe your thoughts about the question you have been asked.
Use Action to run one of the actions available to you - then return PAUSE.
Observation will be the result of running those actions.
Your available actions are:
calculate:
e.g. calculate: 4 * 7 / 3
Runs a calculation and returns the number - uses Python so be sure to use floating point syntax if necessary
fish_weight:
e.g. fish_weight: Shark
returns weight of a fish when given the breed
Example session:
Question: How much does a shark weigh?
Thought: I should look the fish weight using fish_weight
Action: fish_weight: Shark
PAUSE
You will be called again with this:
Observation: A Great white shark weights 41000 lbs
You then output:
Answer: A Great white shark weights 41000 lbs
""".strip()
def calculate(expression):
return eval(expression)
def fish_weight(name):
if "Shark" in name:
return("Great white shark weighs 41000 lbs")
elif "Puffer" in name:
return("A puffer fish weighs 20 lbs")
else:
return("A fish can weight upto 47000 lbs")
known_actions = {
"calculate": calculate,
"fish_weight": fish_weight
}
abot = Agent(prompt)
result = abot("How much does a Shark weigh?")
print(result)
result = fish_weight("Shark")
result
next_prompt = "Observation: {}".format(result)
abot(next_prompt)
abot.messages # View the list of messages containing the conversation
# Present a compund query
abot = Agent(prompt)
# New query
question = """I have 2 fishes, a Shark and a puffer fish. \
What is their combined weight"""
abot(question)
next_prompt = "Observation: {}".format(fish_weight("Shark"))
print(next_prompt)
abot(next_prompt)
next_prompt = "Observation: {}".format(fish_weight("Puffer fish"))
print(next_prompt)
abot(next_prompt)
next_prompt = "Observation: {}".format(eval("41000 + 20"))
print(next_prompt)
abot(next_prompt)
## Add loop (automate the reasoning + act process)
action_re = re.compile('^Action: (\w+): (.*)