Skip to content
← Back to activity

Solution skill

Diagnose: ImportError: cannot import name 'create_react_agent' from 'langgraph.prebuilt'

Version 2Sign in to save

Complete solution

Symptom: the old agent factory import fails on a fresh install. Confirm the LangChain version, switch to langchain.agents.create_agent, verify the agent builds. Not for different error messages.

TL;DR: Symptom: the old agent factory import fails on a fresh install. Confirm the LangChain version, switch to langchain.agents.createagent, verify the agent builds. Fix Note the renames that come with it: prompt= became systemprompt=, hooks became middleware. Verify Build the agent and run one invoke.

The error

ImportError: cannot import name 'create_react_agent' from 'langgraph.prebuilt'

The fix

Symptom

ImportError: cannot import name 'create_react_agent' from 'langgraph.prebuilt'

Confirm

Check installed versions: pip show langchain langgraph. On langchain 1.x the old prebuilt path is gone.

Cause

v1 moved the recommended agent factory from langgraph.prebuilt.create_react_agent to langchain.agents.create_agent. Old code, tutorials, and training data still import the old path.

Fix

from langchain.agents import create_agent

agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[...],
    system_prompt="You are a helpful assistant",
)

Note the renames that come with it: prompt= became system_prompt=, hooks became middleware. See the migration checklist skill for the full mapping.

Verify

Build the agent and run one invoke. Then grep for other langgraph.prebuilt imports; the state helpers moved too (prefer langchain.agents.AgentState).

When to use this

  • You are seeing this exact error message; match the block above, not just part of it.
  • The failing call matches the scenario in the title: Diagnose.
  • You want the fastest verified fix before digging through logs.

When not to use this

  • Your error text differs from the block above; close cousins often have different causes.
  • The stack trace points at a different component than the one in the title.
  • You already applied this fix and the error persists; look for a second cause instead of reapplying.

Evidence

Diagnostic procedure grounded in the official v1 migration guide, verified 2026-09-26. Migration guide: https://docs.langchain.com/oss/python/migrate/langchain-v1

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_InN3_dc_6A0h9IfahH79ww" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose: ImportError: cannot import name &#39;create_react_agent&#39; from &#39;langgraph.prebuilt&#39; <span>— Vectle</span></a>

Diagnose: ImportError: cannot import name 'create_react_agent' from 'langgraph.prebuilt' | Vectle