Skip to content

Migrate to latest LangGraph/LangChain: fix deprecated APIs/imports and unblock dependency upgrades #341

@ansh-info

Description

@ansh-info

Summary

LangGraph/LangChain have evolved significantly and the current codebase relies on deprecated APIs and imports. The app currently only runs against pinned legacy versions. We need a structured migration to the latest LangGraph/LangChain stack, update imports/usages, and keep behavior stable.

Current Problems (Concrete Symptoms)

  • Deprecated agent factory: create_react_agent is deprecated and moved to langchain.agents.create_agent.
  • Deprecated tracer import: langchain.callbacks.tracers.LangChainTracer has moved to langchain_core.tracers.langchain.LangChainTracer.
  • Removed chains modules: langchain.chains.* no longer exists in newer LangChain; graphrag_reasoning.py imports langchain.chains.combine_documents and langchain.chains.retrieval which now break with ModuleNotFoundError.
  • Text splitter moved: langchain.text_splitter.RecursiveCharacterTextSplitter moved to langchain_text_splitters.
  • LangGraph API drift: create_react_agent, ToolNode usage, and state handling differ across versions. The code currently assumes the old prebuilt API.

Impact

  • Code only runs with pinned legacy versions of LangChain/LangGraph.
  • Upgrading to secure versions breaks runtime imports.
  • Pip-audit fails unless we keep legacy versions or ignore CVEs.

Goals

  • Migrate to latest supported LangGraph + LangChain versions.
  • Remove all deprecated imports and APIs.
  • Keep business logic intact.
  • Ensure tests and CI remain green.
  • Allow dependency upgrades without pinning legacy versions.

Migration Scope (Known Hotspots)

  • Agents:
    • talk2biomodels/agents/t2b_agent.py
    • talk2knowledgegraphs/agents/t2kg_agent.py
    • talk2scholars/agents/*
    • talk2cells/agents/scp_agent.py
  • Tools:
    • talk2knowledgegraphs/tools/graphrag_reasoning.py (chains & splitters)
  • Streamlit apps:
    • app/frontend/utils/streamlit_utils.py
    • app/frontend/streamlit_app_talk2cells.py

Suggested Plan

  1. Upgrade dependencies (LangChain/LangGraph stack + related) and regenerate lock.
  2. Replace deprecated APIs/imports:
    • create_react_agentlangchain.agents.create_agent
    • langchain.callbacks.tracers.LangChainTracer
      langchain_core.tracers.langchain.LangChainTracer
    • langchain.chains.* → new retrieval/LLM flow
    • langchain.text_splitterlangchain_text_splitters
  3. Refactor ToolNode usage where required by the new API.
  4. Run full test suite, fix breakages.
  5. Update CI pipelines and remove legacy pinning.

Acceptance Criteria

  • App runs on latest LangChain/LangGraph without deprecation warnings or import errors.
  • Pip-audit passes without ignoring LangChain CVEs.
  • Tests and CI pass at 100% coverage where required.

Notes

This migration should be done in stages to avoid breaking production, and each step should be verified against tests and Streamlit runtime.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions