Tuesday, April 28, 2026

create_react_agent/AgentExecutor vs create_agent in langchain and langgraph

The evolution of LangChain has led to significant shifts in how agents are constructed, moving from the legacy AgentExecutor to the graph-based runtime of LangGraph. 

1. Legacy: AgentExecutor & create_react_agent (LangChain Classic) 
The original LangChain framework used a pre-built loop called AgentExecutor to manage the reasoning and execution cycle of an agent. 
  • create_react_agent (Classic): A legacy factory function that creates a "ReAct" style agent. It requires a specific prompt template with "Thought/Action/Observation" markers.
  • AgentExecutor: A black-box class that wraps the agent and the tools. It handles the loop internally: calling the LLM, parsing the tool request, running the tool, and repeating.
  • Status: While still supported, it is considered legacy and less flexible for complex, production-grade applications. 
2. Current Standard: create_agent (LangChain 1.0) 
With the release of LangChain 1.0, the framework introduced a more unified and flexible approach. 
  • Functional Identity: create_agent is the new standard factory for building agents. It is designed to work seamlessly with the LangGraph runtime.
  • Key Feature (Middleware): It introduces a powerful middleware system for customization, allowing developers to inject logic before the model is called or after tool execution.
  • Simplification: It often defaults to "tool-calling" architectures, which can sometimes skip explicit "Thought" reasoning steps in logs compared to older ReAct implementations. 
3. Prebuilt Graph: create_react_agent (LangGraph) 
This is a high-level helper provided within the langgraph.prebuilt module. 
  • What it does: It automatically constructs a complete StateGraph that implements the ReAct loop (LLM -> Tools -> LLM).
  • Advantages: It provides immediate access to LangGraph's advanced features like persistence (long-term memory), human-in-the-loop (approval steps), and granular streaming of intermediate steps.
  • Migration Note: Recent LangGraph documentation suggests that langgraph.prebuilt.create_react_agent is being superseded by the create_agent function from the core langchain package for better architectural alignment. 
Summary Comparison Table
Feature AgentExecutor / Legacycreate_agent (LangChain 1.0)create_react_agent (LangGraph)
ArchitecturePython loop (Black box)Graph-based (LangGraph runtime)Prebuilt StateGraph
CustomizationHard to modify internal loopHigh (via middleware)High (can modify the graph)
PersistenceSession-bound (Temporary)First-class (Durable)First-class (Durable)
Use CaseSimple prototypesRecommended for productionRapid prototyping on LangGraph
StatusLegacy / ClassicModern StandardPrebuilt Utility



No comments:

Post a Comment

AI Agent to extract info from a static web page

  # STEP 1.1 INSTALL THE REQUIRED PACKAGES ! pip install langchain_community langchain_google_genai ! pip install -U duckduckgo-search #you ...