Overview
LangChain is a framework for developing applications powered by large language models. The LiveKit LangChain plugin allows you to integrate existing LangGraph workflows as LLMs in your voice AI applications.
Quick reference
This section includes a basic usage example and some reference material. For links to more detailed documentation, see Additional resources.
Installation
Install the LiveKit LangChain plugin from PyPI:
pip install "livekit-plugins-langchain~=1.1"
Usage
Use LangGraph workflows within an AgentSession
by wrapping them with the LLMAdapter
. For example, you can use this LLM in the Voice AI quickstart.
from langgraph.graph import StateGraphfrom livekit.agents import AgentSession, Agentfrom livekit.plugins import langchain# Define your LangGraph workflowdef create_workflow():workflow = StateGraph(...)# Add your nodes and edgesreturn workflow.compile()# Use the workflow as an LLMsession = AgentSession(llm=langchain.LLMAdapter(graph=create_workflow()),# ... stt, tts, vad, turn_detection, etc.)
The LLMAdapter
automatically converts the LiveKit chat context to LangChain messages. The mapping is as follows:
system
anddeveloper
messages toSystemMessage
user
messages toHumanMessage
assistant
messages toAIMessage
Parameters
This section describes the available parameters for the LLMAdapter
. See the plugin reference for a complete list of all available parameters.
The LangGraph workflow to use as an LLM. Must be a locally compiled graph. To learn more, see Graph Definitions.
Configuration options for the LangGraph workflow execution. This can include runtime configuration, callbacks, and other LangGraph-specific options. To learn more, see RunnableConfig.
Additional resources
The following resources provide more information about using LangChain with LiveKit Agents.
Python package
The livekit-plugins-langchain
package on PyPI.
Plugin reference
Reference for the LangChain LLM adapter.
GitHub repo
View the source or contribute to the LiveKit LangChain plugin.
LangChain docs
LangChain documentation and tutorials.
LangGraph docs
LangGraph documentation for building stateful workflows.
Voice AI quickstart
Get started with LiveKit Agents and LangChain.