What is the ReAct framework and how does it enable AI agents to reason and act?
ReAct (Reasoning + Acting) is a paradigm where AI agents interleave reasoning traces with actions in the environment. Process: the agent receives a task, generates a thought (reasoning about what to do next), takes an action (calling a tool, searching, computing), observes the result, and repeats until the task is complete. Example cycle: Thought: "I need to find the current stock price of AAPL", Action: search("AAPL stock price"), Observation: "$185.50 as of market close", Thought: "Now I need to calculate the P/E ratio using the earnings data", Action: calculate(185.50 / 6.42), Observation: "28.9". This interleaving is powerful because reasoning guides action selection (the agent plans before acting) and observations inform subsequent reasoning (the agent adapts based on results). Implementation: provide the LLM with a system prompt defining available tools, output format (Thought/Action/Observation), and task instructions. Parse LLM outputs to extract actions, execute them, and feed observations back. Frameworks: LangChain ReAct agent, LlamaIndex ReAct agent, and custom implementations using structured output parsing. Advantages over pure chain-of-thought: grounded in real-world observations rather than generating from memory alone, can access current information, and can verify intermediate results. Limitations: can get stuck in reasoning loops, may take inefficient action sequences, and quality depends heavily on the base model's reasoning capability and tool descriptions.