Looking for the JS/TS version? Check out LangChain.js.
To help you ship LangChain apps to production faster, check out LangSmith. LangSmith is a unified developer platform for building, testing, and monitoring LLM applications.
pip install langchain-classic
Legacy chains, langchain-community re-exports, indexing API, deprecated functionality, and more.
In most cases, you should be using the main langchain package.
For full documentation, see the API reference. For conceptual guides, tutorials, and examples on using LangChain, see the LangChain Docs.
See our Releases and Versioning policies.
As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
For detailed information on how to contribute, see the Contributing Guide.
A utility to experiment with and compare the performance of different models.
Base Single Action Agent class.
Base Multi Action Agent class.
Base class for parsing agent output into agent action/finish.
Base class for parsing agent output into agent actions/finish.
Agent powered by Runnables.
Agent powered by Runnables.
Tool that just returns the query.
Agent that is using tools.
Tool that is run when invalid tool name is encountered by agent.
Chat prompt template for the agent scratchpad.
Iterator for AgentExecutor.
Parses a message into agent actions/finish.
Parses self-ask style LLM calls.
Parses a message into agent action/finish.
Parses ReAct-style LLM calls that have a single tool input in json format.
Parses tool invocations and final answers from XML-formatted agent output.
Parses ReAct-style LLM calls that have a single tool input.
Tool agent action.
Parses a message into agent actions/finish.
Parses tool invocations and final answers in JSON format.
Output parser for the structured chat agent.
Output parser with retries for the structured chat agent.
Memory used to save agent output AND intermediate steps.
Output parser for the conversational agent.
Configuration for a chain to use in MRKL system.
MRKL Output parser for the chat agent.
Information about a VectorStore.
Toolkit for interacting with a VectorStore.
Toolkit for routing between Vector Stores.
Output parser for the ReAct agent.
AgentFinish with run and thread metadata.
AgentAction with info needed to submit custom tool output to existing run.
Run an OpenAI Assistant.
Output parser for the chat agent.
Output parser for the conversational agent.
Wraps a store with key and value encoders/decoders.
BaseStore interface that works on the local file system.
Parse the output of an LLM call to a datetime.
Parse the output of an LLM call to a boolean.
Parse an output that is one of a set of values.
Schema for a response from a structured output parser.
Parse the output of an LLM call to a structured output.
Parse the output of an LLM call using a regex.
Parse the output of an LLM call into a Dictionary using a regex.
Retry chain input for RetryOutputParser.
Retry chain input for RetryWithErrorOutputParser.
Wrap a parser and try to fix parsing errors.
Wrap a parser and try to fix parsing errors.
Parse an output using Pandas DataFrame format.
Parse YAML output using a Pydantic model.
Input for the retry chain of the OutputFixingParser.
Wrap a parser and try to fix parsing errors.
Combine multiple output parsers into one.
A function description for ChatOpenAI.
A runnable that routes to the selected function.
An instance of a runnable stored in the LangChain Hub.
Callback handler that returns an async iterator.
Callback handler that returns an async iterator.
Callback handler for streaming in agents.
Tracer that logs via the input Logger.
Extract items to evaluate from the run object.
Extract items to evaluate from the run object.
Extract items to evaluate from the run object from a chain.
Map an input to the tool.
Map an example, or row in the dataset, to the inputs of an evaluation.
Evaluate Run and optional examples.
Configuration for a given run evaluator.
Configuration for a run evaluator that only requires a single key.
Configuration for a run evaluation.
Configuration for a reference-free criteria evaluator.
Configuration for a labeled (with references) criteria evaluator.
Configuration for an embedding distance evaluator.
Configuration for a string distance evaluator.
Configuration for a QA evaluator.
Configuration for a context-based QA evaluator.
Configuration for a context-based QA evaluator.
Configuration for a json validity evaluator.
Configuration for a json equality evaluator.
Configuration for an exact match string evaluator.
Configuration for a regex match string evaluator.
Configuration for a score string evaluator.
Configuration for a labeled score string evaluator.
A simple progress bar for the console.
Raised when the input format is invalid.
A dictionary of the results of a single test run.
Your architecture raised an error.
Input for a chat model.
Interface for caching results from embedding models.
Simple Memory.
Combining multiple memories' data together.
Memory wrapper that is read-only and cannot be changed.
Conversation chat memory with token limit and vectordb backing.
Abstract base class for creating structured sequences of calls to components.
Pass input through a moderation endpoint.
Chain that transforms the chain output.
Chain where the outputs of one chain feed directly into next.
Simple chain where the outputs of one step feed directly into next.
Base class for prompt selectors.
Prompt collection that goes through conditionals.
Input type for ConversationalRetrievalChain.
Chain for chatting with an index.
Chain for chatting with a vector database.
Chain for interacting with Elasticsearch Database.
Output parser that parses a structured query.
A date in ISO 8601 format (YYYY-MM-DD).
A datetime in ISO 8601 format (YYYY-MM-DDTHH:MM:SS).
Transform a query string into an intermediate representation.
Information about a data source attribute.
Interface for loading the combine documents chain.
Class representing a single statement.
A question and its answer as a list of facts.
An answer to the question, with sources.
Output parser that checks if the output is finished.
Chain that generates questions from uncertain spans.
Flare chain.
Interface for loading the combine documents chain.
Question-answering with sources over an index.
Question-answering with sources over a vector database.
Interface for loading the combine documents chain.
Raise an ImportError if APIChain is used without langchain_community.
A typed dictionary containing information about elements in the viewport.
A crawler for web pages.
Input for a SQL Chain.
Input for a SQL Chain.
A route to a destination chain.
Chain that outputs the name of a destination chain and the inputs to it.
Use a single chain to route an input to one of multiple candidate chains.
Multi Retrieval QA Chain.
Parser for output of router chain in the multi-prompt chain.
Chain that uses embeddings to route between options.
Generate hypothetical document for query, and then embed that.
Interface for the combine_docs method.
Interface for the combine_docs method.
Base interface for chains combining documents.
Class for a constitutional principle.
The types of the evaluators.
A base class for evaluators that use an LLM.
String evaluator interface.
Compare the output of two models (or two outputs of the same model).
Interface for evaluating agent trajectories.
A named tuple containing the score and reasoning for a trajectory.
Trajectory output parser.
A chain for evaluating ReAct style agents.
LLM Chain for evaluating question answering.
LLM Chain for evaluating QA w/o GT based on context.
LLM Chain for evaluating QA using chain of thought reasoning.
LLM Chain for generating examples for question answering.
A Criteria to evaluate.
A parser for the output of the CriteriaEvalChain.
LLM Chain for evaluating runs against criteria.
Criteria evaluation chain that requires references.
Embedding Distance Metric.
Embedding distance evaluation chain.
Use embedding distances to score semantic difference between two predictions.
Distance metric to use.
Compute string distances between the prediction and the reference.
Compute string edit distances between two predictions.
Compute a regex match between the prediction and the reference.
Evaluate whether the prediction is valid JSON.
Json Equality Evaluator.
An evaluator that calculates the edit distance between JSON strings.
An evaluator that validates a JSON prediction against a JSON schema reference.
Compute an exact match between the prediction and the reference.
A parser for the output of the PairwiseStringEvalChain.
Pairwise String Evaluation Chain.
Labeled Pairwise String Evaluation Chain.
A parser for the output of the ScoreStringEvalChain.
A chain for scoring on a scale of 1-10 the output of a model.
A chain for scoring the output of a model on a scale of 1-10.
Enumerator of the types of search to perform.
Retriever that supports multiple embeddings per parent document.
Retrieve small chunks then retrieve their parent documents.
Retriever that wraps a base retriever and compresses the results.
Output parser for a list of lines.
Given a query, use an LLM to write a set of queries.
Retriever that merges the results of multiple retrievers.
Time Weighted Vector Store Retriever.
Retriever that ensembles the multiple retrievers.
Given a query, use an LLM to re-phrase it.
Self Query Retriever.
Document compressor that uses Zero-Shot Listwise Document Reranking.
Document compressor that uses a pipeline of Transformers.
Embeddings Filter.
Document compressor that uses CrossEncoder for reranking.
Parse outputs that could return a null string of some sort.
LLM Chain Extractor.
Filter that drops documents that aren't relevant to the query.
Wrapper around a VectorStore for easy access.
Logic for creating indexes.
Table used to keep track of when a key was last updated.
A SQL Alchemy based implementation of the record manager.
Abstract base class for memory in Chains.
Base class for single action agents.
Agent that calls the language model and deciding the action.
An enum for agent types.
Structured Chat Agent.
Agent driven by OpenAIs function powered API.
Agent for the self-ask-with-search paper.
[Deprecated] Chain that does self-ask with search.
An Agent driven by OpenAIs function powered API.
Agent that uses XML tags.
An agent designed to hold a conversation in addition to using tools.
Agent for the MRKL chain.
Chain that implements the MRKL system.
Agent for the ReAct chain.
Class to assist with exploration of a document store.
Agent for the ReAct TextWorld chain.
[Deprecated] Chain that implements the ReAct paper.
Chat Agent.
An agent that holds a conversation in addition to using tools.
Abstract base class for chat memory.
Mixin for summarizer.
Continually summarizes the conversation history.
Abstract base class for Entity store.
In-memory Entity store.
Upstash Redis backed Entity store.
Redis-backed Entity store.
SQLite-backed Entity store with safe query construction.
Entity extractor & summarizer memory.
Conversation chat memory with token limit.
Vector Store Retriever Memory.
A basic memory implementation that simply stores the conversation history.
A basic memory implementation that simply stores the conversation history.
Use to keep track of the last k turns of a conversation.
Buffer with summarizer for storing conversation memory.
Chain to run queries against LLMs.
Map-reduce chain.
Chain for having a conversation based on retrieved documents.
Chain for making a simple request to an API endpoint.
Base class for question-answer generation chains.
Chain for question-answering with self-verification.
Question answering chain with sources over documents.
Question answering with sources over documents.
Chain to have a conversation and load context from memory.
Implement an LLM driven browser.
Chain that interprets a prompt and executes python code to do math.
A router chain that uses an LLM chain to perform routing.
A multi-route chain that uses an LLM router chain to choose amongst prompts.
Chain that combines documents by stuffing into context.
Combine documents by recursively reducing them.
Chain that splits documents, then analyzes it in pieces.
Combining documents by mapping a chain over them, then combining results.
Combining documents by mapping a chain over them, then reranking results.
Combine documents by doing a first pass and then refining on more documents.
Base class for question-answering chains.
Chain for question-answering against an index.
Chain for question-answering against a vector database.
Chain for applying constitutional principles.
Chain for question-answering with self-verification.
Document compressor that uses Cohere Rerank API.
Parse an AI message potentially containing tool_calls.
Get the appropriate function output parser given the user functions.
Use a single chain to route an input to one of multiple retrieval qa chains.