sample_id stringlengths 21 196 | text stringlengths 105 936k | metadata dict | category stringclasses 6
values |
|---|---|---|---|
langchain-ai/langchain:libs/partners/openrouter/tests/unit_tests/test_chat_models.py | """Unit tests for `ChatOpenRouter` chat model."""
from __future__ import annotations
import warnings
from typing import Any, Literal
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from langchain_core.load import dumpd, dumps, load
from langchain_core.messages import (
AIMessage,
AIMessag... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/openrouter/tests/unit_tests/test_chat_models.py",
"license": "MIT License",
"lines": 2502,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/openrouter/tests/unit_tests/test_imports.py | """Test `langchain_openrouter` public API surface."""
from langchain_openrouter import __all__
EXPECTED_ALL = [
"ChatOpenRouter",
]
def test_all_imports() -> None:
"""Verify that __all__ exports match the expected public API."""
assert sorted(EXPECTED_ALL) == sorted(__all__)
| {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/openrouter/tests/unit_tests/test_imports.py",
"license": "MIT License",
"lines": 8,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/openrouter/tests/unit_tests/test_standard.py | """Standard unit tests for `ChatOpenRouter`."""
from langchain_tests.unit_tests import ChatModelUnitTests
from langchain_openrouter.chat_models import ChatOpenRouter
MODEL_NAME = "openai/gpt-4o-mini"
class TestChatOpenRouterUnit(ChatModelUnitTests):
"""Standard unit tests for `ChatOpenRouter` chat model."""
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/openrouter/tests/unit_tests/test_standard.py",
"license": "MIT License",
"lines": 49,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/core/langchain_core/_security/_ssrf_protection.py | """SSRF Protection for validating URLs against Server-Side Request Forgery attacks.
This module provides utilities to validate user-provided URLs and prevent SSRF attacks
by blocking requests to:
- Private IP ranges (RFC 1918, loopback, link-local)
- Cloud metadata endpoints (AWS, GCP, Azure, etc.)
- Localhost address... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/langchain_core/_security/_ssrf_protection.py",
"license": "MIT License",
"lines": 284,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/core/tests/unit_tests/test_ssrf_protection.py | """Tests for SSRF protection utilities."""
from typing import Any
import pytest
from pydantic import BaseModel, ValidationError
from langchain_core._security._ssrf_protection import (
SSRFProtectedUrl,
SSRFProtectedUrlRelaxed,
is_cloud_metadata,
is_localhost,
is_private_ip,
is_safe_url,
v... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/test_ssrf_protection.py",
"license": "MIT License",
"lines": 226,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py | """Unit tests for ExtendedModelResponse command support in wrap_model_call.
Tests that wrap_model_call middleware can return ExtendedModelResponse to provide
a Command alongside the model response. Commands are applied as separate state
updates through graph reducers (e.g. add_messages for messages).
"""
from collect... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py",
"license": "MIT License",
"lines": 745,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
... | test |
langchain-ai/langchain:libs/standard-tests/langchain_tests/integration_tests/sandboxes.py | """Integration tests for the deepagents sandbox backend abstraction.
Implementers should subclass this test suite and provide a fixture that returns a
clean `SandboxBackendProtocol` instance.
Example:
```python
from __future__ import annotations
from collections.abc import Iterator
import pytest
from deepagents.bac... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/standard-tests/langchain_tests/integration_tests/sandboxes.py",
"license": "MIT License",
"lines": 323,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_backwards_compat.py | """Test backwards compatibility for middleware type parameters.
This file verifies that middlewares written BEFORE the ResponseT change still work.
All patterns that were valid before should remain valid.
Run type check: uv run --group typing mypy <this file>
Run tests: uv run --group test pytest <this file> -v
"""
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_backwards_compat.py",
"license": "MIT License",
"lines": 221,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_type_errors.py | """Demonstrate type errors that mypy catches for ContextT and ResponseT mismatches.
This file contains intentional type errors to demonstrate that mypy catches them.
Run: uv run --group typing mypy <this file>
Expected errors:
1. TypedDict "UserContext" has no key "session_id" - accessing wrong context field
2. Argum... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_type_errors.py",
"license": "MIT License",
"lines": 164,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"tem... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_typing.py | """Test file to verify type safety in middleware (ContextT and ResponseT).
This file demonstrates:
1. Backwards compatible middlewares (no type params specified) - works with defaults
2. Correctly typed middlewares (ContextT/ResponseT match) - full type safety
3. Type errors that are caught when types don't match
Run... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_typing.py",
"license": "MIT License",
"lines": 345,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_fetch_last_ai_and_tool_messages.py | """Unit tests for _fetch_last_ai_and_tool_messages helper function.
These tests verify that the helper function correctly handles edge cases,
including the scenario where no AIMessage exists in the message list
(fixes issue #34792).
"""
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolM... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_fetch_last_ai_and_tool_messages.py",
"license": "MIT License",
"lines": 78,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_dynamic_tools.py | """Tests for dynamic tool registration via middleware.
These tests verify that middleware can dynamically register and handle tools
that are not declared upfront when creating the agent.
"""
import asyncio
from collections.abc import Awaitable, Callable
from typing import Any
import pytest
from langchain_core.messag... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_dynamic_tools.py",
"license": "MIT License",
"lines": 333,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
... | test |
langchain-ai/langchain:libs/core/scripts/check_version.py | """Check version consistency between `pyproject.toml` and `version.py`.
This script validates that the version defined in pyproject.toml matches the `VERSION`
variable in `langchain_core/version.py`. Intended for use as a pre-commit hook to
prevent version mismatches.
"""
import re
import sys
from pathlib import Path... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/scripts/check_version.py",
"license": "MIT License",
"lines": 47,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain_v1/scripts/check_version.py | """Check version consistency between pyproject.toml and __init__.py.
This script validates that the version defined in pyproject.toml matches
the __version__ variable in langchain/__init__.py. Intended for use as
a pre-commit hook to prevent version mismatches.
"""
import re
import sys
from pathlib import Path
def ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/scripts/check_version.py",
"license": "MIT License",
"lines": 47,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_kwargs_tool_runtime_injection.py | """Test that config/runtime in args_schema aren't injected to **kwargs functions."""
from __future__ import annotations
from typing import Any
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_core.tools import StructuredTool
from pydantic import BaseModel, Field
from langchain.agents imp... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_kwargs_tool_runtime_injection.py",
"license": "MIT License",
"lines": 45,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/test_version.py | """Test that package version is consistent across configuration files."""
from pathlib import Path
import toml
import langchain
def test_version_matches_pyproject() -> None:
"""Verify that __version__ in __init__.py matches version in pyproject.toml."""
# Get the version from the package __init__.py
in... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/test_version.py",
"license": "MIT License",
"lines": 19,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/core/tests/unit_tests/utils/test_formatting.py | """Tests for langchain_core.utils.formatting."""
import pytest
from langchain_core.utils.formatting import StrictFormatter, formatter
class TestStrictFormatter:
"""Tests for the `StrictFormatter` class."""
def test_vformat_with_keyword_args(self) -> None:
"""Test that `vformat` works with keyword a... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/utils/test_formatting.py",
"license": "MIT License",
"lines": 103,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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 Pydanti version
based on the langsmith `Run` model. They're intended for langsmith objects (`Run`,
`Example`) which migrate together.
For general Pydantic v1... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/langchain_core/tracers/_compat.py",
"license": "MIT License",
"lines": 67,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
langchain-ai/langchain:libs/partners/fireworks/tests/unit_tests/test_chat_models.py | """Unit tests for ChatFireworks."""
from __future__ import annotations
from langchain_core.messages import AIMessage
from langchain_fireworks.chat_models import _convert_dict_to_message
def test_convert_dict_to_message_with_reasoning_content() -> None:
"""Test that reasoning_content is correctly extracted from... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/fireworks/tests/unit_tests/test_chat_models.py",
"license": "MIT License",
"lines": 27,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/core/langchain_core/load/_validation.py | """Validation utilities for LangChain serialization.
Provides escape-based protection against injection attacks in serialized objects. The
approach uses an allowlist design: only dicts explicitly produced by
`Serializable.to_json()` are treated as LC objects during deserialization.
## How escaping works
During seria... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/langchain_core/load/_validation.py",
"license": "MIT License",
"lines": 132,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
langchain-ai/langchain:libs/core/tests/unit_tests/load/test_secret_injection.py | """Tests for secret injection prevention in serialization.
Verify that user-provided data containing secret-like structures cannot be used to
extract environment variables during deserialization.
"""
import json
import os
import re
from typing import Any
from unittest import mock
import pytest
from pydantic import B... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/load/test_secret_injection.py",
"license": "MIT License",
"lines": 343,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/core/tests/unit_tests/tracers/test_automatic_metadata.py | """Test automatic tool call count storage in tracers."""
from __future__ import annotations
from unittest.mock import MagicMock
from langchain_core.messages import AIMessage
from langchain_core.messages.tool import ToolCall
from langchain_core.outputs import ChatGeneration, LLMResult
from langchain_core.tracers.core... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/tracers/test_automatic_metadata.py",
"license": "MIT License",
"lines": 113,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/perplexity/langchain_perplexity/_utils.py | import os
from typing import Any
from langchain_core.utils import convert_to_secret_str
from perplexity import Perplexity
def initialize_client(values: dict[str, Any]) -> dict[str, Any]:
"""Initialize the Perplexity client."""
pplx_api_key = (
values.get("pplx_api_key")
or os.environ.get("PPL... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/langchain_perplexity/_utils.py",
"license": "MIT License",
"lines": 19,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/partners/perplexity/langchain_perplexity/retrievers.py | from __future__ import annotations
from typing import Any, Literal
from langchain_core.callbacks import CallbackManagerForRetrieverRun
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from pydantic import Field, SecretStr, model_validator
from langchain_perplexity._ut... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/langchain_perplexity/retrievers.py",
"license": "MIT License",
"lines": 58,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/partners/perplexity/langchain_perplexity/tools.py | from __future__ import annotations
from typing import Any, Literal
from langchain_core.callbacks import CallbackManagerForToolRun
from langchain_core.tools import BaseTool
from pydantic import Field, SecretStr, model_validator
from langchain_perplexity._utils import initialize_client
class PerplexitySearchResults(... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/langchain_perplexity/tools.py",
"license": "MIT License",
"lines": 58,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/partners/perplexity/langchain_perplexity/types.py | from __future__ import annotations
from typing import Literal
from pydantic import BaseModel
class UserLocation(BaseModel):
latitude: float | None = None
longitude: float | None = None
country: str | None = None
region: str | None = None
city: str | None = None
class WebSearchOptions(BaseModel... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/langchain_perplexity/types.py",
"license": "MIT License",
"lines": 19,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/partners/perplexity/tests/integration_tests/test_chat_models.py | """Integration tests for ChatPerplexity."""
import os
import pytest
from langchain_core.messages import HumanMessage
from langchain_perplexity import ChatPerplexity, MediaResponse, WebSearchOptions
@pytest.mark.skipif(not os.environ.get("PPLX_API_KEY"), reason="PPLX_API_KEY not set")
class TestChatPerplexityIntegr... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/tests/integration_tests/test_chat_models.py",
"license": "MIT License",
"lines": 104,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/perplexity/tests/integration_tests/test_search_api.py | """Integration tests for Perplexity Search API."""
import os
import pytest
from langchain_core.documents import Document
from langchain_perplexity import PerplexitySearchResults, PerplexitySearchRetriever
@pytest.mark.skipif(not os.environ.get("PPLX_API_KEY"), reason="PPLX_API_KEY not set")
class TestPerplexitySea... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/tests/integration_tests/test_search_api.py",
"license": "MIT License",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/perplexity/tests/unit_tests/test_retrievers.py | from unittest.mock import MagicMock
from pytest_mock import MockerFixture
from langchain_perplexity import PerplexitySearchRetriever
def test_search_retriever_initialization() -> None:
retriever = PerplexitySearchRetriever(pplx_api_key="test")
assert retriever.pplx_api_key.get_secret_value() == "test"
a... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/tests/unit_tests/test_retrievers.py",
"license": "MIT License",
"lines": 30,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/perplexity/tests/unit_tests/test_tools.py | from unittest.mock import MagicMock
from pytest_mock import MockerFixture
from langchain_perplexity import PerplexitySearchResults
def test_search_tool_run(mocker: MockerFixture) -> None:
tool = PerplexitySearchResults(pplx_api_key="test")
mock_result = MagicMock()
mock_result.title = "Test Title"
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/tests/unit_tests/test_tools.py",
"license": "MIT License",
"lines": 25,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_agent_name.py | """Test agent name parameter in create_agent.
This module tests that the name parameter correctly sets .name on AIMessage outputs.
"""
from __future__ import annotations
from langchain_core.messages import (
AIMessage,
HumanMessage,
ToolCall,
)
from langchain_core.tools import tool
from langchain.agents... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_agent_name.py",
"license": "MIT License",
"lines": 169,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/core/tests/unit_tests/messages/block_translators/test_google_genai.py | """Tests for Google GenAI block translator."""
from langchain_core.messages.block_translators.google_genai import (
translate_grounding_metadata_to_citations,
)
def test_translate_grounding_metadata_web() -> None:
"""Test translation of web grounding metadata to citations."""
grounding_metadata = {
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/messages/block_translators/test_google_genai.py",
"license": "MIT License",
"lines": 193,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/langchain_core/utils/uuid.py",
"license": "MIT License",
"lines": 41,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/core/tests/unit_tests/utils/test_uuid_utils.py | import time
from uuid import UUID
from langchain_core.utils.uuid import uuid7
def _uuid_v7_ms(uuid_obj: UUID | str) -> int:
"""Extract milliseconds since epoch from a UUIDv7 using string layout.
UUIDv7 stores Unix time in ms in the first 12 hex chars of the canonical
string representation (48 msb bits).... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/utils/test_uuid_utils.py",
"license": "MIT License",
"lines": 28,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_system_message.py | """Comprehensive unit tests for system message handling in agents.
This module consolidates all system message and dynamic prompt tests:
- Basic system message scenarios (none, string, SystemMessage)
- ModelRequest system_message field support
- System message updates via middleware
- Multiple middleware chaining
- Ca... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_system_message.py",
"license": "MIT License",
"lines": 901,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/langchain_core/language_models/model_profile.py",
"license": "MIT License",
"lines": 63,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
langchain-ai/langchain:libs/model-profiles/langchain_model_profiles/cli.py | """CLI for refreshing model profile data from models.dev."""
import argparse
import json
import re
import sys
import tempfile
from pathlib import Path
from typing import Any
import httpx
try:
import tomllib # type: ignore[import-not-found] # Python 3.11+
except ImportError:
import tomli as tomllib # type:... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/model-profiles/langchain_model_profiles/cli.py",
"license": "MIT License",
"lines": 299,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/model-profiles/tests/unit_tests/test_cli.py | """Tests for CLI functionality."""
import importlib.util
from pathlib import Path
from unittest.mock import Mock, patch
import pytest
from langchain_model_profiles.cli import _model_data_to_profile, refresh
@pytest.fixture
def mock_models_dev_response() -> dict:
"""Create a mock response from models.dev API.""... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/model-profiles/tests/unit_tests/test_cli.py",
"license": "MIT License",
"lines": 251,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/model_retry.py",
"license": "MIT License",
"lines": 249,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py | """Tests for ModelRetryMiddleware functionality."""
import time
from collections.abc import Callable
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 ChatGenera... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py",
"license": "MIT License",
"lines": 553,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"templ... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py | r"""Test response_format for langchain-openai.
If tests fail, cassettes may need to be re-recorded.
To re-record cassettes:
1. Delete existing cassettes (`rm tests/cassettes/test_inference_to_*.yaml.gz`)
2. Re run the tests with a valid OPENAI_API_KEY in your environment:
```bash
OPENAI_API_KEY=... uv run python -m ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py",
"license": "MIT License",
"lines": 147,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_diagram.py | from collections.abc import Callable
from typing import Any
from langgraph.runtime import Runtime
from syrupy.assertion import SnapshotAssertion
from langchain.agents import AgentState
from langchain.agents.factory import create_agent
from langchain.agents.middleware.types import AgentMiddleware, ModelRequest, ModelR... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_diagram.py",
"license": "MIT License",
"lines": 149,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py | import sys
from collections.abc import Awaitable, Callable
from typing import Annotated, Any, Generic
import pytest
from langchain_core.language_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage
from langchain_core.tools import InjectedToolCallId, too... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py",
"license": "MIT License",
"lines": 839,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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 import InterruptOnConfig
from langchain.agents.middleware.human_in_the_loop import (
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_human_in_the_loop.py",
"license": "MIT License",
"lines": 637,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
... | test |
langchain-ai/langchain: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 langgraph.runtime import Runtime
from langchain.agents.factory import create_agent
from langchain.agents.middleware.model_call_limit im... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py",
"license": "MIT License",
"lines": 181,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"... | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_summarization.py | from collections.abc import Iterable
from typing import Any
from unittest.mock import patch
import pytest
from langchain_core.callbacks import AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun
from langchain_core.language_models import ModelProfile
from langchain_core.language_models.base import (
LanguageMo... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_summarization.py",
"license": "MIT License",
"lines": 1086,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"te... | test |
langchain-ai/langchain: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, Any, cast
import pytest
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from langchain.agents.factor... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py",
"license": "MIT License",
"lines": 667,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": "... | test |
langchain-ai/langchain:libs/core/tests/unit_tests/messages/block_translators/test_groq.py | """Test groq block translator."""
from typing import cast
import pytest
from langchain_core.messages import AIMessage
from langchain_core.messages import content as types
from langchain_core.messages.base import _extract_reasoning_from_additional_kwargs
from langchain_core.messages.block_translators import PROVIDER_... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/messages/block_translators/test_groq.py",
"license": "MIT License",
"lines": 113,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/perplexity/tests/unit_tests/test_output_parsers.py | """Unit tests for output parsers."""
import pytest
from langchain_core.exceptions import OutputParserException
from langchain_core.outputs import Generation
from pydantic import BaseModel, Field
from langchain_perplexity.output_parsers import (
ReasoningJsonOutputParser,
ReasoningStructuredOutputParser,
s... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/perplexity/tests/unit_tests/test_output_parsers.py",
"license": "MIT License",
"lines": 312,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/huggingface/tests/integration_tests/test_chat_models.py | from langchain_core.messages import AIMessageChunk
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
def test_stream_usage() -> None:
"""Test we are able to configure stream options on models that require it."""
llm = HuggingFaceEndpoint( # type: ignore[call-arg] # (model is inferred i... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/huggingface/tests/integration_tests/test_chat_models.py",
"license": "MIT License",
"lines": 16,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_create_agent_tool_validation.py | import sys
from typing import Annotated, Any
import pytest
from langchain_core.messages import HumanMessage
from langgraph.prebuilt import InjectedStore, ToolRuntime
from langgraph.store.base import BaseStore
from langgraph.store.memory import InMemoryStore
from langchain.agents import AgentState, create_agent
from l... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_create_agent_tool_validation.py",
"license": "MIT License",
"lines": 325,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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.... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/integration_tests/agents/middleware/test_shell_tool_integration.py",
"license": "MIT License",
"lines": 115,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"tem... | test |
langchain-ai/langchain:libs/partners/xai/tests/integration_tests/test_chat_models.py | """Integration tests for ChatXAI specific features."""
from __future__ import annotations
from typing import Literal
import pytest
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessageChunk
from langchain_xai import ChatXAI
MODEL_NAME = "grok-4-fast-reasoning"
@pytest.mark.parametrize("outpu... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/xai/tests/integration_tests/test_chat_models.py",
"license": "MIT License",
"lines": 97,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_return_direct_graph.py | """Tests for return_direct tool graph structure."""
from langchain_core.tools import tool
from syrupy.assertion import SnapshotAssertion
from langchain.agents.factory import create_agent
from tests.unit_tests.agents.model import FakeToolCallingModel
def test_agent_graph_without_return_direct_tools(snapshot: Snapsho... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_return_direct_graph.py",
"license": "MIT License",
"lines": 54,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/_execution.py",
"license": "MIT License",
"lines": 333,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/_redaction.py",
"license": "MIT License",
"lines": 354,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/shell_tool.py",
"license": "MIT License",
"lines": 753,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/langchain_anthropic/middleware/bash.py | """Anthropic-specific middleware for the Claude bash tool."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from typing import Any
from langchain.agents.middleware.shell_tool import ShellToolMiddleware
from langchain.agents.middleware.types import (
ModelRequest,
ModelRes... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/langchain_anthropic/middleware/bash.py",
"license": "MIT License",
"lines": 71,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/tests/unit_tests/middleware/test_bash.py | from __future__ import annotations
from unittest.mock import MagicMock
import pytest
pytest.importorskip(
"anthropic", reason="Anthropic SDK is required for Claude middleware tests"
)
from langchain_anthropic.middleware.bash import ClaudeBashToolMiddleware
def test_creates_bash_tool(monkeypatch: pytest.Monkey... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/tests/unit_tests/middleware/test_bash.py",
"license": "MIT License",
"lines": 45,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/file_search.py",
"license": "MIT License",
"lines": 305,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py | """Anthropic text editor and memory tool middleware.
This module provides client-side implementations of Anthropic's text editor and
memory tools using schema-less tool definitions and tool call interception.
"""
from __future__ import annotations
import os
import shutil
from datetime import datetime, timezone
from ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py",
"license": "MIT License",
"lines": 980,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/langchain_anthropic/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 re
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING, Literal,... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/langchain_anthropic/middleware/file_search.py",
"license": "MIT License",
"lines": 274,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py | """Unit tests for Anthropic text editor and memory tool middleware."""
from unittest.mock import MagicMock
import pytest
from langchain_core.messages import SystemMessage, ToolMessage
from langgraph.types import Command
from langchain_anthropic.middleware.anthropic_tools import (
AnthropicToolsState,
StateCl... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py",
"license": "MIT License",
"lines": 358,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/anthropic/tests/unit_tests/middleware/test_file_search.py | """Unit tests for file search middleware."""
from langchain_anthropic.middleware.anthropic_tools import AnthropicToolsState
from langchain_anthropic.middleware.file_search import (
StateFileSearchMiddleware,
)
class TestSearchMiddlewareInitialization:
"""Test search middleware initialization."""
def tes... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/tests/unit_tests/middleware/test_file_search.py",
"license": "MIT License",
"lines": 468,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_state_schema.py | """Test state_schema parameter in create_agent.
This module tests that the state_schema parameter allows users to extend
AgentState without needing to create custom middleware.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Annotated, Any
from langchain_core.messages import HumanMessage
fr... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_state_schema.py",
"license": "MIT License",
"lines": 192,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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, Any
from langchain_core.messages import ToolMessage
from langchain.agents.middleware._retry import (
OnFailure,
RetryOn,
calculate_delay,
should_ret... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/tool_retry.py",
"license": "MIT License",
"lines": 316,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | documentation |
langchain-ai/langchain:libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py | """Test ToolRuntime injection with create_agent.
This module tests the injected runtime functionality when using tools
with the create_agent factory. The ToolRuntime provides tools access to:
- state: Current graph state
- tool_call_id: ID of the current tool call
- config: RunnableConfig for the execution
- context: ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py",
"license": "MIT License",
"lines": 682,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
... | test |
langchain-ai/langchain:libs/partners/openai/langchain_openai/middleware/openai_moderation.py | """Agent middleware that integrates OpenAI's moderation endpoint."""
from __future__ import annotations
import json
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Literal, cast
from langchain.agents.middleware.types import AgentMiddleware, AgentState, hook_config
from langchain_core.mess... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/openai/langchain_openai/middleware/openai_moderation.py",
"license": "MIT License",
"lines": 393,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/openai/tests/unit_tests/middleware/test_openai_moderation_middleware.py | from __future__ import annotations
from collections.abc import Mapping
from copy import deepcopy
from typing import Any, cast
from unittest.mock import Mock
import pytest
from langchain.agents.middleware.types import AgentState
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from openai.types... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/openai/tests/unit_tests/middleware/test_openai_moderation_middleware.py",
"license": "MIT License",
"lines": 157,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template... | test |
langchain-ai/langchain:libs/partners/mistralai/langchain_mistralai/_compat.py | """Derivations of standard content blocks from mistral content."""
from __future__ import annotations
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.block_translators import register_translator
def _convert_from_v1_to_m... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/mistralai/langchain_mistralai/_compat.py",
"license": "MIT License",
"lines": 103,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py | """Anthropic prompt caching middleware.
Requires:
- `langchain`: For agent middleware framework
- `langchain-anthropic`: For `ChatAnthropic` model (already a dependency)
"""
from collections.abc import Awaitable, Callable
from typing import Literal
from warnings import warn
from langchain_anthropic.chat_mode... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py",
"license": "MIT License",
"lines": 120,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py | """Tests for Anthropic prompt caching middleware."""
import warnings
from typing import Any, cast
from unittest.mock import MagicMock
import pytest
from langchain.agents.middleware.types import ModelRequest, ModelResponse
from langchain_core.callbacks import (
AsyncCallbackManagerForLLMRun,
CallbackManagerFor... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py",
"license": "MIT License",
"lines": 465,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain:libs/partners/groq/langchain_groq/_compat.py | from __future__ import annotations
import json
from typing import Any, cast
from langchain_core.messages import content as types
def _convert_from_v1_to_groq(
content: list[types.ContentBlock],
model_provider: str | None,
) -> tuple[list[dict[str, Any] | str], dict]:
new_content: list = []
new_addit... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/groq/langchain_groq/_compat.py",
"license": "MIT License",
"lines": 60,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/partners/fireworks/langchain_fireworks/_compat.py | """Converts between AIMessage output formats, governed by `output_version`."""
from __future__ import annotations
from langchain_core.messages import AIMessage
def _convert_from_v1_to_chat_completions(message: AIMessage) -> AIMessage:
"""Convert a v1 message to the Chat Completions format."""
if isinstance(... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/partners/fireworks/langchain_fireworks/_compat.py",
"license": "MIT License",
"lines": 21,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain_v1/langchain/agents/middleware/tool_emulator.py | """Tool emulator middleware for testing."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Generic
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import HumanMessage, ToolMessage
from langchain.agents.middleware.types import AgentMiddlewa... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/tool_emulator.py",
"license": "MIT License",
"lines": 160,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/core/tests/unit_tests/prompts/test_string.py | import pytest
from packaging import version
from langchain_core.prompts.string import get_template_variables, mustache_schema
from langchain_core.utils.pydantic import PYDANTIC_VERSION
PYDANTIC_VERSION_AT_LEAST_29 = version.parse("2.9") <= PYDANTIC_VERSION
@pytest.mark.skipif(
not PYDANTIC_VERSION_AT_LEAST_29,
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/core/tests/unit_tests/prompts/test_string.py",
"license": "MIT License",
"lines": 35,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
langchain-ai/langchain: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
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/context_editing.py",
"license": "MIT License",
"lines": 232,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain: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,
AgentState,
ContextT,
ModelRequest,
ModelResponse,
ResponseT,
)
from langchain.chat_models import init_chat_model
i... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/model_fallback.py",
"license": "MIT License",
"lines": 111,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain: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, Any, Literal, Union
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import AIMessage, HumanMessa... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/tool_selection.py",
"license": "MIT License",
"lines": 283,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain: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 (
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain_v1/langchain/agents/middleware/pii.py",
"license": "MIT License",
"lines": 305,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/langchain/langchain_classic/adapters/openai.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.adapters.openai import (
Chat,
ChatCompletion,
ChatCompletionChunk,
ChatCompletions,
Choice,
ChoiceChunk,
Completions,
... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/adapters/openai.py",
"license": "MIT License",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent.py | """Chain that takes in an input and produces an action and action input."""
from __future__ import annotations
import asyncio
import builtins
import contextlib
import json
import logging
import time
from abc import abstractmethod
from collections.abc import AsyncIterator, Callable, Iterator, Sequence
from pathlib imp... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent.py",
"license": "MIT License",
"lines": 1569,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/ainetwork/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
#... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/ainetwork/toolkit.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/amadeus/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# han... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/amadeus/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/clickup/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.clickup.toolkit import ClickupToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# han... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/clickup/toolkit.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/conversational_retrieval/openai_functions.py | from typing import Any
from langchain_core.language_models import BaseLanguageModel
from langchain_core.messages import SystemMessage
from langchain_core.prompts.chat import MessagesPlaceholder
from langchain_core.tools import BaseTool
from langchain_classic.agents.agent import AgentExecutor
from langchain_classic.ag... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/conversational_retrieval/openai_functions.py",
"license": "MIT License",
"lines": 76,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1... | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/file_management/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.file_management.toolkit import (
FileManagementToolkit,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raisin... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/file_management/toolkit.py",
"license": "MIT License",
"lines": 21,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""... | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/github/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.github.toolkit import (
BranchName,
CommentOnIssue,
CreateFile,
CreatePR,
CreateReviewRequest,
DeleteFile,
Dire... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/github/toolkit.py",
"license": "MIT License",
"lines": 61,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/gitlab/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.gitlab.toolkit import GitLabToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handl... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/gitlab/toolkit.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/gmail/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.gmail.toolkit import GmailToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handlin... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/gmail/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/jira/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.jira.toolkit import JiraToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/jira/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/json/base.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.json.base import create_json_agent
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handli... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/json/base.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/json/prompt.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.json.prompt import JSON_PREFIX, JSON_SUFFIX
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/json/prompt.py",
"license": "MIT License",
"lines": 16,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/json/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/json/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/multion/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.multion.toolkit import MultionToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# han... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/multion/toolkit.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/nasa/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/nasa/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/nla/tool.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.nla.tool import NLATool
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/nla/tool.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/nla/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.nla.toolkit import NLAToolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling op... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/nla/toolkit.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/office365/toolkit.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.office365.toolkit import O365Toolkit
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# hand... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/office365/toolkit.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
langchain-ai/langchain:libs/langchain/langchain_classic/agents/agent_toolkits/openapi/base.py | from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.agent_toolkits.openapi.base import create_openapi_agent
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# ... | {
"repo_id": "langchain-ai/langchain",
"file_path": "libs/langchain/langchain_classic/agents/agent_toolkits/openapi/base.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.