Skip to content

Implement LangChain BaseChatModel wrapper backed by mellea #446

Closed

Description

@akihikokuroda
No description provided.

Activity

  1. psschwei commented on Feb 10, 2026

    @psschwei
    Contributor

    Summary

    Create a LangChain-compatible ChatModel class that wraps mellea's session for chat-based use cases. This is the primary integration point for most LangChain users.

    Problem / Opportunity

    Most modern LLM applications use chat interfaces rather than raw completions. LangChain's BaseChatModel is the standard abstraction for chat-based interactions. Without this integration, LangChain users cannot use mellea for their primary use cases including agents, RAG pipelines, and conversational applications.

    User Story / Use Case

    As a LangChain developer building chat applications, I want to use mellea's chat model wrapper so that I can leverage mellea's optimizations in my agents and conversational pipelines.

    Proposed Solution (High-level)

    Create mellea/integrations/langchain/chat.py containing:

    • MelleaChatModel(BaseChatModel) implementing LangChain's chat interface
    • Support for _generate(), _agenerate(), _stream(), _astream() methods
    • Bidirectional message format conversion (LangChain messages <-> mellea Messages)
    • Tool binding support via bind_tools()

    Scope

    In scope:

    • MelleaChatModel class with all standard ChatModel methods
    • Message format conversion (LangChain <-> mellea)
    • Tool binding and tool calling support
    • Streaming with LangChain callbacks
    • Image/multimodal support where backends support it

    Out of scope:

    • Custom message types beyond standard LangChain types
    • LangChain-specific memory management (use mellea Context instead)
    • LCEL-specific optimizations

    Acceptance Criteria

    • Passes LangChain's standard ChatModel tests
    • Message format conversion is lossless for common cases
    • Tool calling works with LangChain's tool interface
    • Streaming works with LangChain callbacks
    • Image/multimodal support works where backends support it
  2. akihikokuroda commented on Feb 11, 2026

    @akihikokuroda
    ContributorAuthor

    Is it OK to make a project in mellea/integrations/langchain/?

    langchain/
    ├── README.md                          # This file
    ├── GETTING_STARTED.md                 # Quick start guide
    ├── pyproject.toml                     # Project configuration
    ├── src/
    │   └── mellea_langchain/
    │       ├── __init__.py               # Package exports
    │       ├── chat_model.py             # MelleaChatModel class
    │       ├── message_conversion.py     # Message format conversion
    │       └── tool_conversion.py        # Tool calling utilities
    ├── tests/
    │   ├── test_chat_model.py            # Chat model tests
    │   ├── test_message_conversion.py    # Message conversion tests
    │   └── test_tool_conversion.py       # Tool conversion tests
    └── examples/
        ├── basic_usage.py                # Basic example
        ├── streaming_example.py          # Streaming example
        ├── tools_example.py              # Tool calling example
        ├── langchain_chain.py            # Chain example
        └── requirements_strategy_example.py  # Requirements/validation example
    
  3. bjhargrave commented on Feb 11, 2026

    @bjhargrave
    Contributor

    We also need support for with_structured_output for constrained decoding.

    For consistency with other chat model subclasses, I suggest it be called ChatMellea.

    I was also thinking we may want to allow the ChatMellea constructor to take a BaseChatModel argument which would then be used by a Mellea backend implementation to communicate with the model. This would then allow the user to use any langchain integration to provide the model support.

    chat_watsonx = ChatWatsonX(...)
    chat_mellea = ChatMellea(llm=chat_watsonx, ...)

    I am interested in helping this effort as I need this support for recipe and workshop development showing Mellea using in existing langgraph/langchain programs.

    In discussing this idea with @nrfulton, he suggested this langchain integration would be a separate git repo and thus separate python package (e.g. langchain-mellea) to avoid dragging langchain dependencies into the mellea core package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions