Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

LangChain no longer exports AgentExecutor from langchain.agents

ErrorImportError: 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.

  • Applies to LangChain 1.x, langchain-classic, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 langchain
  2. 2Match what you see, then jump to its fix

    1. 1langchain shows version 1.x and the failing line is from langchain.agents import AgentExecutor.AgentExecutor moved to the langchain-classic packageFix
    2. 2The 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

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 AgentExecutor

3Verify

The import succeeds.

python -c "from langchain_classic.agents.agent import AgentExecutor; print('ok')"

Confirmed by docs.langchain.com

Did this fix it?

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

Did this fix it?

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:

Related fixes

AI

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.