[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M792FJWKBQYS4VDNS86SS0Q8":3,"skill-same:01M792FJWKBQYS4VDNS86SS0Q8":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":44,"updatedAt":45,"install":46,"resources":59},"01M792FJWKBQYS4VDNS86SS0Q8","langchain-upgrade-migration",null,"Migrate a LangChain 0.3.x Python codebase to LangChain 1.0 \u002F LangGraph 1.0 without\nbreaking production — named breaking changes, codemod patterns, and a phased rollout.\nUse when upgrading LangChain or LangGraph from 0.2 or 0.3 to 1.0, when hitting\nImportError after an upgrade, or when preparing a migration PR.\nTrigger with \"langchain 1.0 migration\", \"langchain upgrade\", \"LLMChain removed\",\n\"initialize_agent removed\", \"ConversationBufferMemory removed\", \"astream_log deprecated\",\n\"langchain-anthropic 1.0\".","jukeyman\u002Fjukeyman-skills","jukeyman","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F142960420?v=4","01M78FR4Y3DHMMCBCC0GXXNB3F","RICK JEFFERSON","01M78FR4Z8RVQRAD31Y5J7V6EB",1,"MIT","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--langchain-py-pack--langchain-upgrade-migration\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: langchain-upgrade-migration\ndescription: |\n  Migrate a LangChain 0.3.x Python codebase to LangChain 1.0 \u002F LangGraph 1.0 without\n  breaking production — named breaking changes, codemod patterns, and a phased rollout.\n  Use when upgrading LangChain or LangGraph from 0.2 or 0.3 to 1.0, when hitting\n  ImportError after an upgrade, or when preparing a migration PR.\n  Trigger with \"langchain 1.0 migration\", \"langchain upgrade\", \"LLMChain removed\",\n  \"initialize_agent removed\", \"ConversationBufferMemory removed\", \"astream_log deprecated\",\n  \"langchain-anthropic 1.0\".\nallowed-tools: Read, Write, Edit, Grep, Bash(python:*)\nversion: 2.0.0\nlicense: MIT\nauthor: Jeremy Longshore \u003Cjeremy@intentsolutions.io>\ntags: [saas, langchain, langgraph, python, langchain-1.0, migration, upgrade]\ncompatible-with: claude-code, codex\n---\n\n# LangChain 1.0 Upgrade Migration (Python)\n\n## Overview\n\nThe first deploy after `pip install -U langchain` crashes on import with:\n\n```\nImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'\n```\n\nFix the import, restart, and the next error lands:\n\n```\nImportError: cannot import name 'LLMChain' from 'langchain.chains'\nAttributeError: module 'langchain.agents' has no attribute 'initialize_agent'\nAttributeError: 'ConversationBufferMemory' object has no attribute 'save_context'\n```\n\nLangChain 1.0 removed four entire public-API surfaces in one release:\n\n- Provider imports under `langchain.chat_models` \u002F `langchain.llms` (pain code **P38**).\n- The `LLMChain` family under `langchain.chains` (**P39**).\n- `ConversationBufferMemory` and siblings under `langchain.memory` (**P40**).\n- `initialize_agent` under `langchain.agents` (**P41**).\n\nAnything that inspected `intermediate_steps` also breaks because the tuple shape changed from `(AgentAction, observation)` to `(ToolCall, observation)` (**P42**).\n\nThis skill walks a reversible, phased migration:\n\n1. A pre-flight grep audit.\n2. A pinned package upgrade (including the `langchain-anthropic` 1.0 peer-pin against `anthropic >= 0.40`, **P66**).\n3. Codemod patterns for the seven removed APIs.\n4. A rollout playbook with shadow traffic and a sub-five-minute rollback.\n\nIt covers **7 named breaking changes** and typically touches **10–100 files** in a mid-sized service.\n\nThe fix for the error above:\n\n```python\n# BEFORE (0.3)\nfrom langchain.chat_models import ChatOpenAI\n\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\n```\n\nSee [codemod-patterns.md](references\u002Fcodemod-patterns.md) for the other six patterns.\n\n## Prerequisites\n\n- Python 3.10+ (LangChain 1.0 dropped 3.8\u002F3.9).\n- A working test suite for the service being migrated (the playbook runs `pytest -W error::DeprecationWarning` at every phase).\n- Git on a clean working tree — the migration uses per-module commits so rollback is per-commit.\n- Access to staging traffic or a request-mirror. Phase 4 of the playbook needs real-shape traffic.\n- If conversations are persisted (Redis \u002F Postgres \u002F DynamoDB), a snapshot of the chat-history store before Phase 2. The LangGraph checkpointer uses a new schema and a naive rollback is data-lossy.\n\n## Instructions\n\n### Step 1 — Pre-flight grep audit\n\nInventory every 0.3 usage before touching a `requirements.txt`. Each grep below maps to one pain code and one codemod pattern.\n\n```bash\ngrep -rn \"from langchain\\.chat_models\\|from langchain\\.llms\" --include=\"*.py\" .          # P38\ngrep -rn \"from langchain\\.chains\\b\\|\\bLLMChain\\b\\|\\bRetrievalQA\\b\" --include=\"*.py\" .    # P39\ngrep -rn \"from langchain\\.memory\\|ConversationBufferMemory\" --include=\"*.py\" .           # P40\ngrep -rn \"initialize_agent\\|AgentType\\.\" --include=\"*.py\" .                              # P41\ngrep -rn \"\\.tool_input\\b\\|intermediate_steps\" --include=\"*.py\" .                         # P42\ngrep -rn \"astream_log\\b\" --include=\"*.py\" .                                              # P67\n```\n\nPipe the full set into `langchain-0.3-hits.txt` — that file is the migration work list. The [migration-detection.md](references\u002Fmigration-detection.md) reference has the one-shot bundled block and a line-count triage table.\n\n### Step 2 — Pin and upgrade packages together\n\nLangChain 1.0 spans six coordinated packages. A partial upgrade (e.g. `pip install -U langchain-anthropic` without bumping `anthropic`) triggers `AttributeError` at import time (**P66**). Update all six in the same commit:\n\n```\nlangchain>=1.0,\u003C2\nlangchain-core>=0.3,\u003C0.4\nlangchain-openai>=1.0\nlangchain-anthropic>=1.0\nlanggraph>=1.0,\u003C2\nanthropic>=0.40,\u003C1\n```\n\nApply:\n\n```bash\npip install -U \\\n  \"langchain>=1.0,\u003C2\" \\\n  \"langchain-core>=0.3,\u003C0.4\" \\\n  \"langchain-openai>=1.0\" \\\n  \"langchain-anthropic>=1.0\" \\\n  \"langgraph>=1.0,\u003C2\" \\\n  \"anthropic>=0.40,\u003C1\"\n```\n\nThen snapshot the prior state for the rollback: `pip freeze > requirements.lock.pre-1.0.txt`.\n\n### Step 3 — Codemod the four removed APIs\n\nWork through the hits from Step 1 in this order (lowest blast radius first):\n\n1. **Provider imports (P38)** — mechanical find\u002Freplace. `from langchain.chat_models import ChatOpenAI` → `from langchain_openai import ChatOpenAI`. Same pattern for `ChatAnthropic`, `OpenAIEmbeddings`, `Chroma`, etc.\n2. **`LLMChain` → LCEL (P39)** — replace `chain = LLMChain(llm=llm, prompt=prompt)` with `chain = prompt | llm | StrOutputParser()`. Caller changes from `chain.run(x=1)` to `chain.invoke({\"x\": 1})`. If the caller treated the result as a dict, unwrap — `invoke` returns the string directly.\n3. **`initialize_agent` → `create_react_agent` (P41)** — swap the import to `from langgraph.prebuilt import create_react_agent`. Tools written with `Tool(name=..., func=...)` still work; prefer the `@tool` decorator from `langchain_core.tools`. Agent input becomes `{\"messages\": [(\"user\", \"...\")]}`; the final reply is `result[\"messages\"][-1].content`.\n4. **`ConversationBufferMemory` → LangGraph checkpointer (P40)** — swap the memory object for `MemorySaver()` (dev) or `SqliteSaver.from_conn_string(...)` (prod). Compile the graph\u002Fagent with `checkpointer=saver`, then pass `config={\"configurable\": {\"thread_id\": \"...\"}}` on every `invoke`. The `thread_id` is the conversation primary key.\n\nFull before\u002Fafter snippets for all four are in [codemod-patterns.md](references\u002Fcodemod-patterns.md).\n\n### Step 4 — Update streaming callers (P67)\n\n`astream_log` still works in 1.0 but is soft-deprecated. The replacement is `astream_events(version=\"v2\")`:\n\n```python\n# BEFORE\nasync for patch in chain.astream_log({\"input\": \"hi\"}):\n    for op in patch.ops:\n        if op[\"op\"] == \"add\" and op[\"path\"].endswith(\"\u002Fstreamed_output\u002F-\"):\n            print(op[\"value\"], end=\"\")\n\n# AFTER\nasync for event in chain.astream_events({\"input\": \"hi\"}, version=\"v2\"):\n    if event[\"event\"] == \"on_chat_model_stream\":\n        print(event[\"data\"][\"chunk\"].content, end=\"\")\n```\n\nEvent names in v2: `on_chain_start`, `on_chain_end`, `on_chat_model_start`, `on_chat_model_stream`, `on_chat_model_end`, `on_tool_start`, `on_tool_end`. The payload under `data` is typed — `chunk` is an `AIMessageChunk`, not a raw string.\n\n### Step 5 — Fix `intermediate_steps` consumers (P42)\n\nIf any code iterates `result[\"intermediate_steps\"]` and reads `.tool` \u002F `.tool_input`, it breaks silently in 1.0 — the tuples now hold `ToolCall` dicts, not `AgentAction` objects. The 1.0 equivalent reads from graph state:\n\n```python\n# BEFORE\nfor action, observation in result[\"intermediate_steps\"]:\n    log(action.tool, action.tool_input, observation)\n\n# AFTER\nfor msg in result[\"messages\"]:\n    for tc in getattr(msg, \"tool_calls\", []) or []:\n        log(tc[\"name\"], tc[\"args\"])   # .tool -> \"name\", .tool_input -> \"args\"\n```\n\n`ToolCall` dict keys are `name`, `args`, `id`. There is no `tool` or `tool_input` accessor anywhere in 1.0.\n\n### Step 6 — Gate on deprecation-as-error tests\n\nTurn `DeprecationWarning` into a test failure so any surviving 0.3 pattern surfaces before the rollout:\n\n```bash\npytest -W error::DeprecationWarning\n```\n\nDo not promote to staging while this is red. Re-run the Step 1 greps — they should now return zero hits outside intentionally-pinned 0.3 test fixtures.\n\n### Step 7 — Phased rollout on production traffic\n\nDeploy behind a feature flag (`LANGCHAIN_1_0_ENABLED`), canary at 1%, and ramp to 100% over 2–4 hours with a 15-minute soak at each step. The rollback is always \"flip the flag off\" — not a redeploy. Full playbook (shadow traffic in staging, dual-write for persistent chat histories, per-phase exit criteria) is in [phased-rollout-playbook.md](references\u002Fphased-rollout-playbook.md).\n\n## Output\n\n- `requirements.txt` pinning all six 1.0 packages with the `anthropic >= 0.40` peer-pin (P66).\n- `requirements.lock.pre-1.0.txt` in the repo root for five-minute rollback.\n- Per-module git commits referencing pain codes (e.g. `refactor: migrate P39 LLMChain in billing-summariser to LCEL`).\n- `langchain-0.3-hits.txt` work-list returning zero non-test hits on re-run.\n- `pytest -W error::DeprecationWarning` green on the migration branch.\n- Feature-flagged production cutover at 100%, flag removed after a full day of soak.\n\n## Error Handling\n\n| Error | Cause | Fix |\n|---|---|---|\n| `ImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'` | **P38** — provider imports moved to partner packages | `from langchain_openai import ChatOpenAI` |\n| `ImportError: cannot import name 'LLMChain' from 'langchain.chains'` | **P39** — `LLMChain` removed | Replace with LCEL: `prompt \\| llm \\| StrOutputParser()` |\n| `AttributeError: 'ConversationBufferMemory' object has no attribute 'save_context'` | **P40** — memory classes removed from the public API | Swap for LangGraph `MemorySaver` \u002F `SqliteSaver` with a `thread_id` |\n| `AttributeError: module 'langchain.agents' has no attribute 'initialize_agent'` | **P41** — legacy agent constructor removed | `from langgraph.prebuilt import create_react_agent` |\n| `AttributeError: 'ToolCall' object has no attribute 'tool'` | **P42** — tuple shape changed, fields renamed | Read `tc[\"name\"]` and `tc[\"args\"]` instead of `.tool` \u002F `.tool_input` |\n| `AttributeError: module 'anthropic' has no attribute 'AsyncAnthropic'` | **P66** — `langchain-anthropic 1.0` needs `anthropic >= 0.40` | Pin `anthropic>=0.40,\u003C1` in the same commit as the `langchain-anthropic` bump |\n| `DeprecationWarning: astream_log is deprecated; use astream_events(version=\"v2\")` | **P67** — soft deprecation | Switch to `astream_events(version=\"v2\")` and update event-name handling |\n\n## Examples\n\n### Example 1 — Minimal LLMChain to LCEL\n\n```python\n# BEFORE (0.3)\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts import ChatPromptTemplate\nfrom langchain.chains import LLMChain\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nprompt = ChatPromptTemplate.from_messages([(\"system\", \"Summarise in one line.\"), (\"user\", \"{text}\")])\nchain = LLMChain(llm=llm, prompt=prompt)\nprint(chain.run(text=\"LangChain 1.0 removed LLMChain.\"))\n\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_core.output_parsers import StrOutputParser\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nprompt = ChatPromptTemplate.from_messages([(\"system\", \"Summarise in one line.\"), (\"user\", \"{text}\")])\nchain = prompt | llm | StrOutputParser()\nprint(chain.invoke({\"text\": \"LangChain 1.0 removed LLMChain.\"}))\n```\n\n### Example 2 — Stateful agent with LangGraph checkpointer\n\n```python\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.tools import tool\nfrom langgraph.prebuilt import create_react_agent\nfrom langgraph.checkpoint.memory import MemorySaver    # use SqliteSaver \u002F PostgresSaver in prod\n\n@tool\ndef add(a: int, b: int) -> int:\n    \"\"\"Add two integers.\"\"\"\n    return a + b\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nagent = create_react_agent(llm, [add], checkpointer=MemorySaver())\n\nconfig = {\"configurable\": {\"thread_id\": \"user-42\"}}\nr1 = agent.invoke({\"messages\": [(\"user\", \"What's 2 + 3?\")]}, config=config)\nr2 = agent.invoke({\"messages\": [(\"user\", \"And plus 10?\")]}, config=config)   # remembers \"5\"\nprint(r2[\"messages\"][-1].content)\n```\n\n### Example 3 — Rollback pin\n\nIf Phase 5 of the rollout regresses and the feature flag is already off:\n\n```bash\ngit checkout main\npip install -r requirements.lock.pre-1.0.txt\npytest                      # confirm green on the rollback pin\n# deploy\n```\n\n## Resources\n\n- [LangChain migration guide](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fversions\u002Fmigrating\u002F)\n- [LangChain release policy](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fversions\u002Frelease_policy\u002F)\n- [LangGraph prebuilt `create_react_agent`](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Fprebuilt\u002F)\n- [`astream_events` v2 reference](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fconcepts\u002Fstreaming\u002F)\n- [Breaking changes matrix](references\u002Fbreaking-changes-matrix.md) — all 7 named changes mapped to pain codes\n- [Codemod patterns](references\u002Fcodemod-patterns.md) — before\u002Fafter for the 7 most common migrations\n- [Phased rollout playbook](references\u002Fphased-rollout-playbook.md) — shadow traffic, dual-write, rollback\n- [Migration detection](references\u002Fmigration-detection.md) — pre-flight grep audit\n- [One-pager](references\u002Fone-pager.md) — executive summary\n","# LangChain 1.0 Upgrade Migration (Python)\n\n## Overview\n\nThe first deploy after `pip install -U langchain` crashes on import with:\n\n```\nImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'\n```\n\nFix the import, restart, and the next error lands:\n\n```\nImportError: cannot import name 'LLMChain' from 'langchain.chains'\nAttributeError: module 'langchain.agents' has no attribute 'initialize_agent'\nAttributeError: 'ConversationBufferMemory' object has no attribute 'save_context'\n```\n\nLangChain 1.0 removed four entire public-API surfaces in one release:\n\n- Provider imports under `langchain.chat_models` \u002F `langchain.llms` (pain code **P38**).\n- The `LLMChain` family under `langchain.chains` (**P39**).\n- `ConversationBufferMemory` and siblings under `langchain.memory` (**P40**).\n- `initialize_agent` under `langchain.agents` (**P41**).\n\nAnything that inspected `intermediate_steps` also breaks because the tuple shape changed from `(AgentAction, observation)` to `(ToolCall, observation)` (**P42**).\n\nThis skill walks a reversible, phased migration:\n\n1. A pre-flight grep audit.\n2. A pinned package upgrade (including the `langchain-anthropic` 1.0 peer-pin against `anthropic >= 0.40`, **P66**).\n3. Codemod patterns for the seven removed APIs.\n4. A rollout playbook with shadow traffic and a sub-five-minute rollback.\n\nIt covers **7 named breaking changes** and typically touches **10–100 files** in a mid-sized service.\n\nThe fix for the error above:\n\n```python\n# BEFORE (0.3)\nfrom langchain.chat_models import ChatOpenAI\n\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\n```\n\nSee [codemod-patterns.md](references\u002Fcodemod-patterns.md) for the other six patterns.\n\n## Prerequisites\n\n- Python 3.10+ (LangChain 1.0 dropped 3.8\u002F3.9).\n- A working test suite for the service being migrated (the playbook runs `pytest -W error::DeprecationWarning` at every phase).\n- Git on a clean working tree — the migration uses per-module commits so rollback is per-commit.\n- Access to staging traffic or a request-mirror. Phase 4 of the playbook needs real-shape traffic.\n- If conversations are persisted (Redis \u002F Postgres \u002F DynamoDB), a snapshot of the chat-history store before Phase 2. The LangGraph checkpointer uses a new schema and a naive rollback is data-lossy.\n\n## Instructions\n\n### Step 1 — Pre-flight grep audit\n\nInventory every 0.3 usage before touching a `requirements.txt`. Each grep below maps to one pain code and one codemod pattern.\n\n```bash\ngrep -rn \"from langchain\\.chat_models\\|from langchain\\.llms\" --include=\"*.py\" .          # P38\ngrep -rn \"from langchain\\.chains\\b\\|\\bLLMChain\\b\\|\\bRetrievalQA\\b\" --include=\"*.py\" .    # P39\ngrep -rn \"from langchain\\.memory\\|ConversationBufferMemory\" --include=\"*.py\" .           # P40\ngrep -rn \"initialize_agent\\|AgentType\\.\" --include=\"*.py\" .                              # P41\ngrep -rn \"\\.tool_input\\b\\|intermediate_steps\" --include=\"*.py\" .                         # P42\ngrep -rn \"astream_log\\b\" --include=\"*.py\" .                                              # P67\n```\n\nPipe the full set into `langchain-0.3-hits.txt` — that file is the migration work list. The [migration-detection.md](references\u002Fmigration-detection.md) reference has the one-shot bundled block and a line-count triage table.\n\n### Step 2 — Pin and upgrade packages together\n\nLangChain 1.0 spans six coordinated packages. A partial upgrade (e.g. `pip install -U langchain-anthropic` without bumping `anthropic`) triggers `AttributeError` at import time (**P66**). Update all six in the same commit:\n\n```\nlangchain>=1.0,\u003C2\nlangchain-core>=0.3,\u003C0.4\nlangchain-openai>=1.0\nlangchain-anthropic>=1.0\nlanggraph>=1.0,\u003C2\nanthropic>=0.40,\u003C1\n```\n\nApply:\n\n```bash\npip install -U \\\n  \"langchain>=1.0,\u003C2\" \\\n  \"langchain-core>=0.3,\u003C0.4\" \\\n  \"langchain-openai>=1.0\" \\\n  \"langchain-anthropic>=1.0\" \\\n  \"langgraph>=1.0,\u003C2\" \\\n  \"anthropic>=0.40,\u003C1\"\n```\n\nThen snapshot the prior state for the rollback: `pip freeze > requirements.lock.pre-1.0.txt`.\n\n### Step 3 — Codemod the four removed APIs\n\nWork through the hits from Step 1 in this order (lowest blast radius first):\n\n1. **Provider imports (P38)** — mechanical find\u002Freplace. `from langchain.chat_models import ChatOpenAI` → `from langchain_openai import ChatOpenAI`. Same pattern for `ChatAnthropic`, `OpenAIEmbeddings`, `Chroma`, etc.\n2. **`LLMChain` → LCEL (P39)** — replace `chain = LLMChain(llm=llm, prompt=prompt)` with `chain = prompt | llm | StrOutputParser()`. Caller changes from `chain.run(x=1)` to `chain.invoke({\"x\": 1})`. If the caller treated the result as a dict, unwrap — `invoke` returns the string directly.\n3. **`initialize_agent` → `create_react_agent` (P41)** — swap the import to `from langgraph.prebuilt import create_react_agent`. Tools written with `Tool(name=..., func=...)` still work; prefer the `@tool` decorator from `langchain_core.tools`. Agent input becomes `{\"messages\": [(\"user\", \"...\")]}`; the final reply is `result[\"messages\"][-1].content`.\n4. **`ConversationBufferMemory` → LangGraph checkpointer (P40)** — swap the memory object for `MemorySaver()` (dev) or `SqliteSaver.from_conn_string(...)` (prod). Compile the graph\u002Fagent with `checkpointer=saver`, then pass `config={\"configurable\": {\"thread_id\": \"...\"}}` on every `invoke`. The `thread_id` is the conversation primary key.\n\nFull before\u002Fafter snippets for all four are in [codemod-patterns.md](references\u002Fcodemod-patterns.md).\n\n### Step 4 — Update streaming callers (P67)\n\n`astream_log` still works in 1.0 but is soft-deprecated. The replacement is `astream_events(version=\"v2\")`:\n\n```python\n# BEFORE\nasync for patch in chain.astream_log({\"input\": \"hi\"}):\n    for op in patch.ops:\n        if op[\"op\"] == \"add\" and op[\"path\"].endswith(\"\u002Fstreamed_output\u002F-\"):\n            print(op[\"value\"], end=\"\")\n\n# AFTER\nasync for event in chain.astream_events({\"input\": \"hi\"}, version=\"v2\"):\n    if event[\"event\"] == \"on_chat_model_stream\":\n        print(event[\"data\"][\"chunk\"].content, end=\"\")\n```\n\nEvent names in v2: `on_chain_start`, `on_chain_end`, `on_chat_model_start`, `on_chat_model_stream`, `on_chat_model_end`, `on_tool_start`, `on_tool_end`. The payload under `data` is typed — `chunk` is an `AIMessageChunk`, not a raw string.\n\n### Step 5 — Fix `intermediate_steps` consumers (P42)\n\nIf any code iterates `result[\"intermediate_steps\"]` and reads `.tool` \u002F `.tool_input`, it breaks silently in 1.0 — the tuples now hold `ToolCall` dicts, not `AgentAction` objects. The 1.0 equivalent reads from graph state:\n\n```python\n# BEFORE\nfor action, observation in result[\"intermediate_steps\"]:\n    log(action.tool, action.tool_input, observation)\n\n# AFTER\nfor msg in result[\"messages\"]:\n    for tc in getattr(msg, \"tool_calls\", []) or []:\n        log(tc[\"name\"], tc[\"args\"])   # .tool -> \"name\", .tool_input -> \"args\"\n```\n\n`ToolCall` dict keys are `name`, `args`, `id`. There is no `tool` or `tool_input` accessor anywhere in 1.0.\n\n### Step 6 — Gate on deprecation-as-error tests\n\nTurn `DeprecationWarning` into a test failure so any surviving 0.3 pattern surfaces before the rollout:\n\n```bash\npytest -W error::DeprecationWarning\n```\n\nDo not promote to staging while this is red. Re-run the Step 1 greps — they should now return zero hits outside intentionally-pinned 0.3 test fixtures.\n\n### Step 7 — Phased rollout on production traffic\n\nDeploy behind a feature flag (`LANGCHAIN_1_0_ENABLED`), canary at 1%, and ramp to 100% over 2–4 hours with a 15-minute soak at each step. The rollback is always \"flip the flag off\" — not a redeploy. Full playbook (shadow traffic in staging, dual-write for persistent chat histories, per-phase exit criteria) is in [phased-rollout-playbook.md](references\u002Fphased-rollout-playbook.md).\n\n## Output\n\n- `requirements.txt` pinning all six 1.0 packages with the `anthropic >= 0.40` peer-pin (P66).\n- `requirements.lock.pre-1.0.txt` in the repo root for five-minute rollback.\n- Per-module git commits referencing pain codes (e.g. `refactor: migrate P39 LLMChain in billing-summariser to LCEL`).\n- `langchain-0.3-hits.txt` work-list returning zero non-test hits on re-run.\n- `pytest -W error::DeprecationWarning` green on the migration branch.\n- Feature-flagged production cutover at 100%, flag removed after a full day of soak.\n\n## Error Handling\n\n| Error | Cause | Fix |\n|---|---|---|\n| `ImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'` | **P38** — provider imports moved to partner packages | `from langchain_openai import ChatOpenAI` |\n| `ImportError: cannot import name 'LLMChain' from 'langchain.chains'` | **P39** — `LLMChain` removed | Replace with LCEL: `prompt \\| llm \\| StrOutputParser()` |\n| `AttributeError: 'ConversationBufferMemory' object has no attribute 'save_context'` | **P40** — memory classes removed from the public API | Swap for LangGraph `MemorySaver` \u002F `SqliteSaver` with a `thread_id` |\n| `AttributeError: module 'langchain.agents' has no attribute 'initialize_agent'` | **P41** — legacy agent constructor removed | `from langgraph.prebuilt import create_react_agent` |\n| `AttributeError: 'ToolCall' object has no attribute 'tool'` | **P42** — tuple shape changed, fields renamed | Read `tc[\"name\"]` and `tc[\"args\"]` instead of `.tool` \u002F `.tool_input` |\n| `AttributeError: module 'anthropic' has no attribute 'AsyncAnthropic'` | **P66** — `langchain-anthropic 1.0` needs `anthropic >= 0.40` | Pin `anthropic>=0.40,\u003C1` in the same commit as the `langchain-anthropic` bump |\n| `DeprecationWarning: astream_log is deprecated; use astream_events(version=\"v2\")` | **P67** — soft deprecation | Switch to `astream_events(version=\"v2\")` and update event-name handling |\n\n## Examples\n\n### Example 1 — Minimal LLMChain to LCEL\n\n```python\n# BEFORE (0.3)\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts import ChatPromptTemplate\nfrom langchain.chains import LLMChain\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nprompt = ChatPromptTemplate.from_messages([(\"system\", \"Summarise in one line.\"), (\"user\", \"{text}\")])\nchain = LLMChain(llm=llm, prompt=prompt)\nprint(chain.run(text=\"LangChain 1.0 removed LLMChain.\"))\n\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_core.output_parsers import StrOutputParser\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nprompt = ChatPromptTemplate.from_messages([(\"system\", \"Summarise in one line.\"), (\"user\", \"{text}\")])\nchain = prompt | llm | StrOutputParser()\nprint(chain.invoke({\"text\": \"LangChain 1.0 removed LLMChain.\"}))\n```\n\n### Example 2 — Stateful agent with LangGraph checkpointer\n\n```python\n# AFTER (1.0)\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.tools import tool\nfrom langgraph.prebuilt import create_react_agent\nfrom langgraph.checkpoint.memory import MemorySaver    # use SqliteSaver \u002F PostgresSaver in prod\n\n@tool\ndef add(a: int, b: int) -> int:\n    \"\"\"Add two integers.\"\"\"\n    return a + b\n\nllm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\nagent = create_react_agent(llm, [add], checkpointer=MemorySaver())\n\nconfig = {\"configurable\": {\"thread_id\": \"user-42\"}}\nr1 = agent.invoke({\"messages\": [(\"user\", \"What's 2 + 3?\")]}, config=config)\nr2 = agent.invoke({\"messages\": [(\"user\", \"And plus 10?\")]}, config=config)   # remembers \"5\"\nprint(r2[\"messages\"][-1].content)\n```\n\n### Example 3 — Rollback pin\n\nIf Phase 5 of the rollout regresses and the feature flag is already off:\n\n```bash\ngit checkout main\npip install -r requirements.lock.pre-1.0.txt\npytest                      # confirm green on the rollback pin\n# deploy\n```\n\n## Resources\n\n- [LangChain migration guide](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fversions\u002Fmigrating\u002F)\n- [LangChain release policy](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fversions\u002Frelease_policy\u002F)\n- [LangGraph prebuilt `create_react_agent`](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Fprebuilt\u002F)\n- [`astream_events` v2 reference](https:\u002F\u002Fpython.langchain.com\u002Fdocs\u002Fconcepts\u002Fstreaming\u002F)\n- [Breaking changes matrix](references\u002Fbreaking-changes-matrix.md) — all 7 named changes mapped to pain codes\n- [Codemod patterns](references\u002Fcodemod-patterns.md) — before\u002Fafter for the 7 most common migrations\n- [Phased rollout playbook](references\u002Fphased-rollout-playbook.md) — shadow traffic, dual-write, rollback\n- [Migration detection](references\u002Fmigration-detection.md) — pre-flight grep audit\n- [One-pager](references\u002Fone-pager.md) — executive summary\n",{"name":5,"tags":24,"author":32,"license":15,"version":33,"description":34,"allowed-tools":35,"compatible-with":36},[25,26,27,28,29,30,31],"saas","langchain","langgraph","python","langchain-1.0","migration","upgrade","Jeremy Longshore \u003Cjeremy@intentsolutions.io>","2.0.0","Migrate a LangChain 0.3.x Python codebase to LangChain 1.0 \u002F LangGraph 1.0 without\nbreaking production — named breaking changes, codemod patterns, and a phased rollout.\nUse when upgrading LangChain or LangGraph from 0.2 or 0.3 to 1.0, when hitting\nImportError after an upgrade, or when preparing a migration PR.\nTrigger with \"langchain 1.0 migration\", \"langchain upgrade\", \"LLMChain removed\",\n\"initialize_agent removed\", \"ConversationBufferMemory removed\", \"astream_log deprecated\",\n\"langchain-anthropic 1.0\".\n","Read, Write, Edit, Grep, Bash(python:*)","claude-code, codex","main","99825ad3f3bcc6597ddcc7294a14e6e922f2b67b","skills\u002Fsaas-packs--langchain-py-pack--langchain-upgrade-migration",0,"https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills","https:\u002F\u002Fgithub.com\u002Fjukeyman","https:\u002F\u002FRJBUSINESSSOLUTIONS.ORG","Credit and Finance Expert | Developer\r\n\r\nI'm Rick Jefferson, a seasoned credit and finance expert with over a decade of experience in financial literacy,","2026-07-13 07:03:29",{"source":8,"skillName":5,"commands":47,"prompt":57,"zipAvailable":58},[48,51,54],{"tool":49,"command":50},"npx","npx skills add jukeyman\u002Fjukeyman-skills --skill langchain-upgrade-migration",{"tool":52,"command":53},"bunx","bunx skills add jukeyman\u002Fjukeyman-skills --skill langchain-upgrade-migration",{"tool":55,"command":56},"pnpm","pnpm dlx skills add jukeyman\u002Fjukeyman-skills --skill langchain-upgrade-migration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--langchain-py-pack--langchain-upgrade-migration\u002FSKILL.md",true,[],[61,68,75,82,89,97],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M79ANS2SM329NEP5ZCX106RR","zustand-store-creator","Create zustand store creator operations. Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category. Use when working with zustand store creator functionality. Trigger with phrases like \"zustand store creator\", \"zustand creator\", \"zustand\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M79AMZKP4YDEZ7EHG1Y7PP74","zero-trust-config-helper","Configure with zero trust config helper operations. Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category. Use when configuring systems or services. Trigger with phrases like \"zero trust config helper\", \"zero helper\", \"zero\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M79AMJSBCEJQNBTYNAHYN5HM","zapier-integration-helper","Assist with zapier integration helper operations. Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category. Use when working with APIs or building integrations. Trigger with phrases like \"zapier integration helper\", \"zapier helper\", \"zapier\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M79AHJZGVMARS13VFQYRR1MP","yaml-config-validator","Validate yaml config validator operations. Auto-activating skill for DevOps Basics.\nTriggers on: yaml config validator, yaml config validator\nPart of the DevOps Basics skill category. Use when configuring systems or services. Trigger with phrases like \"yaml config validator\", \"yaml validator\", \"yaml\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fyaml-config-validator\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":93,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M79AHGDZRN0020RDQSQDPAM8","xvary-stock-research","Thesis-driven equity analysis from public SEC EDGAR and market data; \u002Fanalyze, \u002Fscore, \u002Fcompare workflows with bundled Python tools (Claude Code, Cursor, Codex).","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M79AHCYJ9FV9RMHQ24HDRN33","xss-vulnerability-scanner","Scan xss vulnerability scanner operations. Auto-activating skill for Security Fundamentals.\nTriggers on: xss vulnerability scanner, xss vulnerability scanner\nPart of the Security Fundamentals skill category. Use when working with xss vulnerability scanner functionality. Trigger with phrases like \"xss vulnerability scanner\", \"xss scanner\", \"xss\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxss-vulnerability-scanner\u002FSKILL.md",[],[]]