Skip to content

[Refactor] Replace LangChain with LangGraph: Node/Edge Graph and Tool Call Integration #38

@karthik18495

Description

@karthik18495

Summary

Refactor the RAG4EIC codebase to use LangGraph instead of LangChain for orchestrating the LLM workflow. LangGraph enables more flexible, graph-based workflows using nodes, edges, and tool calls. This will improve modularity, maintainability, and enable advanced RAG behaviors (e.g., conditional tool use, branching, multi-hop reasoning).

Requirements

  • Replace LangChain chains/runnables with LangGraph graphs (nodes and edges):
    • Each node represents an atomic operation (e.g., LLM prompt, retriever, tool call, response formatting)
    • Edges control data flow and can branch based on conditions (e.g., decide whether to call a retriever or respond directly)
  • Integrate tool calls (e.g., retrieval, calculator, custom tools) within the graph
  • Support for:
    • User message input node
    • Decide node (determine if retrieval is needed)
    • Retriever node(s) (arxiv, indico, or both)
    • LLM response node
    • Tool-calling node (for advanced queries)
    • Output formatting node
  • Ensure all existing RAG features are mapped to graph nodes/edges (e.g., feedback, trace logging, source attribution)

Implementation Plan

  1. Research LangGraph

  2. Design the Graph Structure

    • Draw out the flow as a directed graph:
      • Start → User Input Node → Decide Node
        • If retrieval needed → Retriever Node(s) → LLM Node → Output Node
        • If not → LLM Node → Output Node
      • Add tool call node for specialized tools (e.g., calculator, DB query)
    • Allow branching for arxiv/indico/both retrievers based on user selection
    • Add nodes for logging, feedback, and error handling
  3. Refactor Chains to Graph Nodes

    • Convert each "chain" or function in LangChain to a node in LangGraph
    • Wire up edges for data flow, including conditional branches (if/else)
  4. Integrate Tool Calls

    • Implement tool-calling pattern per LangGraph's API (e.g., for retrieval, calculators, or custom actions)
    • Register tools and expose them as nodes in the graph
  5. Testing & Migration

    • Write unit/integration tests for each node and the overall graph
    • Ensure all features work as before (or better)
    • Migrate streamlit UI to use LangGraph backend
  6. Documentation

    • Document the new architecture and graph structure
    • Add diagrams showing node/edge layout
    • Provide migration/usage instructions for contributors

References

Future Improvements

  • Add more tool call support (e.g., web search, citation generator)
  • Enable multi-agent or multi-hop reasoning via graph branches
  • Visualize the workflow graphically in documentation or UI

Metadata

Metadata

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions