Skip to content

Add ecosystem bridge adapters for LangChain and LlamaIndex #82

@dgenio

Description

@dgenio

Context / Problem

MCP developers also use LangChain, LlamaIndex, and other agent frameworks. These ecosystems have their own tool abstractions (BaseTool in LangChain, FunctionTool in LlamaIndex). If users can't bring their existing tools into ChainWeaver — or use ChainWeaver tools in their existing frameworks — adoption is blocked by ecosystem lock-in.

ChainWeaver should act as a compilation layer that sits on top of any tool ecosystem, not compete with it.

Proposal

Provide thin, bidirectional adapter functions for major frameworks:

LangChain Adapter

from chainweaver.integrations.langchain import from_langchain_tool, to_langchain_tool

# Import LangChain tool into ChainWeaver
cw_tool = from_langchain_tool(my_langchain_tool)

# Export ChainWeaver tool to LangChain
lc_tool = to_langchain_tool(my_cw_tool)

LlamaIndex Adapter

from chainweaver.integrations.llamaindex import from_llamaindex_tool, to_llamaindex_tool

cw_tool = from_llamaindex_tool(my_llama_tool)
llama_tool = to_llamaindex_tool(my_cw_tool)

Core capabilities:

  1. from_langchain_tool() — convert LangChain BaseTool → ChainWeaver Tool (extract schemas from Pydantic args_schema, wrap _run() as fn)
  2. to_langchain_tool() — convert ChainWeaver Tool → LangChain BaseTool
  3. from_llamaindex_tool() — convert LlamaIndex FunctionTool → ChainWeaver Tool
  4. to_llamaindex_tool() — convert ChainWeaver Tool → LlamaIndex FunctionTool
  5. Batch conversionfrom_langchain_toolkit(toolkit) to convert all tools in a LangChain toolkit at once

Acceptance Criteria

  • chainweaver.integrations.langchain module with from_langchain_tool() and to_langchain_tool()
  • chainweaver.integrations.llamaindex module with from_llamaindex_tool() and to_llamaindex_tool()
  • Framework packages are optional dependencies: pip install chainweaver[langchain], pip install chainweaver[llamaindex]
  • Import of integration modules raises clear error if framework is not installed
  • Converted tools preserve: name, description, input/output schemas, callable behavior
  • Converted tools pass ChainWeaver schema validation (input + output)
  • Round-trip works: to_langchain_tool(from_langchain_tool(lc_tool)) produces equivalent tool
  • Tests cover: conversion in both directions, schema preservation, execution, missing dependency error
  • Example scripts demonstrate building a ChainWeaver flow from LangChain tools

Implementation Notes

  • LangChain BaseTool has args_schema (Pydantic model) and _run() method — these map directly to ChainWeaver Tool(input_schema=..., fn=...)
  • LangChain output is typically unstructured (string). May need a wrapper that parses output into a dict matching output_schema.
  • LlamaIndex FunctionTool uses fn_schema for input schema.
  • Pin framework version ranges loosely to avoid breaking on minor updates.
  • Each integration should be in its own submodule for clean optional imports.

Dependencies

Tasks

  • Create chainweaver/integrations/__init__.py
  • Create chainweaver/integrations/langchain.py with bidirectional adapters
  • Create chainweaver/integrations/llamaindex.py with bidirectional adapters
  • Add optional dependencies to pyproject.toml ([langchain], [llamaindex])
  • Add unit tests with mocked framework classes (avoid requiring full framework install in CI)
  • Add example: examples/langchain_integration.py
  • Document integrations in README

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-friendlyDesigned for AI-assisted implementationarea:integrationsExternal system integrationscomplexity:averageModerate effort, some design neededpriority:highMust address first within the milestonesize:MMedium effort (1-3 days)type:featureNew feature or capability

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions