LangChain no longer exports AgentExecutor from langchain.agents
ImportError: cannot import name 'AgentExecutor' from 'langchain.agents'Short answer
LangChain v1 moved legacy classes into a separate package called langchain-classic, and AgentExecutor lives there now. Install it and import from langchain_classic. For new code, the v1 guide replaces the old agent helpers with create_agent from langchain.agents, so consider porting instead of keeping the legacy path.
Fix it fast
1Find out which cause you have
Check which LangChain packages and versions are installed. Version 1.0 or higher is the one that dropped the old names from langchain.agents.
pip list | grep -i langchain2Match what you see, then jump to its fix
- 1
langchain shows version 1.x and the failing line is from langchain.agents import AgentExecutor.AgentExecutor moved to the langchain-classic packageFix - 2
The same file also uses create_react_agent, and you are starting a new project or touching the agent anyway.The old agent-building code should be ported, not keptFix
- 1
What does the error look like?
ImportError: cannot import name 'AgentExecutor' from 'langchain.agents'
Cause 1 of 2
AgentExecutor moved to the langchain-classic package
1Check
The v1 guide says legacy chains and other deprecated pieces moved into langchain-classic, and the API reference lists AgentExecutor under langchain_classic.
python -c "import langchain; print(langchain.__version__)"2Fix
Install the legacy package and change the import to the new module. The reference shows the class defined in langchain_classic.agents.agent.
pip install langchain-classic
# in your code
from langchain_classic.agents.agent import AgentExecutor3Verify
The import succeeds.
python -c "from langchain_classic.agents.agent import AgentExecutor; print('ok')"Confirmed by docs.langchain.com
Cause 2 of 2
The old agent-building code should be ported, not kept
1Check
The v1 guide names create_agent as the replacement for create_react_agent, and renames the prompt= argument to system_prompt=.
grep -rn "create_react_agent\|AgentExecutor" --include='*.py' .2Fix
Build the agent with create_agent and pass your instructions as system_prompt. LangChain v1 needs Python 3.10 or newer.
from langchain.agents import create_agent
agent = create_agent(
model=MODEL,
tools=TOOLS,
system_prompt="You are a helpful assistant.",
)3Verify
The import and the build both work with no ImportError.
python -c "from langchain.agents import create_agent; print('ok')"Confirmed by docs.langchain.com
How do I stop it coming back?
- Pin langchain and langchain-classic to compatible major versions in requirements.txt.
- Read the migration guide before a major upgrade and grep your code for the moved names.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
LangChain says it could not import the chromadb package
ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.
The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.
2 causes, each with a fixAI
Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier
429 RESOURCE_EXHAUSTED
Gemini limits are applied per Google Cloud project, not per API key, so a new key in the same project does not reset anything.
3 causes, each with a fixAI
ChatPromptTemplate is missing the variable agent_scratchpad
Expected: ['agent_scratchpad', 'input']
A tool-calling agent keeps its tool calls and tool results in a prompt slot named agent_scratchpad.
2 causes, each with a fixAI
ConversationalRetrievalChain cannot be imported from langchain.chains
Importing ConversationalRetrievalChain from langchain.chains isn't working
In LangChain v1 the legacy chains moved out of the langchain package into langchain-classic, so langchain.chains no longer has ConversationalRetrievalChain.
2 causes, each with a fix