SuperAPI AI 工具集

langchain-upgrade-migration

智能体与模型

查看项目

更新于 10-15 23:27

技能介绍

用途:把 LangChain 0.3.x 的 Python 代码库迁移到 LangChain 1.0 / LangGraph 1.0,避免升级后导入即崩溃。资料列出 7 项命名破坏性变更(P38–P42、P66、P67),典型中型服务会涉及 10–100 个文件。

主要能力:预检 grep 审计生成迁移工作清单;六个包协同升级并锁定版本;针对被移除 API 的 codemod 改写;流式调用从 astream_log 迁移到 astream_events(version="v2");intermediate_steps 消费方改读 ToolCall 的 name/args;以 DeprecationWarning 作为测试失败门禁;带特性开关的分阶段灰度上线与回滚。

必要用法:先跑 grep 审计,例如 grep -rn "from langchain.chat_models|from langchain.llms" --include="*.py" .;再同一次提交内升级六个包:pip install -U "langchain>=1.0,<2" "langchain-core>=0.3,<0.4" "langchain-openai>=1.0" "langchain-anthropic>=1.0" "langgraph>=1.0,<2" "anthropic>=0.40,<1",并执行 pip freeze > requirements.lock.pre-1.0.txt 以便回滚。随后按 P38 导入迁移、P39 LLMChain 改 LCEL、P41 initialize_agent 改 create_react_agent、P40 记忆改 LangGraph checkpointer 的顺序改写,最后运行 pytest -W error::DeprecationWarning。

适用场景:使用 LangChain 0.3.x 且需要升级到 1.0 的 Python 服务,尤其是使用 LLMChain、ConversationBufferMemory、initialize_agent 或持久化会话历史的项目。

限制:要求 Python 3.10+、可用的测试套件、干净的 Git 工作树,以及 staging 流量或请求镜像;若会话持久化在 Redis/Postgres/DynamoDB,Phase 2 前需快照,因为 LangGraph checkpointer 使用新 schema,简单回滚会丢数据。资料未提供具体收费、价格或平台信息。