Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Oct 20, 2025

Important

Adds Langchain v1.0+ support with version detection and import updates, but has a critical dependency issue in pyproject.toml.

  • Behavior:
    • Adds version detection in CallbackHandler.py to support Langchain v1.0+ and v0.x.
    • Updates imports for v1 from langchain_core.* instead of langchain.schema.* and langchain.callbacks.base.
    • Changes Serializable import path in serializer.py.
  • Tests:
    • Updates test files to use v1 import paths and .invoke() API.
    • Removes deprecated chain-based tests.
  • Dependencies:
    • Updates pyproject.toml to require langchain >= 1 and langgraph >= 1.
    • Bumps minimum Python version to 3.10+.
  • Critical Issue:
    • langchain removed from optional dependencies but still referenced in extras, causing pip install langfuse[langchain] to fail.

This description was created by Ellipsis for 85d411b. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Overview

Updated On: 2025-10-20 10:03:22 UTC

Summary

Adds Langchain v1.0+ support to the Langfuse Python SDK by implementing version detection and conditional imports in the CallbackHandler, maintaining backward compatibility with Langchain v0.x.

Key Changes

  • Version Detection: Added langchain.__version__.startswith("1") check to conditionally import from appropriate modules
  • Import Path Updates: For v1, imports from langchain_core.agents, langchain_core.callbacks, langchain_core.documents instead of langchain.schema.* and langchain.callbacks.base
  • Serializer Update: Changed Serializable import from langchain.load.serializable to langchain_core.load.serializable
  • Test Migration: Updated test files to use v1 import paths (langchain_core.prompts, langchain.messages) and modern API (.invoke() instead of direct call)
  • Dependency Updates: Updated pyproject.toml to require langchain >= 1 and langgraph >= 1 in dev dependencies; bumped minimum Python version to 3.10+

Critical Issue Found

BLOCKING BUG: langchain was removed from optional dependencies in [tool.poetry.dependencies] but is still referenced in [tool.poetry.extras]. This will cause pip install langfuse[langchain] to fail. The dependency must be added back as langchain = { version = ">=1", optional = true }.

Confidence Score: 0/5

  • This PR has a critical bug that will break package installation and must not be merged.
  • Score is 0 because langchain dependency was removed from optional dependencies but still referenced in extras, causing pip install langfuse[langchain] to fail. While the code changes for v1 support are well-implemented, this packaging bug is a blocker that will break user installations.
  • pyproject.toml requires immediate fix - langchain must be added back as optional dependency

Important Files Changed

File Analysis

Filename Score Overview
pyproject.toml 0/5 CRITICAL: langchain removed from optional dependencies but still referenced in extras, breaking pip installs. Python version bumped to 3.10+.
langfuse/langchain/CallbackHandler.py 4/5 Added version detection to support both Langchain v0 and v1 with appropriate imports. Clean implementation with backward compatibility.
tests/test_langchain.py 4/5 Updated imports for v1 compatibility. Removed deprecated chain-based tests (LLMChain, ConversationChain). Updated to use .invoke() API.

Sequence Diagram

sequenceDiagram
    participant User
    participant LangfuseSDK
    participant CallbackHandler
    participant Langchain
    participant LangchainCore
    
    User->>LangfuseSDK: pip install langfuse[langchain]
    LangfuseSDK->>User: Install with langchain dependency
    
    User->>CallbackHandler: Import CallbackHandler
    CallbackHandler->>Langchain: Check langchain.__version__
    
    alt Langchain v1.x
        Langchain-->>CallbackHandler: Version starts with "1"
        CallbackHandler->>LangchainCore: Import from langchain_core.agents
        CallbackHandler->>LangchainCore: Import from langchain_core.callbacks
        CallbackHandler->>LangchainCore: Import from langchain_core.documents
        CallbackHandler->>LangchainCore: Import from langchain_core.messages
        CallbackHandler->>LangchainCore: Import from langchain_core.outputs
    else Langchain v0.x
        Langchain-->>CallbackHandler: Version starts with "0"
        CallbackHandler->>Langchain: Import from langchain.callbacks.base
        CallbackHandler->>Langchain: Import from langchain.schema.agent
        CallbackHandler->>Langchain: Import from langchain.schema.document
        CallbackHandler->>LangchainCore: Import from langchain_core.messages
        CallbackHandler->>LangchainCore: Import from langchain_core.outputs
    end
    
    CallbackHandler-->>User: Handler ready
    
    User->>Langchain: chat.invoke(messages, callbacks=[handler])
    Langchain->>CallbackHandler: Trigger callback methods
    CallbackHandler->>LangfuseSDK: Create spans/generations via OTel
    LangfuseSDK-->>User: Track LLM operations
Loading

@hassiebp hassiebp linked an issue Oct 20, 2025 that may be closed by this pull request
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. pyproject.toml, line 37-38 (link)

    logic: langchain dependency removed from [tool.poetry.dependencies] but [tool.poetry.extras] still references it. Users installing with pip install langfuse[langchain] will fail.

    Add langchain back as optional dependency:

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@hassiebp hassiebp merged commit 671b2d3 into main Oct 20, 2025
12 checks passed
@hassiebp hassiebp deleted the add-langchain-v1-support branch October 20, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Langchain v1 support

2 participants