langchain-core: 0.3.28#
langchain-core
defines the base abstractions for the LangChain ecosystem.
The interfaces for core components like chat models, LLMs, vector stores, retrievers, and more are defined here. The universal invocation protocol (Runnables) along with a syntax for combining components (LangChain Expression Language) are also defined here.
No third-party integrations are defined here. The dependencies are kept purposefully very lightweight.
agents#
Classes
Represents a request to execute an action by an agent. |
|
Representation of an action to be executed by an agent. |
|
Final return value of an ActionAgent. |
|
Result of running an AgentAction. |
beta#
Classes
Context for a runnable. |
|
|
Context for a runnable with a prefix. |
Functions
Asynchronously patch a runnable config with context getters and setters. |
|
Patch a runnable config with context getters and setters. |
caches#
Classes
Interface for a caching layer for LLMs and Chat models. |
|
|
Cache that stores things in memory. |
callbacks#
Classes
Async callback handler for LangChain. |
|
Base callback handler for LangChain. |
|
|
Base callback manager for LangChain. |
Mixin for callback manager. |
|
Mixin for chain callbacks. |
|
Mixin for LLM callbacks. |
|
Mixin for Retriever callbacks. |
|
Mixin for run manager. |
|
Mixin for tool callbacks. |
|
|
Callback Handler that writes to a file. |
|
Async callback manager that handles callbacks from LangChain. |
Async callback manager for the chain group. |
|
Async callback manager for chain run. |
|
Async callback manager for LLM run. |
|
|
Async callback manager for retriever run. |
Async callback manager for tool run. |
|
Async Parent Run Manager. |
|
|
Async Run Manager. |
|
Base class for run manager (a bound callback manager). |
|
Callback manager for LangChain. |
Callback manager for the chain group. |
|
Callback manager for chain run. |
|
Callback manager for LLM run. |
|
Callback manager for retriever run. |
|
Callback manager for tool run. |
|
|
Sync Parent Run Manager. |
|
Sync Run Manager. |
Callback Handler that prints to std out. |
|
Callback handler for streaming. |
Functions
Dispatch an adhoc event to the handlers. |
|
|
Async generic event handler for AsyncCallbackManager. |
Get an async callback manager for a chain group in a context manager. |
|
Dispatch an adhoc event. |
|
|
Generic event handler for CallbackManager. |
Makes so an awaitable method is always shielded from cancellation. |
|
Get a callback manager for a chain group in a context manager. |
chat_history#
Classes
Abstract base class for storing chat message history. |
|
In memory implementation of chat message history. |
chat_loaders#
Classes
Base class for chat loaders. |
chat_sessions#
Classes
Chat Session represents a single conversation, channel, or other group of messages. |
document_loaders#
Classes
Abstract interface for blob parsers. |
|
Interface for Document Loader. |
|
Abstract interface for blob loaders implementation. |
|
Load LangSmith Dataset examples as Documents. |
documents#
Classes
Use to represent media content. |
|
Blob represents raw data by either reference or value. |
|
Class for storing a piece of text and associated metadata. |
|
Base class for document compressors. |
|
Abstract base class for document transformation. |
embeddings#
Classes
Interface for embedding models. |
|
Deterministic fake embedding model for unit testing purposes. |
|
Fake embedding model for unit testing purposes. |
example_selectors#
Classes
Interface for selecting examples to include in prompts. |
|
Select examples based on length. |
|
|
Select examples based on Max Marginal Relevance. |
|
Select examples based on semantic similarity. |
Functions
Return a list of values in dict sorted by key. |
exceptions#
Classes
|
|
General LangChain exception. |
|
|
Exception that output parsers should raise to signify a parsing error. |
Base class for exceptions in tracers module. |
Functions
|
globals#
Functions
Get the value of the debug global setting. |
|
Get the value of the llm_cache global setting. |
|
Get the value of the verbose global setting. |
|
|
Set a new value for the debug global setting. |
|
Set a new LLM cache, overwriting the previous value, if any. |
|
Set a new value for the verbose global setting. |
indexing#
Classes
Raised when an indexing operation fails. |
|
Return a detailed a breakdown of the result of the indexing operation. |
|
A generic response for delete operation. |
|
|
An in-memory record manager for testing purposes. |
|
Abstract base class representing the interface for a record manager. |
A generic response for upsert operations. |
|
Functions
|
Async index data from the loader into the vector store. |
|
Index data from the loader into the vector store. |
language_models#
Classes
Abstract base class for interfacing with language models. |
|
|
Abstract base class for interfacing with language models. |
|
Abstract base class for interfacing with language models. |
LangSmith parameters for tracing. |
|
Base class for chat models. |
|
Simplified implementation for a chat model to inherit from. |
|
Fake LLM for testing purposes. |
|
Fake error for testing purposes. |
|
Fake streaming list LLM for testing purposes. |
|
Fake Chat Model wrapper for testing purposes. |
|
Fake ChatModel for testing purposes. |
|
Fake ChatModel for testing purposes. |
|
Generic fake chat model that can be used to test the chat model interface. |
|
Generic fake chat model that can be used to test the chat model interface. |
|
Base LLM abstract interface. |
|
Simple interface for implementing a custom LLM. |
Functions
Async generate from a stream. |
|
Generate from a stream. |
|
|
Get prompts that are already cached. |
|
Update the cache and get the LLM output. |
Create a retry decorator for a given LLM and provided |
|
|
Get prompts that are already cached. |
|
Update the cache and get the LLM output. |
load#
Classes
|
Reviver for JSON objects. |
Base class for serialized objects. |
|
Serializable base class. |
|
Serialized constructor. |
|
Serialized not implemented. |
|
Serialized secret. |
Functions
|
Return a default value for a Serializable object or a SerializedNotImplemented object. |
|
Return a dict representation of an object. |
|
Return a json string representation of an object. |
|
|
|
|
Serialize a "not implemented" object. |
|
|
Try to determine if a value is different from the default. |
messages#
Classes
Message from an AI. |
|
Message chunk from an AI. |
|
Breakdown of input token counts. |
|
Breakdown of output token counts. |
|
Usage metadata for a message, such as token counts. |
|
Base abstract message class. |
|
Message chunk, which can be concatenated with other Message chunks. |
|
Message that can be assigned an arbitrary speaker (i.e. role). |
|
Chat Message chunk. |
|
Message for passing the result of executing a tool back to a model. |
|
Function Message chunk. |
|
Message from a human. |
|
Human Message chunk. |
|
Message responsible for deleting other messages. |
|
Message for priming AI behavior. |
|
System Message chunk. |
|
Allowance for errors made by LLM. |
|
Represents a request to call a tool. |
|
A chunk of a tool call (e.g., as part of a stream). |
|
Message for passing the result of executing a tool back to a model. |
|
Tool Message chunk. |
|
Mixin for objects that tools can return directly. |
Functions
|
Add multiple AIMessageChunks together. |
|
Recursively add two UsageMetadata objects. |
|
Recursively subtract two UsageMetadata objects. |
|
Get a title representation for a message. |
|
Merge two message contents. |
|
Convert a Message to a dictionary. |
|
Convert a sequence of Messages to a list of dictionaries. |
Best-effort parsing of tool chunks. |
|
|
Best-effort parsing of tools. |
|
|
|
|
|
|
|
Convert a sequence of messages to a list of messages. |
Convert LangChain messages into OpenAI message dicts. |
|
|
Filter messages based on name, type or id. |
|
Convert a sequence of Messages to strings and concatenate them into one string. |
|
Merge consecutive Messages of the same type. |
Convert a message chunk to a message. |
|
|
Convert a sequence of messages from dicts to Message objects. |
|
Trim messages to be below a token count. |
output_parsers#
Classes
Base class to parse the output of an LLM call. |
|
|
Base class to parse the output of an LLM call. |
Abstract base class for parsing the outputs of a model. |
|
Base class to parse the output of an LLM call. |
|
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
|
|
|
|
Parse the output of an LLM call to a JSON object. |
|
alias of |
|
Parse the output of an LLM call to a comma-separated list. |
|
Parse the output of an LLM call to a list. |
|
Parse a Markdown list. |
|
Parse a numbered list. |
|
|
Parse an output as the element of the Json object. |
Parse an output as the Json object. |
|
Parse an output that is one of sets of values. |
|
|
Parse an output as an attribute of a pydantic object. |
|
Parse an output as a pydantic object. |
Parse tools from OpenAI response. |
|
Parse tools from OpenAI response. |
|
Parse tools from OpenAI response. |
|
Parse an output using a pydantic model. |
|
OutputParser that parses LLMResult into the top likely string. |
|
|
Base class for an output parser that can handle streaming input. |
|
Base class for an output parser that can handle streaming input. |
Base class for an output parser that can handle streaming input. |
|
|
Base class for an output parser that can handle streaming input. |
|
Base class for an output parser that can handle streaming input. |
Parse an output using xml format. |
Functions
|
Drop the last n elements of an iterator. |
Create an InvalidToolCall from a raw tool call. |
|
Parse a single tool call. |
|
Parse a list of tool calls. |
|
|
Get nested element from path. |
outputs#
Classes
A single chat generation output. |
|
ChatGeneration chunk, which can be concatenated with other ChatGeneration chunks. |
|
Use to represent the result of a chat model call with a single prompt. |
|
A single text generation output. |
|
Generation chunk, which can be concatenated with other Generation chunks. |
|
A container for results of an LLM call. |
|
Class that contains metadata for a single execution of a Chain or model. |
prompt_values#
Classes
Chat prompt value. |
|
Chat prompt value which explicitly lists out the message types it accepts. |
|
Image prompt value. |
|
Image URL. |
|
Base abstract class for inputs to any language model. |
|
String prompt value. |
prompts#
Classes
Base class for all prompt templates, returning a prompt. |
|
|
Base class for all prompt templates, returning a prompt. |
AI message prompt template. |
|
Base class for chat prompt templates. |
|
Base class for message prompt templates. |
|
Base class for message prompt templates that use a string prompt template. |
|
Chat message prompt template. |
|
Prompt template for chat models. |
|
Human message prompt template. |
|
Prompt template that assumes variable is already list of messages. |
|
System message prompt template. |
|
Chat prompt template that supports few-shot examples. |
|
Prompt template that contains few shot examples. |
|
Prompt template that contains few shot examples. |
|
Image prompt template for a multimodal model. |
|
Prompt template for a language model. |
|
String prompt that exposes the format method, returning a prompt. |
|
Functions
|
Async format a document into a string based on a prompt template. |
|
Format a document into a string based on a prompt template. |
|
Unified method for loading a prompt from LangChainHub or local fs. |
Load prompt from Config Dict. |
|
Check that template string is valid. |
|
Get the variables from the template. |
|
|
Format a template using jinja2. |
|
Format a template using mustache. |
|
Get the variables from a mustache template. |
|
Get the variables from a mustache template. |
|
Validate that the input variables are valid for the template. |
Deprecated classes
rate_limiters#
Classes
|
|
|
retrievers#
Classes
Abstract base class for a Document retrieval system. |
|
LangSmith parameters for tracing. |
runnables#
Classes
A unit of work that can be invoked, batched, streamed, transformed and composed. |
|
Wrap a Runnable with additional functionality. |
|
Runnable that delegates calls to another Runnable with a set of kwargs. |
|
Runnable that delegates calls to another Runnable with each element of the input sequence. |
|
Runnable that delegates calls to another Runnable with each element of the input sequence. |
|
|
Runnable that runs a generator function. |
|
RunnableLambda converts a python callable into a Runnable. |
alias of |
|
Runnable that runs a mapping of Runnables in parallel, and returns a mapping of their outputs. |
|
Sequence of Runnables, where the output of each is the input of the next. |
|
Runnable that can be serialized to JSON. |
|
Runnable that selects which branch to run based on a condition. |
|
ThreadPoolExecutor that copies the context to the child thread. |
|
Empty dict type. |
|
Configuration for a Runnable. |
|
Serializable Runnable that can be dynamically configured. |
|
Runnable that can be dynamically configured. |
|
Runnable that can be dynamically configured. |
|
|
String enum. |
Runnable that can fallback to other Runnables if it fails. |
|
|
Branch in a graph. |
|
Enum for different curve styles supported by Mermaid |
|
Edge in a graph. |
|
Graph of nodes and edges. |
Dictionary of labels for nodes and edges in a graph. |
|
|
Enum for different draw methods supported by Mermaid |
|
Node in a graph. |
|
Schema for Hexadecimal color codes for different node types. |
|
|
|
Class for drawing in ASCII. |
Class to define vertex box boundaries that will be accounted for during graph building by grandalf. |
|
|
Helper class to draw a state graph into a PNG file. |
Runnable that manages chat message history for another Runnable. |
|
Runnable that assigns key-value pairs to Dict[str, Any] inputs. |
|
Runnable to passthrough inputs unchanged or with additional keys. |
|
Runnable that picks keys from Dict[str, Any] inputs. |
|
Retry a Runnable if it fails. |
|
Router input. |
|
Runnable that routes to a set of Runnables based on Input['key']. |
|
Streaming event. |
|
Custom stream event created by the user. |
|
Data associated with a streaming event. |
|
A standard stream event that follows LangChain convention for event data. |
|
Dictionary that can be added to another dictionary. |
|
|
Field that can be configured by the user. |
Field that can be configured by the user with multiple default values. |
|
Field that can be configured by the user with a default value. |
|
Field that can be configured by the user. |
|
Get the nonlocal variables accessed of a function. |
|
Get the source code of a lambda function. |
|
Check if the first argument of a function is a dict. |
|
|
Check if a name is a local dict. |
Get nonlocal variables accessed. |
|
|
Protocol for objects that support addition. |
Functions
Decorate a function to make it a Runnable. |
|
Coerce a Runnable-like object into a Runnable. |
|
Async call function that may optionally accept a run_manager and/or config. |
|
Call function that may optionally accept a run_manager and/or config. |
|
|
Ensure that a config is a dict with all keys present. |
|
Get an async callback manager for a config. |
Get a callback manager for a config. |
|
|
Get a list of configs from a single config or a list of configs. |
Get an executor for a config. |
|
|
Merge multiple configs into one. |
|
Patch a config with new values. |
Run a function in an executor. |
|
Make a ConfigurableFieldSpec for a ConfigurableFieldSingleOption or ConfigurableFieldMultiOption. |
|
Prefix the id of a ConfigurableFieldSpec. |
|
|
Check if a string is a valid UUID. |
|
Convert the data of a node to a JSON-serializable format. |
|
Convert the data of a node to a string. |
|
Build a DAG and draw it in ASCII. |
|
Draws a Mermaid graph using the provided graph data. |
Draws a Mermaid graph as PNG using provided syntax. |
|
Async identity function. |
|
Identity function. |
|
|
Asynchronously add a sequence of addable objects together. |
|
Check if a callable accepts a config argument. |
|
Check if a callable accepts a context argument. |
|
Check if a callable accepts a run_manager argument. |
|
Add a sequence of addable objects together. |
|
Run a coroutine with a semaphore. |
Gather coroutines with a limit on the number of concurrent coroutines. |
|
Get the keys of the first argument of a function if it is a dict. |
|
Get the source code of a lambda function. |
|
Get the unique config specs from a sequence of config specs. |
|
Indent all lines of text after the first line. |
|
Check if a function is async. |
|
Check if a function is an async generator. |
stores#
Classes
Abstract interface for a key-value store. |
|
In-memory implementation of the BaseStore using a dictionary. |
|
In-memory store for bytes. |
|
In-memory store for any type of data. |
|
Raised when a key is invalid; e.g., uses incorrect characters. |
structured_query#
Classes
|
Enumerator of the comparison operators. |
Comparison to a value. |
|
Base class for all expressions. |
|
Filtering expression. |
|
Logical operation over other directives. |
|
|
Enumerator of the operations. |
Structured query. |
|
Defines interface for IR translation using a visitor pattern. |
sys_info#
Functions
|
Print information about the environment for debugging purposes. |
tools#
Classes
Interface LangChain tools must implement. |
|
Base Toolkit representing a collection of related tools. |
|
Annotation for a Tool arg that is not meant to be generated by a model. |
|
Annotation for injecting the tool_call_id. |
|
Raised when 'args_schema' is missing or has an incorrect type annotation. |
|
Optional exception that tool throws when execution error occurs. |
|
Input to the retriever. |
|
Tool that takes in function or coroutine directly. |
|
Tool that can operate on any number of inputs. |
Functions
Create a pydantic schema from a function's signature. |
|
|
Convert a Runnable into a BaseTool. |
Make tools out of functions, can be used with or without arguments. |
|
Render the tool name and description in plain text. |
|
Render the tool name, description, and args in plain text. |
|
|
Create a tool to do retrieval of documents. |
tracers#
Classes
|
Async Base interface for tracers. |
|
Base interface for tracers. |
Tracer that runs a run evaluator whenever a run is persisted. |
|
Information about a run. |
|
Implementation of the SharedTracer that POSTS to the LangChain endpoint. |
|
A single entry in the run log. |
|
Tracer that streams run logs to a stream. |
|
|
Run log. |
Patch to the run log. |
|
State of the run. |
|
Async Tracer that calls listeners on run start, end, and error. |
|
Tracer that calls listeners on run start, end, and error. |
|
Tracer that collects all nested runs in a list. |
|
|
Tracer that prints to the console. |
Tracer that calls a function with a single str parameter. |
Functions
Collect all run traces in context. |
|
Register a configure hook. |
|
|
Throw an error because this has been replaced by tracing_v2_enabled. |
Instruct LangChain to log all runs in context to LangSmith. |
|
Wait for all tracers to finish. |
|
Get the client. |
|
|
Log an error once. |
Wait for all tracers to finish. |
|
Throw an error because this has been replaced by LangChainTracer. |
|
|
Throw an error because this has been replaced by get_headers. |
Get the elapsed time of a run. |
|
|
Try to stringify an object to JSON. |
Deprecated classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Deprecated functions
utils#
Classes
Dummy lock that provides the proper interface but no protection. |
|
|
Create |
|
Async context manager for safely finalizing an asynchronously cleaned-up resource such as an async generator, calling its |
alias of |
|
Formatter that checks for extra keys. |
|
Representation of a callable function to send to an LLM. |
|
Representation of a callable function to the OpenAI API. |
|
Dummy lock that provides the proper interface but no protection. |
|
|
Create |
alias of |
|
Custom exception for Chevron errors. |
Functions
|
Utility batching function for async iterables. |
|
Pure-Python implementation of anext() for testing purposes. |
|
An individual iterator of a |
|
Check if an environment variable is set. |
|
Get a value from a dictionary or an environment variable. |
|
Get a value from a dictionary or an environment variable. |
Convert a raw function/class to an OpenAI function. :param function: A dictionary, Pydantic BaseModel class, TypedDict class, a LangChain Tool object, or a Python function. If a dictionary is passed in, it is assumed to already be a valid OpenAI function, a JSON schema with top-level 'title' key specified, an Anthropic format tool, or an Amazon Bedrock Converse format tool. :param strict: If True, model output is guaranteed to exactly match the JSON Schema provided in the function definition. If None, |
|
Convert a tool-like object to an OpenAI tool schema. |
|
|
Extract all links from a raw HTML string and convert into absolute paths. |
|
Extract all links from a raw HTML string. |
Get bolded text. |
|
|
Get mapping for items to a support color. |
|
Get colored text. |
|
Print text with highlighting and no end characters. |
Determine if running within IPython or Jupyter. |
|
|
Utility batching function. |
|
An individual iterator of a |
Parse a JSON string from a Markdown string and check that it contains the expected keys. |
|
|
Parse a JSON string from a Markdown string. |
|
Parse a JSON string that may be missing closing braces. |
|
Try to substitute $refs in JSON Schema. |
|
Parse a literal from the template. |
|
Do a preliminary check to see if a tag could be a standalone. |
|
Parse a tag from a template. |
|
Do a final check to see if a tag could be a standalone. |
|
Render a mustache template. |
|
Tokenize a mustache template. |
|
Create a pydantic model with the given field definitions. |
|
Create a pydantic model with the given field definitions. |
Get the field names of a Pydantic model. |
|
Get the major version of Pydantic. |
|
Check if the given class is an instance of Pydantic BaseModel. |
|
Check if the given class is a subclass of Pydantic BaseModel. |
|
Check if the installed Pydantic version is 1.x-like. |
|
Check if the installed Pydantic version is 1.x-like. |
|
|
Decorator to run a function before model initialization. |
|
Convert a list to a comma-separated string. |
Stringify a dictionary. |
|
Stringify a value. |
|
|
Build extra kwargs from values and extra_kwargs. |
|
Check the version of a package. |
Convert a string to a SecretStr if needed. |
|
Create a factory method that gets a value from an environment variable. |
|
Get field names, including aliases, for a pydantic class. |
|
|
Dynamically import a module and raise an exception if the module is not installed. |
|
Context manager for mocking out datetime.now() in unit tests. |
|
Raise an error with the response text. |
Secret from env. |
|
|
Validate specified keyword args are mutually exclusive." |
Deprecated functions
vectorstores#
Classes
Interface for vector store. |
|
Base Retriever class for VectorStore. |
|
In-memory vector store implementation. |
Functions
Calculate maximal marginal relevance. |