Using with Langchain 🦜🔗#

LlamaIndex provides both Tool abstractions for a Langchain agent as well as a memory module.

The API reference of the Tool abstractions + memory modules are here.

Use any data loader as a Langchain Tool#

LlamaIndex allows you to use any data loader within the LlamaIndex core repo or in LlamaHub as an “on-demand” data query Tool within a LangChain agent.

The Tool will 1) load data using the data loader, 2) index the data, and 3) query the data and return the response in an ad-hoc manner.


Use a query engine as a Langchain Tool#

LlamaIndex provides Tool abstractions so that you can use a LlamaIndex query engine along with a Langchain agent.

For instance, you can choose to create a “Tool” from an QueryEngine directly as follows:

from llama_index.core.langchain_helpers.agents import (

tool_config = IndexToolConfig(
    name=f"Vector Index",
    description=f"useful for when you want to answer queries about X",
    tool_kwargs={"return_direct": True},

tool = LlamaIndexTool.from_tool_config(tool_config)

Llama Demo Notebook: Tool + Memory module#

We provide another demo notebook showing how you can build a chat agent with the following components.

  • Using LlamaIndex as a generic callable tool with a Langchain agent

  • Using LlamaIndex as a memory module; this allows you to insert arbitrary amounts of conversation history with a Langchain chatbot!

Please see the notebook here.