ReAct Framework
Tool Calling used tool_calls JSON. ReAct is the text version — the model prints each step. You will still see it in older repos and blog posts.
Lines in the output
Agent Types already sketched these. On a real run they look like:
Thought — short plan before picking a tool.
Action + Action Input — tool name and args as plain text.
Observation — whatever your Python function returned.
Final Answer — user-facing reply when the loop stops.
The pattern comes from the ReAct paper. LangChain ships a copy of the prompt in the docs.
One lookup_html_tag call:
Prompt template
ReAct is mostly this block pasted into a PromptTemplate. Watch {agent_scratchpad} — LangChain drops previous Thought/Action/Observation lines there between passes.
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (Thought/Action/Action Input/Observation can repeat)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Question: {input}
Thought:{agent_scratchpad}For new work, stick with create_agent. ReAct is handy when you need the steps printed or you are reading code from 2023.
create_agent tool_calls JSON hidden steps
ReAct
create_react_agent Thought / Action / Observation in output fixed prompt template
lookup_html_tag tool. Different way of asking the model to pick it.create_react_agent
Import from langchain_classic, not the main agents package. Pass ChatOpenAI, your tools, and the template. AgentExecutor calls lookup_html_tag when the model names it in Action.
from langchain_classic.agents import AgentExecutor, create_react_agent
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
prompt = PromptTemplate.from_template(REACT_PROMPT)
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
agent = create_react_agent(llm, [lookup_html_tag], prompt)
executor = AgentExecutor(agent=agent, tools=[lookup_html_tag], verbose=True)
result = executor.invoke({"input": "What does the <a> tag do?"})
print(result["output"])Run the demo
Venv from Project Setup. One extra package:
pip install langchain-classic
Download, then:
react_framework_demo.py
One <a> question, verbose on
OPENAI_API_KEY in .env. Needs langchain-classic below.python react_framework_demo.py
verbose=True to see each line in the shell.create_react_agent in the reference.