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/langchain_v1/tests/unit_tests/agents/middleware/core/test_overrides.py
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_overrides.py
"""Unit tests for override() methods on ModelRequest and ToolCallRequest.""" from langchain_core.language_models.fake_chat_models import GenericFakeChatModel from langchain_core.messages import AIMessage, HumanMessage from langchain_core.tools import tool from langchain.agents.middleware.types import ModelRequest, To...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_composition.py
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_composition.py
"""Unit tests for _chain_model_call_handlers handler composition.""" from typing import TYPE_CHECKING, cast from langchain_core.messages import AIMessage from langchain.agents.factory import _chain_model_call_handlers from langchain.agents.middleware.types import ModelRequest, ModelResponse if TYPE_CHECKING: fr...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py
"""Unit tests for wrap_model_call hook and @wrap_model_call decorator. This module tests the wrap_model_call functionality in three forms: 1. As a middleware method (AgentMiddleware.wrap_model_call) 2. As a decorator (@wrap_model_call) 3. Async variant (AgentMiddleware.awrap_model_call) """ from collections.abc impor...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
true
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py
import pytest from langchain_core.messages import AIMessage, HumanMessage, ToolMessage from langchain_core.tools import tool from langgraph.checkpoint.memory import InMemorySaver from langchain.agents.factory import create_agent from langchain.agents.middleware.model_call_limit import ( ModelCallLimitExceededError...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_fallback.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_fallback.py
"""Unit tests for ModelFallbackMiddleware.""" from __future__ import annotations import warnings from typing import TYPE_CHECKING, cast import pytest from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.language_models.fake_chat_models import GenericFakeChatModel 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/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py
"""Unit tests for LLM tool selection middleware.""" import typing from itertools import cycle from typing import Any, Literal import pytest from langchain_core.language_models import LanguageModelInput from langchain_core.language_models.fake_chat_models import GenericFakeChatModel from langchain_core.messages import...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_structured_output_retry.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_structured_output_retry.py
"""Tests for StructuredOutputRetryMiddleware functionality.""" from collections.abc import Callable import pytest from langchain_core.messages import HumanMessage from langchain_core.tools import tool from langgraph.checkpoint.memory import InMemorySaver from pydantic import BaseModel from langchain.agents import cr...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py
"""Tests for the ContextEditingMiddleware.""" from __future__ import annotations from typing import TYPE_CHECKING, cast from langchain_core.language_models.fake_chat_models import FakeChatModel from langchain_core.messages import ( AIMessage, MessageLikeRepresentation, ToolMessage, ) from langchain.agen...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py
"""Unit tests for TodoListMiddleware.""" from __future__ import annotations from typing import TYPE_CHECKING, cast import pytest from langchain_core.language_models.fake_chat_models import GenericFakeChatModel from langchain_core.messages import AIMessage, HumanMessage from langchain.agents.factory import create_ag...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_human_in_the_loop.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_human_in_the_loop.py
import re from typing import Any from unittest.mock import patch import pytest from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage from langgraph.runtime import Runtime from langchain.agents.middleware.human_in_the_loop import ( Action, HumanInTheLoopMiddleware, ) from langchain...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py
"""Tests for ModelRetryMiddleware functionality.""" import time from typing import Any import pytest from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, ChatResult from langgraph.check...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_execution_policies.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_execution_policies.py
from __future__ import annotations import os import shutil from typing import TYPE_CHECKING, Any import pytest from langchain.agents.middleware import _execution from langchain.agents.middleware.shell_tool import ( CodexSandboxExecutionPolicy, DockerExecutionPolicy, HostExecutionPolicy, ) if TYPE_CHECKI...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_file_search.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_file_search.py
"""Unit tests for file search middleware.""" from pathlib import Path from typing import Any import pytest from langchain.agents.middleware.file_search import ( FilesystemFileSearchMiddleware, _expand_include_patterns, _is_valid_include_pattern, _match_include_pattern, ) class TestFilesystemGrepSea...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py
"""Unit tests for tool emulator middleware.""" import typing from collections.abc import Callable, Sequence from itertools import cycle from typing import Any, Literal from langchain_core.language_models import LanguageModelInput from langchain_core.language_models.chat_models import BaseChatModel from langchain_core...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/__init__.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/__init__.py
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py
"""Tests for PII detection middleware.""" import pytest from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage from langchain.agents.factory import create_agent from langchain.agents.middleware.pii import ( PIIDetectionError, PIIMiddleware, detect_credit_card, detect_email,...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_retry.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_retry.py
"""Tests for ToolRetryMiddleware functionality.""" import time from collections.abc import Callable import pytest from langchain_core.messages import HumanMessage, ToolCall, ToolMessage from langchain_core.tools import tool from langgraph.checkpoint.memory import InMemorySaver from langgraph.prebuilt.tool_node import...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_summarization.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_summarization.py
from unittest.mock import patch import pytest from langchain_core.language_models import ModelProfile from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import AIMessage, AnyMessage, HumanMessage, RemoveMessage, ToolMessage from langchain_core.outputs import ChatGeneratio...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
true
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py
from __future__ import annotations import asyncio import gc import tempfile import time from pathlib import Path from typing import TYPE_CHECKING import pytest from langchain_core.messages import ToolMessage from langchain_core.tools.base import ToolException from langchain.agents.middleware.shell_tool import ( ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py
"""Unit tests for ToolCallLimitMiddleware.""" import pytest from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage from langchain_core.tools import tool from langgraph.checkpoint.memory import InMemorySaver from langchain.agents.factory import create_agent from langchain.agents.middleware....
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/embeddings/test_base.py
libs/langchain_v1/tests/unit_tests/embeddings/test_base.py
"""Test embeddings base module.""" import pytest from langchain.embeddings.base import ( _SUPPORTED_PROVIDERS, _infer_model_and_provider, _parse_model_string, ) @pytest.mark.parametrize( ("model_string", "expected_provider", "expected_model"), [ ("openai:text-embedding-3-small", "openai"...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/embeddings/__init__.py
libs/langchain_v1/tests/unit_tests/embeddings/__init__.py
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/unit_tests/embeddings/test_imports.py
libs/langchain_v1/tests/unit_tests/embeddings/test_imports.py
from langchain import embeddings EXPECTED_ALL = [ "Embeddings", "init_embeddings", ] def test_all_imports() -> None: assert set(embeddings.__all__) == set(EXPECTED_ALL)
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/conftest.py
libs/langchain_v1/tests/integration_tests/conftest.py
from pathlib import Path import pytest from dotenv import load_dotenv # Getting the absolute path of the current file's directory ABS_PATH = Path(__file__).resolve().parent # Getting the absolute path of the project's root directory PROJECT_DIR = ABS_PATH.parent.parent # Loading the .env file if it exists def _loa...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/test_compile.py
libs/langchain_v1/tests/integration_tests/test_compile.py
import pytest @pytest.mark.compile def test_placeholder() -> None: """Used for compiling integration tests without running any real tests."""
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/__init__.py
libs/langchain_v1/tests/integration_tests/__init__.py
"""All integration tests (tests that call out to an external API)."""
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/chat_models/test_base.py
libs/langchain_v1/tests/integration_tests/chat_models/test_base.py
from typing import cast import pytest from langchain_core.language_models import BaseChatModel from langchain_core.messages import AIMessage from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableConfig from langchain_tests.integration_tests import ChatModelIntegrationTests ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/chat_models/__init__.py
libs/langchain_v1/tests/integration_tests/chat_models/__init__.py
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/cache/fake_embeddings.py
libs/langchain_v1/tests/integration_tests/cache/fake_embeddings.py
"""Fake Embedding class for testing purposes.""" import math from langchain_core.embeddings import Embeddings from typing_extensions import override fake_texts = ["foo", "bar", "baz"] class FakeEmbeddings(Embeddings): """Fake embeddings functionality for testing.""" @override def embed_documents(self,...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/cache/__init__.py
libs/langchain_v1/tests/integration_tests/cache/__init__.py
"""All integration tests for Cache objects."""
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/agents/__init__.py
libs/langchain_v1/tests/integration_tests/agents/__init__.py
"""Integration tests for the agents module."""
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/agents/middleware/__init__.py
libs/langchain_v1/tests/integration_tests/agents/middleware/__init__.py
"""Integration tests for agent middleware."""
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/agents/middleware/test_shell_tool_integration.py
libs/langchain_v1/tests/integration_tests/agents/middleware/test_shell_tool_integration.py
"""Integration tests for ShellToolMiddleware with create_agent.""" from __future__ import annotations from typing import TYPE_CHECKING, Any import pytest from langchain_core.messages import HumanMessage from langchain_core.tools import tool from langchain.agents import create_agent from langchain.agents.middleware....
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/embeddings/test_base.py
libs/langchain_v1/tests/integration_tests/embeddings/test_base.py
"""Test embeddings base module.""" import importlib import pytest from langchain_core.embeddings import Embeddings from langchain.embeddings.base import _SUPPORTED_PROVIDERS, init_embeddings @pytest.mark.parametrize( ("provider", "model"), [ ("openai", "text-embedding-3-large"), ("google_ve...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/tests/integration_tests/embeddings/__init__.py
libs/langchain_v1/tests/integration_tests/embeddings/__init__.py
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/__init__.py
libs/langchain_v1/langchain/__init__.py
"""Main entrypoint into LangChain.""" __version__ = "1.2.0"
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/tools/tool_node.py
libs/langchain_v1/langchain/tools/tool_node.py
"""Utils file included for backwards compat imports.""" from langgraph.prebuilt import InjectedState, InjectedStore, ToolRuntime from langgraph.prebuilt.tool_node import ( ToolCallRequest, ToolCallWithContext, ToolCallWrapper, ) from langgraph.prebuilt.tool_node import ( ToolNode as _ToolNode, # noqa:...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/tools/__init__.py
libs/langchain_v1/langchain/tools/__init__.py
"""Tools.""" from langchain_core.tools import ( BaseTool, InjectedToolArg, InjectedToolCallId, ToolException, tool, ) from langchain.tools.tool_node import InjectedState, InjectedStore, ToolRuntime __all__ = [ "BaseTool", "InjectedState", "InjectedStore", "InjectedToolArg", "I...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/chat_models/__init__.py
libs/langchain_v1/langchain/chat_models/__init__.py
"""Entrypoint to using [chat models](https://docs.langchain.com/oss/python/langchain/models) in LangChain.""" # noqa: E501 from langchain_core.language_models import BaseChatModel from langchain.chat_models.base import init_chat_model __all__ = ["BaseChatModel", "init_chat_model"]
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/chat_models/base.py
libs/langchain_v1/langchain/chat_models/base.py
"""Factory functions for chat models.""" from __future__ import annotations import functools import importlib import warnings from typing import ( TYPE_CHECKING, Any, Literal, TypeAlias, cast, overload, ) from langchain_core.language_models import BaseChatModel, LanguageModelInput from langch...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
true
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/factory.py
libs/langchain_v1/langchain/agents/factory.py
"""Agent factory for creating agents with middleware support.""" from __future__ import annotations import itertools from typing import ( TYPE_CHECKING, Annotated, Any, cast, get_args, get_origin, get_type_hints, ) from langchain_core.language_models.chat_models import BaseChatModel from ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
true
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/__init__.py
libs/langchain_v1/langchain/agents/__init__.py
"""Entrypoint to building [Agents](https://docs.langchain.com/oss/python/langchain/agents) with LangChain.""" # noqa: E501 from langchain.agents.factory import create_agent from langchain.agents.middleware.types import AgentState __all__ = [ "AgentState", "create_agent", ]
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/structured_output.py
libs/langchain_v1/langchain/agents/structured_output.py
"""Types for setting agent response formats.""" from __future__ import annotations import json import uuid from dataclasses import dataclass, is_dataclass from types import UnionType from typing import ( TYPE_CHECKING, Any, Generic, Literal, TypeVar, Union, get_args, get_origin, ) fro...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py
libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py
"""Human in the loop middleware.""" from typing import Any, Literal, Protocol from langchain_core.messages import AIMessage, ToolCall, ToolMessage from langgraph.runtime import Runtime from langgraph.types import interrupt from typing_extensions import NotRequired, TypedDict from langchain.agents.middleware.types im...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/_retry.py
libs/langchain_v1/langchain/agents/middleware/_retry.py
"""Shared retry utilities for agent middleware. This module contains common constants, utilities, and logic used by both model and tool retry middleware implementations. """ from __future__ import annotations import random from collections.abc import Callable from typing import Literal # Type aliases RetryOn = tupl...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/shell_tool.py
libs/langchain_v1/langchain/agents/middleware/shell_tool.py
"""Middleware that exposes a persistent shell tool to agents.""" from __future__ import annotations import contextlib import logging import os import queue import signal import subprocess import tempfile import threading import time import uuid import weakref from dataclasses import dataclass, field from pathlib impo...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/todo.py
libs/langchain_v1/langchain/agents/middleware/todo.py
"""Planning and task management middleware for agents.""" from __future__ import annotations from typing import TYPE_CHECKING, Annotated, Literal, cast if TYPE_CHECKING: from collections.abc import Awaitable, Callable from langchain_core.messages import SystemMessage, ToolMessage from langchain_core.tools impor...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/file_search.py
libs/langchain_v1/langchain/agents/middleware/file_search.py
"""File search middleware for Anthropic text editor and memory tools. This module provides Glob and Grep search tools that operate on files stored in state or filesystem. """ from __future__ import annotations import fnmatch import json import re import subprocess from contextlib import suppress from datetime import...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/model_fallback.py
libs/langchain_v1/langchain/agents/middleware/model_fallback.py
"""Model fallback middleware for agents.""" from __future__ import annotations from typing import TYPE_CHECKING from langchain.agents.middleware.types import ( AgentMiddleware, ModelCallResult, ModelRequest, ModelResponse, ) from langchain.chat_models import init_chat_model if TYPE_CHECKING: fro...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/tool_retry.py
libs/langchain_v1/langchain/agents/middleware/tool_retry.py
"""Tool retry middleware for agents.""" from __future__ import annotations import asyncio import time import warnings from typing import TYPE_CHECKING from langchain_core.messages import ToolMessage from langchain.agents.middleware._retry import ( OnFailure, RetryOn, calculate_delay, should_retry_ex...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/_execution.py
libs/langchain_v1/langchain/agents/middleware/_execution.py
"""Execution policies for the persistent shell middleware.""" from __future__ import annotations import abc import json import os import shutil import subprocess import sys import typing from collections.abc import Mapping, Sequence from dataclasses import dataclass, field from pathlib import Path try: # pragma: no...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/model_retry.py
libs/langchain_v1/langchain/agents/middleware/model_retry.py
"""Model retry middleware for agents.""" from __future__ import annotations import asyncio import time from typing import TYPE_CHECKING from langchain_core.messages import AIMessage from langchain.agents.middleware._retry import ( OnFailure, RetryOn, calculate_delay, should_retry_exception, vali...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/_redaction.py
libs/langchain_v1/langchain/agents/middleware/_redaction.py
"""Shared redaction utilities for middleware components.""" from __future__ import annotations import hashlib import ipaddress import operator import re from collections.abc import Callable, Sequence from dataclasses import dataclass from typing import Literal from urllib.parse import urlparse from typing_extensions...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/tool_emulator.py
libs/langchain_v1/langchain/agents/middleware/tool_emulator.py
"""Tool emulator middleware for testing.""" from __future__ import annotations from typing import TYPE_CHECKING from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import HumanMessage, ToolMessage from langchain.agents.middleware.types import AgentMiddleware from langch...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/__init__.py
libs/langchain_v1/langchain/agents/middleware/__init__.py
"""Entrypoint to using [middleware](https://docs.langchain.com/oss/python/langchain/middleware) plugins with [Agents](https://docs.langchain.com/oss/python/langchain/agents).""" # noqa: E501 from .context_editing import ( ClearToolUsesEdit, ContextEditingMiddleware, ) from .file_search import FilesystemFileSe...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/types.py
libs/langchain_v1/langchain/agents/middleware/types.py
"""Types for middleware and agents.""" from __future__ import annotations from collections.abc import Awaitable, Callable, Sequence from dataclasses import dataclass, field, replace from inspect import iscoroutinefunction from typing import ( TYPE_CHECKING, Annotated, Any, Generic, Literal, Pr...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
true
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/pii.py
libs/langchain_v1/langchain/agents/middleware/pii.py
"""PII detection and handling middleware for agents.""" from __future__ import annotations from typing import TYPE_CHECKING, Any, Literal from langchain_core.messages import AIMessage, AnyMessage, HumanMessage, ToolMessage from typing_extensions import override from langchain.agents.middleware._redaction import ( ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/summarization.py
libs/langchain_v1/langchain/agents/middleware/summarization.py
"""Summarization middleware.""" import uuid import warnings from collections.abc import Callable, Iterable, Mapping from functools import partial from typing import Any, Literal, cast from langchain_core.messages import ( AnyMessage, MessageLikeRepresentation, RemoveMessage, ToolMessage, ) from langch...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/context_editing.py
libs/langchain_v1/langchain/agents/middleware/context_editing.py
"""Context editing middleware. Mirrors Anthropic's context editing capabilities by clearing older tool results once the conversation grows beyond a configurable token threshold. The implementation is intentionally model-agnostic so it can be used with any LangChain chat model. """ from __future__ import annotations ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py
libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py
"""Tool call limit middleware for agents.""" from __future__ import annotations from typing import TYPE_CHECKING, Annotated, Any, Generic, Literal from langchain_core.messages import AIMessage, ToolCall, ToolMessage from langgraph.channels.untracked_value import UntrackedValue from langgraph.typing import ContextT f...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/model_call_limit.py
libs/langchain_v1/langchain/agents/middleware/model_call_limit.py
"""Call tracking middleware for agents.""" from __future__ import annotations from typing import TYPE_CHECKING, Annotated, Any, Literal from langchain_core.messages import AIMessage from langgraph.channels.untracked_value import UntrackedValue from typing_extensions import NotRequired, override from langchain.agent...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/agents/middleware/tool_selection.py
libs/langchain_v1/langchain/agents/middleware/tool_selection.py
"""LLM-based tool selector middleware.""" from __future__ import annotations import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Annotated, Literal, Union if TYPE_CHECKING: from collections.abc import Awaitable, Callable from langchain.tools import BaseTool from langchain_cor...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/messages/__init__.py
libs/langchain_v1/langchain/messages/__init__.py
"""Message and message content types. Includes message types for different roles (e.g., human, AI, system), as well as types for message content blocks (e.g., text, image, audio) and tool calls. """ from langchain_core.messages import ( AIMessage, AIMessageChunk, Annotation, AnyMessage, AudioConte...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/rate_limiters/__init__.py
libs/langchain_v1/langchain/rate_limiters/__init__.py
"""Base abstraction and in-memory implementation of rate limiters. These rate limiters can be used to limit the rate of requests to an API. The rate limiters can be used together with `BaseChatModel`. """ from langchain_core.rate_limiters import BaseRateLimiter, InMemoryRateLimiter __all__ = [ "BaseRateLimiter"...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/embeddings/__init__.py
libs/langchain_v1/langchain/embeddings/__init__.py
"""Embeddings models. !!! warning "Modules moved" With the release of `langchain 1.0.0`, several embeddings modules were moved to `langchain-classic`, such as `CacheBackedEmbeddings` and all community embeddings. See [list](https://github.com/langchain-ai/langchain/blob/bdf1cd383ce36dc18381a3bf3fb0a579337a...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/langchain_v1/langchain/embeddings/base.py
libs/langchain_v1/langchain/embeddings/base.py
"""Factory functions for embeddings.""" import functools import importlib from collections.abc import Callable from typing import Any from langchain_core.embeddings import Embeddings def _call(cls: type[Embeddings], **kwargs: Any) -> Embeddings: return cls(**kwargs) _SUPPORTED_PROVIDERS: dict[str, tuple[str, ...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false
langchain-ai/langchain
https://github.com/langchain-ai/langchain/blob/e5d4acf681784d1ea356c932cf31c1c9723dbafa/libs/core/scripts/check_imports.py
libs/core/scripts/check_imports.py
"""Script to check if python modules can be imported.""" import random import string import sys import traceback from importlib.machinery import SourceFileLoader if __name__ == "__main__": files = sys.argv[1:] has_failure = False for file in files: try: module_name = "".join( ...
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/stores.py
libs/core/langchain_core/stores.py
"""**Store** implements the key-value stores and storage helpers. Module provides implementations of various key-value stores that conform to a simple key-value interface. The primary goal of these storages is to support implementation of caching. """ from abc import ABC, abstractmethod from collections.abc import 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/chat_sessions.py
libs/core/langchain_core/chat_sessions.py
"""**Chat Sessions** are a collection of messages and function calls.""" from collections.abc import Sequence from typing import TypedDict from langchain_core.messages import BaseMessage class ChatSession(TypedDict, total=False): """Chat Session. Chat Session represents a single conversation, channel, or o...
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/structured_query.py
libs/core/langchain_core/structured_query.py
"""Internal representation of a structured query language.""" from __future__ import annotations from abc import ABC, abstractmethod from enum import Enum from typing import TYPE_CHECKING, Any from pydantic import BaseModel if TYPE_CHECKING: from collections.abc import Sequence class Visitor(ABC): """Defi...
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/chat_loaders.py
libs/core/langchain_core/chat_loaders.py
"""Chat loaders.""" from abc import ABC, abstractmethod from collections.abc import Iterator from langchain_core.chat_sessions import ChatSession class BaseChatLoader(ABC): """Base class for chat loaders.""" @abstractmethod def lazy_load(self) -> Iterator[ChatSession]: """Lazy load the chat ses...
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/rate_limiters.py
libs/core/langchain_core/rate_limiters.py
"""Interface for a rate limiter and an in-memory rate limiter.""" from __future__ import annotations import abc import asyncio import threading import time class BaseRateLimiter(abc.ABC): """Base class for rate limiters. Usage of the base limiter is through the acquire and aacquire methods depending on...
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/chat_history.py
libs/core/langchain_core/chat_history.py
"""**Chat message history** stores a history of the message interactions in a chat.""" from __future__ import annotations from abc import ABC, abstractmethod from typing import TYPE_CHECKING from pydantic import BaseModel, Field from langchain_core.messages import ( AIMessage, BaseMessage, HumanMessage,...
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/exceptions.py
libs/core/langchain_core/exceptions.py
"""Custom **exceptions** for LangChain.""" from enum import Enum from typing import Any class LangChainException(Exception): # noqa: N818 """General LangChain exception.""" class TracerException(LangChainException): """Base class for exceptions in tracers module.""" class OutputParserException(ValueErro...
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/version.py
libs/core/langchain_core/version.py
"""langchain-core version information and utilities.""" VERSION = "1.2.6"
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/sys_info.py
libs/core/langchain_core/sys_info.py
"""Print information about the system and langchain packages for debugging purposes.""" import pkgutil import platform import re import sys from collections.abc import Sequence from importlib import metadata, util def _get_sub_deps(packages: Sequence[str]) -> list[str]: """Get any specified sub-dependencies.""" ...
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/prompt_values.py
libs/core/langchain_core/prompt_values.py
"""**Prompt values** for language model prompts. Prompt values are used to represent different pieces of prompts. They can be used to represent text, images, or chat message pieces. """ from __future__ import annotations from abc import ABC, abstractmethod from collections.abc import Sequence from typing import Lite...
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/retrievers.py
libs/core/langchain_core/retrievers.py
"""**Retriever** class returns Documents given a text **query**. It is more general than a vector store. A retriever does not need to be able to store documents, only to return (or retrieve) it. Vector stores can be used as the backbone of a retriever, but there are other types of retrievers as well. """ from __futur...
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/_import_utils.py
libs/core/langchain_core/_import_utils.py
from importlib import import_module def import_attr( attr_name: str, module_name: str | None, package: str | None, ) -> object: """Import an attribute from a module located in a package. This utility function is used in custom __getattr__ methods within __init__.py files to dynamically 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/__init__.py
libs/core/langchain_core/__init__.py
"""`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 ...
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/caches.py
libs/core/langchain_core/caches.py
"""Optional caching layer for language models. Distinct from provider-based [prompt caching](https://docs.langchain.com/oss/python/langchain/models#prompt-caching). !!! warning "Beta feature" This is a beta feature. Please be wary of deploying experimental code to production unless you've taken appropriate p...
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/globals.py
libs/core/langchain_core/globals.py
"""Global values and configuration that apply to all of LangChain.""" from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: from langchain_core.caches import BaseCache # DO NOT USE THESE VALUES DIRECTLY! # Use them only via `get_<X>()` and `set_<X>()` below, # or else your code may behave unexpectedly wi...
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/agents.py
libs/core/langchain_core/agents.py
"""Schema definitions for representing agent actions, observations, and return values. !!! warning The schema definitions are provided for backwards compatibility. !!! warning New agents should be built using the [`langchain` library](https://pypi.org/project/langchain/), which provides a simpler and ...
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/env.py
libs/core/langchain_core/env.py
"""Utilities for getting information about the runtime environment.""" import platform from functools import lru_cache from langchain_core import __version__ @lru_cache(maxsize=1) def get_runtime_environment() -> dict: """Get information about the LangChain runtime environment. Returns: A dictionar...
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/_api/path.py
libs/core/langchain_core/_api/path.py
import os from pathlib import Path HERE = Path(__file__).parent # Get directory of langchain package PACKAGE_DIR = HERE.parent SEPARATOR = os.sep def get_relative_path(file: Path | str, *, relative_to: Path = PACKAGE_DIR) -> str: """Get the path of the file as a relative path to the package directory. Args...
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/_api/beta_decorator.py
libs/core/langchain_core/_api/beta_decorator.py
"""Helper functions for marking parts of the LangChain API as beta. This module was loosely adapted from matplotlibs _api/deprecation.py module: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py !!! warning This module is for internal use only. Do not use it in your own code....
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/_api/deprecation.py
libs/core/langchain_core/_api/deprecation.py
"""Helper functions for deprecating parts of the LangChain API. This module was adapted from matplotlibs _api/deprecation.py module: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py !!! warning This module is for internal use only. Do not use it in your own code. We may chan...
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/_api/internal.py
libs/core/langchain_core/_api/internal.py
import inspect from typing import cast def is_caller_internal(depth: int = 2) -> bool: """Return whether the caller at `depth` of this function is internal.""" try: frame = inspect.currentframe() except AttributeError: return False if frame is None: return False try: ...
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/_api/__init__.py
libs/core/langchain_core/_api/__init__.py
"""Helper functions for managing the LangChain API. This module is only relevant for LangChain developers, not for users. !!! warning This module and its submodules are for internal use only. Do not use them in your own code. We may change the API at any time with no warning. """ from typing import TYPE_CH...
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/language_models/llms.py
libs/core/langchain_core/language_models/llms.py
"""Base interface for traditional large language models (LLMs) to expose. These are traditionally older models (newer models generally are chat models). """ from __future__ import annotations import asyncio import functools import inspect import json import logging from abc import ABC, abstractmethod from collection...
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/language_models/fake.py
libs/core/langchain_core/language_models/fake.py
"""Fake LLMs for testing purposes.""" import asyncio import time from collections.abc import AsyncIterator, Iterator, Mapping from typing import Any from typing_extensions import override from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) from langchain_core.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/language_models/chat_models.py
libs/core/langchain_core/language_models/chat_models.py
"""Chat models for conversational AI.""" from __future__ import annotations import asyncio import inspect import json import typing from abc import ABC, abstractmethod from collections.abc import AsyncIterator, Callable, Iterator, Sequence from functools import cached_property from operator import itemgetter from typ...
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/language_models/fake_chat_models.py
libs/core/langchain_core/language_models/fake_chat_models.py
"""Fake chat models for testing purposes.""" import asyncio import re import time from collections.abc import AsyncIterator, Iterator from typing import Any, Literal, cast from typing_extensions import override from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) ...
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/language_models/model_profile.py
libs/core/langchain_core/language_models/model_profile.py
"""Model profile types and utilities.""" from typing_extensions import TypedDict class ModelProfile(TypedDict, total=False): """Model profile. !!! warning "Beta feature" This is a beta feature. The format of model profiles is subject to change. Provides information about chat model capabilitie...
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/language_models/__init__.py
libs/core/langchain_core/language_models/__init__.py
"""Core language model abstractions. LangChain has two main classes to work with language models: chat models and "old-fashioned" LLMs (string-in, string-out). **Chat models** Language models that use a sequence of messages as inputs and return chat messages as outputs (as opposed to using plain text). Chat models ...
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/language_models/base.py
libs/core/langchain_core/language_models/base.py
"""Base language models class.""" from __future__ import annotations import warnings from abc import ABC, abstractmethod from collections.abc import Callable, Mapping, Sequence from functools import cache from typing import ( TYPE_CHECKING, Any, Literal, TypeAlias, TypeVar, cast, ) from 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/language_models/_utils.py
libs/core/langchain_core/language_models/_utils.py
import re from collections.abc import Sequence from typing import ( TYPE_CHECKING, Literal, TypedDict, TypeVar, ) if TYPE_CHECKING: from langchain_core.messages import BaseMessage from langchain_core.messages.content import ( ContentBlock, ) def is_openai_data_block( block: dict, filter_:...
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/example_selectors/length_based.py
libs/core/langchain_core/example_selectors/length_based.py
"""Select examples based on length.""" import re from collections.abc import Callable from pydantic import BaseModel, Field, model_validator from typing_extensions import Self from langchain_core.example_selectors.base import BaseExampleSelector from langchain_core.prompts.prompt import PromptTemplate def _get_len...
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/example_selectors/__init__.py
libs/core/langchain_core/example_selectors/__init__.py
"""Example selectors. **Example selector** implements logic for selecting examples to include them in prompts. This allows us to select examples that are most relevant to the input. """ from typing import TYPE_CHECKING from langchain_core._import_utils import import_attr if TYPE_CHECKING: from langchain_core.ex...
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/example_selectors/semantic_similarity.py
libs/core/langchain_core/example_selectors/semantic_similarity.py
"""Example selector that selects examples based on SemanticSimilarity.""" from __future__ import annotations from abc import ABC from typing import TYPE_CHECKING, Any from pydantic import BaseModel, ConfigDict from langchain_core.example_selectors.base import BaseExampleSelector from langchain_core.vectorstores imp...
python
MIT
e5d4acf681784d1ea356c932cf31c1c9723dbafa
2026-01-04T14:38:15.444279Z
false