repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/example_selectors/base.py | libs/core/langchain_core/example_selectors/base.py | """Interface for selecting examples to include in prompts."""
from abc import ABC, abstractmethod
from typing import Any
from langchain_core.runnables import run_in_executor
class BaseExampleSelector(ABC):
"""Interface for selecting examples to include in prompts."""
@abstractmethod
def add_example(sel... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/vectorstores/in_memory.py | libs/core/langchain_core/vectorstores/in_memory.py | """In-memory vector store."""
from __future__ import annotations
import json
import uuid
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
)
from typing_extensions import override
from langchain_core.documents import Document
from langchain_core.load import dumpd, load
from langchain_core.ve... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/vectorstores/utils.py | libs/core/langchain_core/vectorstores/utils.py | """Internal utilities for the in memory implementation of `VectorStore`.
These are part of a private API, and users should not use them directly
as they can change without notice.
"""
from __future__ import annotations
import logging
import warnings
from typing import TYPE_CHECKING, cast
try:
import numpy as np... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/vectorstores/__init__.py | libs/core/langchain_core/vectorstores/__init__.py | """Vector stores."""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
from langchain_core.vectorstores.base import VST, VectorStore, VectorStoreRetriever
from langchain_core.vectorstores.in_memory import InMemoryVectorStore
__all__ = (
"VST",
"I... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/vectorstores/base.py | libs/core/langchain_core/vectorstores/base.py | """**Vector store** stores embedded data and performs vector search.
One of the most common ways to store and search over unstructured data is to
embed it and store the resulting embedding vectors, and then query the store
and retrieve the data that are 'most similar' to the embedded query.
"""
from __future__ import... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/structured.py | libs/core/langchain_core/tools/structured.py | """Structured tool."""
from __future__ import annotations
import functools
import textwrap
from collections.abc import Awaitable, Callable
from inspect import signature
from typing import (
TYPE_CHECKING,
Annotated,
Any,
Literal,
)
from pydantic import Field, SkipValidation
from typing_extensions imp... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/render.py | libs/core/langchain_core/tools/render.py | """Utilities to render tools."""
from __future__ import annotations
from collections.abc import Callable
from inspect import signature
from langchain_core.tools.base import BaseTool
ToolsRenderer = Callable[[list[BaseTool]], str]
def render_text_description(tools: list[BaseTool]) -> str:
"""Render the tool na... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/convert.py | libs/core/langchain_core/tools/convert.py | """Convert functions and runnables to tools."""
import inspect
from collections.abc import Callable
from typing import Any, Literal, cast, get_type_hints, overload
from pydantic import BaseModel, Field, create_model
from langchain_core.callbacks import Callbacks
from langchain_core.runnables import Runnable
from lan... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/simple.py | libs/core/langchain_core/tools/simple.py | """Tool that takes in function or coroutine directly."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from inspect import signature
from typing import (
TYPE_CHECKING,
Any,
)
from typing_extensions import override
# Cannot move to TYPE_CHECKING as _run/_arun parameter a... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/__init__.py | libs/core/langchain_core/tools/__init__.py | """**Tools** are classes that an Agent uses to interact with the world.
Each tool has a **description**. Agent uses the description to choose the right
tool for the job.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/retriever.py | libs/core/langchain_core/tools/retriever.py | """Retriever tool."""
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
from pydantic import BaseModel, Field
# Cannot move Callbacks and Document to TYPE_CHECKING as StructuredTool's
# func/coroutine parameter annotations are evaluated at runtime.
from langchain_core.callbacks import Cal... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tools/base.py | libs/core/langchain_core/tools/base.py | """Base classes and utilities for LangChain tools."""
from __future__ import annotations
import functools
import inspect
import json
import typing
import warnings
from abc import ABC, abstractmethod
from collections.abc import Callable # noqa: TC003
from inspect import signature
from typing import (
TYPE_CHECKIN... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/chat_result.py | libs/core/langchain_core/outputs/chat_result.py | """Chat result schema."""
from pydantic import BaseModel
from langchain_core.outputs.chat_generation import ChatGeneration
class ChatResult(BaseModel):
"""Use to represent the result of a chat model call with a single prompt.
This container is used internally by some implementations of chat model,
it w... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/run_info.py | libs/core/langchain_core/outputs/run_info.py | """RunInfo class."""
from __future__ import annotations
from uuid import UUID
from pydantic import BaseModel
class RunInfo(BaseModel):
"""Class that contains metadata for a single execution of a Chain or model.
Defined for backwards compatibility with older versions of langchain_core.
This model will... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/llm_result.py | libs/core/langchain_core/outputs/llm_result.py | """LLMResult class."""
from __future__ import annotations
from copy import deepcopy
from typing import Literal
from pydantic import BaseModel
from langchain_core.outputs.chat_generation import ChatGeneration, ChatGenerationChunk
from langchain_core.outputs.generation import Generation, GenerationChunk
from langchai... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/__init__.py | libs/core/langchain_core/outputs/__init__.py | """Output classes.
Used to represent the output of a language model call and the output of a chat.
The top container for information is the `LLMResult` object. `LLMResult` is used by both
chat models and LLMs. This object contains the output of the language model and any
additional information that the model provider... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/chat_generation.py | libs/core/langchain_core/outputs/chat_generation.py | """Chat generation output classes."""
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
from pydantic import model_validator
from langchain_core.messages import BaseMessage, BaseMessageChunk
from langchain_core.outputs.generation import Generation
from langchain_core.utils._merge import m... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/outputs/generation.py | libs/core/langchain_core/outputs/generation.py | """Generation output schema."""
from __future__ import annotations
from typing import Any, Literal
from langchain_core.load import Serializable
from langchain_core.utils._merge import merge_dicts
class Generation(Serializable):
"""A single text generation output.
Generation represents the response from an... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/schemas.py | libs/core/langchain_core/tracers/schemas.py | """Schemas for tracers."""
from __future__ import annotations
from langsmith import RunTree
# Begin V2 API Schemas
Run = RunTree # For backwards compatibility
__all__ = [
"Run",
]
| python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/_compat.py | libs/core/langchain_core/tracers/_compat.py | """Compatibility helpers for Pydantic v1/v2 with langsmith Run objects.
Note: The generic helpers (`pydantic_to_dict`, `pydantic_copy`) detect Pydantic
version based on the langsmith `Run` model. They're intended for langsmith objects
(`Run`, `Example`) which migrate together.
For general Pydantic v1/v2 handling, see... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/core.py | libs/core/langchain_core/tracers/core.py | """Utilities for the root listener."""
from __future__ import annotations
import logging
import traceback
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from typing import (
TYPE_CHECKING,
Any,
Literal,
cast,
)
from langchain_core.exceptions import TracerException
from la... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/stdout.py | libs/core/langchain_core/tracers/stdout.py | """Tracers that print to the console."""
import json
from collections.abc import Callable
from typing import Any
from langchain_core.tracers.base import BaseTracer
from langchain_core.tracers.schemas import Run
from langchain_core.utils.input import get_bolded_text, get_colored_text
MILLISECONDS_IN_SECOND = 1000
d... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/log_stream.py | libs/core/langchain_core/tracers/log_stream.py | """Tracer that streams run logs to a stream."""
from __future__ import annotations
import asyncio
import contextlib
import copy
import threading
from collections import defaultdict
from pprint import pformat
from typing import (
TYPE_CHECKING,
Any,
Literal,
TypeVar,
overload,
)
import jsonpatch ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/event_stream.py | libs/core/langchain_core/tracers/event_stream.py | """Internal tracer to power the event stream API."""
from __future__ import annotations
import asyncio
import contextlib
import logging
from typing import (
TYPE_CHECKING,
Any,
TypedDict,
TypeVar,
cast,
)
from typing_extensions import NotRequired, override
from langchain_core.callbacks.base impo... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/memory_stream.py | libs/core/langchain_core/tracers/memory_stream.py | """Module implements a memory stream for communication between two co-routines.
This module provides a way to communicate between two co-routines using a memory
channel. The writer and reader can be in the same event loop or in different event
loops. When they're in different event loops, they will also be in differen... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/evaluation.py | libs/core/langchain_core/tracers/evaluation.py | """A tracer that runs evaluators over completed runs."""
from __future__ import annotations
import logging
import threading
import weakref
from concurrent.futures import Future, ThreadPoolExecutor, wait
from typing import TYPE_CHECKING, Any, cast
from uuid import UUID
import langsmith
from langsmith.evaluation.evalu... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/__init__.py | libs/core/langchain_core/tracers/__init__.py | """**Tracers** are classes for tracing runs."""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
from langchain_core.tracers.base import BaseTracer
from langchain_core.tracers.evaluation import EvaluatorCallbackHandler
from langchain_core.tracers.lan... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/context.py | libs/core/langchain_core/tracers/context.py | """Context management for tracers."""
from __future__ import annotations
from contextlib import contextmanager
from contextvars import ContextVar
from typing import (
TYPE_CHECKING,
Any,
Literal,
cast,
)
from uuid import UUID
from langsmith import run_helpers as ls_rh
from langsmith import utils as l... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/root_listeners.py | libs/core/langchain_core/tracers/root_listeners.py | """Tracers that call listeners."""
from collections.abc import Awaitable, Callable
from typing import TYPE_CHECKING
from langchain_core.runnables.config import (
RunnableConfig,
acall_func_with_variable_args,
call_func_with_variable_args,
)
from langchain_core.tracers.base import AsyncBaseTracer, BaseTrac... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/run_collector.py | libs/core/langchain_core/tracers/run_collector.py | """A tracer that collects all nested runs in a list."""
from typing import Any
from uuid import UUID
from langchain_core.tracers._compat import run_copy
from langchain_core.tracers.base import BaseTracer
from langchain_core.tracers.schemas import Run
class RunCollectorCallbackHandler(BaseTracer):
"""Tracer that... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/base.py | libs/core/langchain_core/tracers/base.py | """Base interfaces for tracing runs."""
from __future__ import annotations
import asyncio
import logging
from abc import ABC, abstractmethod
from typing import (
TYPE_CHECKING,
Any,
)
from typing_extensions import override
from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
f... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/_streaming.py | libs/core/langchain_core/tracers/_streaming.py | """Internal tracers used for stream_log and astream events implementations."""
import typing
from collections.abc import AsyncIterator, Iterator
from uuid import UUID
T = typing.TypeVar("T")
# THIS IS USED IN LANGGRAPH.
@typing.runtime_checkable
class _StreamingCallbackHandler(typing.Protocol[T]):
"""Types for ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/tracers/langchain.py | libs/core/langchain_core/tracers/langchain.py | """A Tracer implementation that records to LangChain endpoint."""
from __future__ import annotations
import logging
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any
from uuid import UUID
from langsmith import Client, get_tracing_context
f... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/document_loaders/blob_loaders.py | libs/core/langchain_core/document_loaders/blob_loaders.py | """Schema for Blobs and Blob Loaders.
The goal is to facilitate decoupling of content loading from content parsing code.
In addition, content loading code should provide a lazy loading interface by default.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/document_loaders/__init__.py | libs/core/langchain_core/document_loaders/__init__.py | """Document loaders."""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
from langchain_core.document_loaders.base import BaseBlobParser, BaseLoader
from langchain_core.document_loaders.blob_loaders import Blob, BlobLoader, PathLike
from langchain_co... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/document_loaders/base.py | libs/core/langchain_core/document_loaders/base.py | """Abstract interface for document loader implementations."""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from langchain_core.runnables import run_in_executor
if TYPE_CHECKING:
from collections.abc import AsyncIterator, Iterator
from langchain_tex... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/document_loaders/langsmith.py | libs/core/langchain_core/document_loaders/langsmith.py | """LangSmith document loader."""
import datetime
import json
import uuid
from collections.abc import Callable, Iterator, Sequence
from typing import Any
from langsmith import Client as LangSmithClient
from typing_extensions import override
from langchain_core.document_loaders.base import BaseLoader
from langchain_co... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/chat.py | libs/core/langchain_core/messages/chat.py | """Chat Message."""
from typing import Any, Literal
from typing_extensions import override
from langchain_core.messages.base import (
BaseMessage,
BaseMessageChunk,
merge_content,
)
from langchain_core.utils._merge import merge_dicts
class ChatMessage(BaseMessage):
"""Message that can be assigned a... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/modifier.py | libs/core/langchain_core/messages/modifier.py | """Message responsible for deleting other messages."""
from typing import Any, Literal
from langchain_core.messages.base import BaseMessage
class RemoveMessage(BaseMessage):
"""Message responsible for deleting other messages."""
type: Literal["remove"] = "remove"
"""The type of the message (used for se... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/function.py | libs/core/langchain_core/messages/function.py | """Function Message."""
from typing import Any, Literal
from typing_extensions import override
from langchain_core.messages.base import (
BaseMessage,
BaseMessageChunk,
merge_content,
)
from langchain_core.utils._merge import merge_dicts
class FunctionMessage(BaseMessage):
"""Message for passing th... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/system.py | libs/core/langchain_core/messages/system.py | """System message."""
from typing import Any, Literal, cast, overload
from langchain_core.messages import content as types
from langchain_core.messages.base import BaseMessage, BaseMessageChunk
class SystemMessage(BaseMessage):
"""Message for priming AI behavior.
The system message is usually passed in as ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/human.py | libs/core/langchain_core/messages/human.py | """Human message."""
from typing import Any, Literal, cast, overload
from langchain_core.messages import content as types
from langchain_core.messages.base import BaseMessage, BaseMessageChunk
class HumanMessage(BaseMessage):
"""Message from the user.
A `HumanMessage` is a message that is passed in from a ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/utils.py | libs/core/langchain_core/messages/utils.py | """Module contains utility functions for working with messages.
Some examples of what you can do with these functions include:
* Convert messages to strings (serialization)
* Convert messages from dicts to Message objects (deserialization)
* Filter messages from a list of messages based on name, type or id etc.
"""
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/__init__.py | libs/core/langchain_core/messages/__init__.py | """**Messages** are objects used in prompts and chat conversations."""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
from langchain_core.utils.utils import LC_AUTO_PREFIX, LC_ID_PREFIX, ensure_id
if TYPE_CHECKING:
from langchain_core.messages.ai import (
AIMessage,... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/base.py | libs/core/langchain_core/messages/base.py | """Base message."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, cast, overload
from pydantic import ConfigDict, Field
from langchain_core._api.deprecation import warn_deprecated
from langchain_core.load.serializable import Serializable
from langchain_core.utils import get_bolded_text
f... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/content.py | libs/core/langchain_core/messages/content.py | """Standard, multimodal content blocks for Large Language Model I/O.
This module provides standardized data structures for representing inputs to and outputs
from LLMs. The core abstraction is the **Content Block**, a `TypedDict`.
**Rationale**
Different LLM providers use distinct and incompatible API schemas. This ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/ai.py | libs/core/langchain_core/messages/ai.py | """AI message."""
import json
import logging
import operator
from collections.abc import Sequence
from typing import Any, Literal, cast, overload
from pydantic import Field, model_validator
from typing_extensions import NotRequired, Self, TypedDict, override
from langchain_core.messages import content as types
from ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/tool.py | libs/core/langchain_core/messages/tool.py | """Messages for tools."""
import json
from typing import Any, Literal, cast, overload
from uuid import UUID
from pydantic import Field, model_validator
from typing_extensions import NotRequired, TypedDict, override
from langchain_core.messages import content as types
from langchain_core.messages.base import BaseMess... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/anthropic.py | libs/core/langchain_core/messages/block_translators/anthropic.py | """Derivations of standard content blocks from Anthropic content."""
import json
from collections.abc import Iterable
from typing import Any, cast
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
def _populate_extras(
standard_block: types.Conten... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/bedrock_converse.py | libs/core/langchain_core/messages/block_translators/bedrock_converse.py | """Derivations of standard content blocks from Amazon (Bedrock Converse) content."""
import base64
from collections.abc import Iterable
from typing import Any, cast
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
def _bytes_to_b64_str(bytes_: bytes)... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/langchain_v0.py | libs/core/langchain_core/messages/block_translators/langchain_v0.py | """Derivations of standard content blocks from LangChain v0 multimodal content."""
from typing import Any, cast
from langchain_core.messages import content as types
def _convert_v0_multimodal_input_to_v1(
content: list[types.ContentBlock],
) -> list[types.ContentBlock]:
"""Convert v0 multimodal blocks to v1... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/google_vertexai.py | libs/core/langchain_core/messages/block_translators/google_vertexai.py | """Derivations of standard content blocks from Google (VertexAI) content."""
from langchain_core.messages.block_translators.google_genai import (
translate_content,
translate_content_chunk,
)
def _register_google_vertexai_translator() -> None:
"""Register the Google (VertexAI) translator with the central... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/groq.py | libs/core/langchain_core/messages/block_translators/groq.py | """Derivations of standard content blocks from Groq content."""
import json
import re
from typing import Any
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.base import _extract_reasoning_from_additional_kwargs
def _popu... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/__init__.py | libs/core/langchain_core/messages/block_translators/__init__.py | """Derivations of standard content blocks from provider content.
`AIMessage` will first attempt to use a provider-specific translator if
`model_provider` is set in `response_metadata` on the message. Consequently, each
provider translator must handle all possible content response types from the provider,
including tex... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/bedrock.py | libs/core/langchain_core/messages/block_translators/bedrock.py | """Derivations of standard content blocks from Bedrock content."""
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.block_translators.anthropic import (
_convert_to_v1_from_anthropic,
)
def _convert_to_v1_from_bedrock(... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/google_genai.py | libs/core/langchain_core/messages/block_translators/google_genai.py | """Derivations of standard content blocks from Google (GenAI) content."""
import base64
import re
from collections.abc import Iterable
from typing import Any, cast
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.content im... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/messages/block_translators/openai.py | libs/core/langchain_core/messages/block_translators/openai.py | """Derivations of standard content blocks from OpenAI content."""
from __future__ import annotations
import json
import warnings
from typing import TYPE_CHECKING, Any, Literal, cast
from langchain_core.language_models._utils import (
_parse_data_uri,
is_openai_data_block,
)
from langchain_core.messages impor... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/graph.py | libs/core/langchain_core/runnables/graph.py | """Graph used in Runnables."""
from __future__ import annotations
import inspect
from collections import defaultdict
from dataclasses import dataclass, field
from enum import Enum
from typing import (
TYPE_CHECKING,
Any,
NamedTuple,
Protocol,
TypedDict,
overload,
)
from uuid import UUID, uuid4... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/router.py | libs/core/langchain_core/runnables/router.py | """Runnable that routes to a set of Runnables."""
from __future__ import annotations
from collections.abc import Mapping
from typing import (
TYPE_CHECKING,
Any,
cast,
)
from pydantic import ConfigDict
from typing_extensions import TypedDict, override
from langchain_core.runnables.base import (
Runn... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/history.py | libs/core/langchain_core/runnables/history.py | """Runnable that manages chat message history for another Runnable."""
from __future__ import annotations
import inspect
from collections.abc import Callable, Sequence
from types import GenericAlias
from typing import (
TYPE_CHECKING,
Any,
)
from pydantic import BaseModel
from typing_extensions import overri... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/schema.py | libs/core/langchain_core/runnables/schema.py | """Module contains typedefs that are used with `Runnable` objects."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal
from typing_extensions import NotRequired, TypedDict
if TYPE_CHECKING:
from collections.abc import Sequence
class EventData(TypedDict, total=False):
"""Da... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/graph_png.py | libs/core/langchain_core/runnables/graph_png.py | """Helper class to draw a state graph into a PNG file."""
from itertools import groupby
from typing import Any, cast
from langchain_core.runnables.graph import Graph, LabelsDict
try:
import pygraphviz as pgv # type: ignore[import-not-found]
_HAS_PYGRAPHVIZ = True
except ImportError:
_HAS_PYGRAPHVIZ = F... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/branch.py | libs/core/langchain_core/runnables/branch.py | """Runnable that selects which branch to run based on a condition."""
from collections.abc import (
AsyncIterator,
Awaitable,
Callable,
Iterator,
Mapping,
Sequence,
)
from typing import (
Any,
cast,
)
from pydantic import BaseModel, ConfigDict
from typing_extensions import override
fr... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/utils.py | libs/core/langchain_core/runnables/utils.py | """Utility code for runnables."""
from __future__ import annotations
import ast
import asyncio
import inspect
import sys
import textwrap
# Cannot move to TYPE_CHECKING as Mapping and Sequence are needed at runtime by
# RunnableConfigurableFields.
from collections.abc import Mapping, Sequence # noqa: TC003
from func... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/passthrough.py | libs/core/langchain_core/runnables/passthrough.py | """Implementation of the RunnablePassthrough."""
from __future__ import annotations
import asyncio
import inspect
import threading
from collections.abc import Awaitable, Callable
from typing import (
TYPE_CHECKING,
Any,
cast,
)
from pydantic import BaseModel, RootModel
from typing_extensions import overr... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/config.py | libs/core/langchain_core/runnables/config.py | """Configuration utilities for Runnables."""
from __future__ import annotations
import asyncio
# Cannot move uuid to TYPE_CHECKING as RunnableConfig is used in Pydantic models
import uuid # noqa: TC003
import warnings
from collections.abc import Awaitable, Callable, Generator, Iterable, Iterator, Sequence
from conc... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/retry.py | libs/core/langchain_core/runnables/retry.py | """Runnable that retries a Runnable if it fails."""
from typing import (
TYPE_CHECKING,
Any,
TypeVar,
cast,
)
from tenacity import (
AsyncRetrying,
RetryCallState,
RetryError,
Retrying,
retry_if_exception_type,
stop_after_attempt,
wait_exponential_jitter,
)
from typing_exte... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/__init__.py | libs/core/langchain_core/runnables/__init__.py | """LangChain **Runnable** and the **LangChain Expression Language (LCEL)**.
The LangChain Expression Language (LCEL) offers a declarative method to build
production-grade programs that harness the power of LLMs.
Programs created using LCEL and LangChain Runnables inherently support
synchronous, asynchronous, batch, a... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/configurable.py | libs/core/langchain_core/runnables/configurable.py | """`Runnable` objects that can be dynamically configured."""
from __future__ import annotations
import enum
import threading
from abc import abstractmethod
from collections.abc import (
AsyncIterator,
Callable,
Iterator,
Sequence,
)
from functools import wraps
from typing import (
TYPE_CHECKING,
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/base.py | libs/core/langchain_core/runnables/base.py | """Base classes and utilities for `Runnable`s."""
from __future__ import annotations
import asyncio
import collections
import contextlib
import functools
import inspect
import threading
from abc import ABC, abstractmethod
from collections.abc import (
AsyncGenerator,
AsyncIterator,
Awaitable,
Callable... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/graph_ascii.py | libs/core/langchain_core/runnables/graph_ascii.py | """Draws DAG in ASCII.
Adapted from https://github.com/iterative/dvc/blob/main/dvc/dagascii.py.
"""
from __future__ import annotations
import math
import os
from typing import TYPE_CHECKING, Any
try:
from grandalf.graphs import Edge, Graph, Vertex # type: ignore[import-untyped]
from grandalf.layouts import... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/graph_mermaid.py | libs/core/langchain_core/runnables/graph_mermaid.py | """Mermaid graph drawing utilities."""
from __future__ import annotations
import asyncio
import base64
import random
import re
import string
import time
import urllib.parse
from dataclasses import asdict
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, cast
import yaml
from langchain_core.ru... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/runnables/fallbacks.py | libs/core/langchain_core/runnables/fallbacks.py | """Runnable that can fallback to other Runnables if it fails."""
import asyncio
import inspect
import typing
from collections.abc import AsyncIterator, Iterator, Sequence
from functools import wraps
from typing import TYPE_CHECKING, Any, cast
from pydantic import BaseModel, ConfigDict
from typing_extensions import ov... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/image.py | libs/core/langchain_core/utils/image.py | """Utilities for image processing."""
from typing import Any
def __getattr__(name: str) -> Any:
if name in {"encode_image", "image_to_data_url"}:
msg = (
f"'{name}' has been removed for security reasons.\n\n"
f"Usage of this utility in environments with user-input paths is a "
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/function_calling.py | libs/core/langchain_core/utils/function_calling.py | """Methods for creating function specs in the style of OpenAI Functions."""
from __future__ import annotations
import collections
import inspect
import logging
import types
import typing
import uuid
from typing import (
TYPE_CHECKING,
Annotated,
Any,
Literal,
Union,
cast,
get_args,
get... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/iter.py | libs/core/langchain_core/utils/iter.py | """Utilities for working with iterators."""
from collections import deque
from collections.abc import Generator, Iterable, Iterator
from contextlib import AbstractContextManager
from itertools import islice
from types import TracebackType
from typing import (
Any,
Generic,
Literal,
TypeVar,
overloa... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/html.py | libs/core/langchain_core/utils/html.py | """Utilities for working with HTML."""
import logging
import re
from collections.abc import Sequence
from urllib.parse import urljoin, urlparse
logger = logging.getLogger(__name__)
PREFIXES_TO_IGNORE = ("javascript:", "mailto:", "#")
SUFFIXES_TO_IGNORE = (
".css",
".js",
".ico",
".png",
".jpg",
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/aiter.py | libs/core/langchain_core/utils/aiter.py | """Asynchronous iterator utilities.
Adapted from
https://github.com/maxfischer2781/asyncstdlib/blob/master/asyncstdlib/itertools.py
MIT License.
"""
from collections import deque
from collections.abc import (
AsyncGenerator,
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Iterator,
)
from c... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/uuid.py | libs/core/langchain_core/utils/uuid.py | """UUID utility functions.
This module exports a uuid7 function to generate monotonic, time-ordered UUIDs
for tracing and similar operations.
"""
from __future__ import annotations
import typing
from uuid import UUID
from uuid_utils.compat import uuid7 as _uuid_utils_uuid7
if typing.TYPE_CHECKING:
from uuid im... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/input.py | libs/core/langchain_core/utils/input.py | """Handle chained inputs."""
from typing import TextIO
_TEXT_COLOR_MAPPING = {
"blue": "36;1",
"yellow": "33;1",
"pink": "38;5;200",
"green": "32;1",
"red": "31;1",
}
def get_color_mapping(
items: list[str], excluded_colors: list | None = None
) -> dict[str, str]:
"""Get mapping for item... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/usage.py | libs/core/langchain_core/utils/usage.py | """Usage utilities."""
from collections.abc import Callable
def _dict_int_op(
left: dict,
right: dict,
op: Callable[[int, int], int],
*,
default: int = 0,
depth: int = 0,
max_depth: int = 100,
) -> dict:
"""Apply an integer operation to corresponding values in two dictionaries.
R... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/utils.py | libs/core/langchain_core/utils/utils.py | """Generic utility functions."""
import contextlib
import datetime
import functools
import importlib
import os
import warnings
from collections.abc import Callable, Iterator, Sequence
from importlib.metadata import version
from typing import Any, overload
from uuid import uuid4
from packaging.version import parse
fro... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/strings.py | libs/core/langchain_core/utils/strings.py | """String utilities."""
from typing import Any
def stringify_value(val: Any) -> str:
"""Stringify a value.
Args:
val: The value to stringify.
Returns:
The stringified value.
"""
if isinstance(val, str):
return val
if isinstance(val, dict):
return "\n" + strin... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/__init__.py | libs/core/langchain_core/utils/__init__.py | """Utility functions for LangChain.
These functions do not depend on any other LangChain module.
"""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
# for type checking and IDE support, we include the imports here
# but we don't want to eagerly import ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/_merge.py | libs/core/langchain_core/utils/_merge.py | from __future__ import annotations
from typing import Any
def merge_dicts(left: dict[str, Any], *others: dict[str, Any]) -> dict[str, Any]:
r"""Merge dictionaries.
Merge many dicts, handling specific scenarios where a key exists in both
dictionaries but has a value of None in 'left'. In such cases, the ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/json.py | libs/core/langchain_core/utils/json.py | """Utilities for JSON."""
from __future__ import annotations
import json
import re
from typing import TYPE_CHECKING, Any
from langchain_core.exceptions import OutputParserException
if TYPE_CHECKING:
from collections.abc import Callable
def _replace_new_line(match: re.Match[str]) -> str:
"""Replace newline... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/json_schema.py | libs/core/langchain_core/utils/json_schema.py | """Utilities for JSON Schema."""
from __future__ import annotations
from copy import deepcopy
from typing import TYPE_CHECKING, Any, cast
if TYPE_CHECKING:
from collections.abc import Sequence
def _retrieve_ref(path: str, schema: dict) -> list | dict:
"""Retrieve a referenced object from a JSON schema usin... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/interactive_env.py | libs/core/langchain_core/utils/interactive_env.py | """Utilities for working with interactive environments."""
import sys
def is_interactive_env() -> bool:
"""Determine if running within IPython or Jupyter.
Returns:
True if running in an interactive environment, `False` otherwise.
"""
return hasattr(sys, "ps2")
| python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/mustache.py | libs/core/langchain_core/utils/mustache.py | """Adapted from https://github.com/noahmorrison/chevron.
MIT License.
"""
from __future__ import annotations
import logging
from collections.abc import Iterator, Mapping, Sequence
from types import MappingProxyType
from typing import (
TYPE_CHECKING,
Any,
Literal,
cast,
)
if TYPE_CHECKING:
from ... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/formatting.py | libs/core/langchain_core/utils/formatting.py | """Utilities for formatting strings."""
from collections.abc import Mapping, Sequence
from string import Formatter
from typing import Any
class StrictFormatter(Formatter):
"""Formatter that checks for extra keys."""
def vformat(
self, format_string: str, args: Sequence, kwargs: Mapping[str, Any]
... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/pydantic.py | libs/core/langchain_core/utils/pydantic.py | """Utilities for pydantic."""
from __future__ import annotations
import inspect
import textwrap
import warnings
from contextlib import nullcontext
from functools import lru_cache, wraps
from types import GenericAlias
from typing import (
TYPE_CHECKING,
Any,
TypeVar,
cast,
overload,
)
import pydan... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/utils/env.py | libs/core/langchain_core/utils/env.py | """Utilities for environment variables."""
from __future__ import annotations
import os
from typing import Any
def env_var_is_set(env_var: str) -> bool:
"""Check if an environment variable is set.
Args:
env_var: The name of the environment variable.
Returns:
`True` if the environment v... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/file.py | libs/core/langchain_core/callbacks/file.py | """Callback Handler that writes to a file."""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING, Any, TextIO, cast
from typing_extensions import Self, override
from langchain_core._api import warn_deprecated
from langchain_core.callbacks import BaseCallbackHandler
from lan... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/usage.py | libs/core/langchain_core/callbacks/usage.py | """Callback Handler that tracks AIMessage.usage_metadata."""
import threading
from collections.abc import Generator
from contextlib import contextmanager
from contextvars import ContextVar
from typing import Any
from typing_extensions import override
from langchain_core.callbacks import BaseCallbackHandler
from lang... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/stdout.py | libs/core/langchain_core/callbacks/stdout.py | """Callback Handler that prints to std out."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from typing_extensions import override
from langchain_core.callbacks.base import BaseCallbackHandler
from langchain_core.utils import print_text
if TYPE_CHECKING:
from langchain_core.agents i... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/__init__.py | libs/core/langchain_core/callbacks/__init__.py | """**Callback handlers** allow listening to events in LangChain."""
from typing import TYPE_CHECKING
from langchain_core._import_utils import import_attr
if TYPE_CHECKING:
from langchain_core.callbacks.base import (
AsyncCallbackHandler,
BaseCallbackHandler,
BaseCallbackManager,
C... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/base.py | libs/core/langchain_core/callbacks/base.py | """Base callback handler for LangChain."""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from collections.abc import Sequence
from uuid import UUID
from tenacity import RetryCallState
from typing_extensions import Self
from langchain_c... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/manager.py | libs/core/langchain_core/callbacks/manager.py | """Run managers."""
from __future__ import annotations
import asyncio
import atexit
import functools
import logging
from abc import ABC, abstractmethod
from collections.abc import Callable
from concurrent.futures import ThreadPoolExecutor
from contextlib import asynccontextmanager, contextmanager
from contextvars imp... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | true |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/callbacks/streaming_stdout.py | libs/core/langchain_core/callbacks/streaming_stdout.py | """Callback Handler streams to stdout on new llm token."""
from __future__ import annotations
import sys
from typing import TYPE_CHECKING, Any
from typing_extensions import override
from langchain_core.callbacks.base import BaseCallbackHandler
if TYPE_CHECKING:
from langchain_core.agents import AgentAction, Ag... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
langchain-ai/langchain | https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/langchain_core/prompts/structured.py | libs/core/langchain_core/prompts/structured.py | """Structured prompt template for a language model."""
from collections.abc import AsyncIterator, Callable, Iterator, Mapping, Sequence
from typing import (
Any,
)
from pydantic import BaseModel, Field
from typing_extensions import override
from langchain_core._api.beta_decorator import beta
from langchain_core.... | python | MIT | e5d4acf681784d1ea356c932cf31c1c9723dbafa | 2026-01-04T14:38:15.444279Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.