Intermediate10 min
LangChain v1 Migration Guide
Everything that changed in LangChain v1: create_agent replaces create_react_agent, ToolRuntime replaces InjectedState, middleware replaces hooks, and TypedDict is the only state type.
Quick Reference
- →from langchain.agents import create_agent — replaces create_react_agent from langgraph.prebuilt
- →system_prompt parameter replaces prompt — extract string from SystemMessage objects
- →ToolRuntime replaces InjectedState, InjectedStore, InjectedConfig — one typed parameter
- →State schemas must be TypedDict only — Pydantic and dataclass no longer supported
- →.text is a property, not a method — remove parentheses: message.text not message.text()
- →Legacy code available in langchain-classic package
Breaking Changes at a Glance
| Before (v0.x) | After (v1.0) | Migration |
|---|---|---|
| from langgraph.prebuilt import create_react_agent | from langchain.agents import create_agent | Change import |
| prompt=SystemMessage(...) | system_prompt='...' | Extract string or pass SystemMessage |
| InjectedState, InjectedStore, InjectedConfig | ToolRuntime[Context] | Single typed parameter |
| config['configurable']['user_id'] | runtime.context.user_id | Use typed context_schema |
| pre_model_hook / post_model_hook | middleware=[...] | Use AgentMiddleware or decorators |
| Pydantic / dataclass state | TypedDict only | Convert to TypedDict subclass of AgentState |
| .text() method | .text property | Remove parentheses |
| example= on AIMessage | Removed | Use few-shot via messages list |
| Streaming node name 'agent' | Node name 'model' | Update stream filters |
| Output parsers for structured output | ProviderStrategy / ToolStrategy | Use response_format |
| Legacy chains (LLMChain, etc.) | langchain-classic package | pip install langchain-classic |