The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
chore(langchain_v1): remove unused internal namespace (#33352)
Eugene Yurtsev97f731da7e91
diff --git a/libs/langchain_v1/langchain/_internal/__init__.py b/libs/langchain_v1/langchain/_internal/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/libs/langchain_v1/langchain/_internal/_documents.py b/libs/langchain_v1/langchain/_internal/_documents.pydeleted file mode 100644index 32297896c6..0000000000--- a/libs/langchain_v1/langchain/_internal/_documents.py+++ /dev/null@@ -1,35 +0,0 @@-"""Internal document utilities."""--from __future__ import annotations--from typing import TYPE_CHECKING--if TYPE_CHECKING:- from langchain_core.documents import Document---def format_document_xml(doc: Document) -> str:- """Format a document as XML-like structure for LLM consumption.-- Args:- doc: Document to format-- Returns:- Document wrapped in XML tags:- <document>- <id>...</id>- <content>...</content>- <metadata>...</metadata>- </document>-- !!! note- Does not generate valid XML or escape special characters. Intended for- semi-structured LLM input only.-- """- id_str = f"<id>{doc.id}</id>" if doc.id is not None else "<id></id>"- metadata_str = ""- if doc.metadata:- metadata_items = [f"{k}: {v!s}" for k, v in doc.metadata.items()]- metadata_str = f"<metadata>{', '.join(metadata_items)}</metadata>"- return f"<document>{id_str}<content>{doc.page_content}</content>{metadata_str}</document>"diff --git a/libs/langchain_v1/langchain/_internal/_lazy_import.py b/libs/langchain_v1/langchain/_internal/_lazy_import.pydeleted file mode 100644index 35eadc203f..0000000000--- a/libs/langchain_v1/langchain/_internal/_lazy_import.py+++ /dev/null@@ -1,35 +0,0 @@-"""Lazy import utilities."""--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 attributes.-- Args:- attr_name: The name of the attribute to import.- module_name: The name of the module to import from. If None, the attribute- is imported from the package itself.- package: The name of the package where the module is located.- """- if module_name == "__module__" or module_name is None:- try:- result = import_module(f".{attr_name}", package=package)- except ModuleNotFoundError:- msg = f"module '{package!r}' has no attribute {attr_name!r}"- raise AttributeError(msg) from None- else:- try:- module = import_module(f".{module_name}", package=package)- except ModuleNotFoundError as err:- msg = f"module '{package!r}.{module_name!r}' not found ({err})"- raise ImportError(msg) from None- result = getattr(module, attr_name)- return resultdiff --git a/libs/langchain_v1/langchain/_internal/_prompts.py b/libs/langchain_v1/langchain/_internal/_prompts.pydeleted file mode 100644index 6cfc569e3e..0000000000--- a/libs/langchain_v1/langchain/_internal/_prompts.py+++ /dev/null@@ -1,158 +0,0 @@-"""Internal prompt resolution utilities.--This module provides utilities for resolving different types of prompt specifications-into standardized message formats for language models. It supports both synchronous-and asynchronous prompt resolution with automatic detection of callable types.--The module is designed to handle common prompt patterns across LangChain components,-particularly for summarization chains and other document processing workflows.--"""--from __future__ import annotations--import inspect-from typing import TYPE_CHECKING--if TYPE_CHECKING:- from collections.abc import Awaitable, Callable-- from langchain_core.messages import MessageLikeRepresentation- from langgraph.runtime import Runtime-- from langchain._internal._typing import ContextT, StateT---def resolve_prompt(- prompt: str | None | Callable[[StateT, Runtime[ContextT]], list[MessageLikeRepresentation]],- state: StateT,- runtime: Runtime[ContextT],- default_user_content: str,- default_system_content: str,-) -> list[MessageLikeRepresentation]:- """Resolve a prompt specification into a list of messages.-- Handles prompt resolution across different strategies. Supports callable functions,- string system messages, and None for default behavior.-- Args:- prompt: The prompt specification to resolve. Can be:- - Callable: Function taking (state, runtime) returning message list.- - str: A system message string.- - None: Use the provided default system message.- state: Current state, passed to callable prompts.- runtime: LangGraph runtime instance, passed to callable prompts.- default_user_content: User content to include (e.g., document text).- default_system_content: Default system message when prompt is None.-- Returns:- List of message dictionaries for language models, typically containing- a system message and user message with content.-- Raises:- TypeError: If prompt type is not str, None, or callable.-- Example:- ```python- def custom_prompt(state, runtime):- return [{"role": "system", "content": "Custom"}]--- messages = resolve_prompt(custom_prompt, state, runtime, "content", "default")- messages = resolve_prompt("Custom system", state, runtime, "content", "default")- messages = resolve_prompt(None, state, runtime, "content", "Default")- ```-- !!! note- Callable prompts have full control over message structure and content parameter- is ignored. String/None prompts create standard system + user structure.-- """- if callable(prompt):- return prompt(state, runtime)- if isinstance(prompt, str):- system_msg = prompt- elif prompt is None:- system_msg = default_system_content- else:- msg = f"Invalid prompt type: {type(prompt)}. Expected str, None, or callable."- raise TypeError(msg)-- return [- {"role": "system", "content": system_msg},- {"role": "user", "content": default_user_content},- ]---async def aresolve_prompt(- prompt: str- | None- | Callable[[StateT, Runtime[ContextT]], list[MessageLikeRepresentation]]- | Callable[[StateT, Runtime[ContextT]], Awaitable[list[MessageLikeRepresentation]]],- state: StateT,- runtime: Runtime[ContextT],- default_user_content: str,- default_system_content: str,-) -> list[MessageLikeRepresentation]:- """Async version of resolve_prompt supporting both sync and async callables.-- Handles prompt resolution across different strategies. Supports sync/async callable- functions, string system messages, and None for default behavior.-- Args:- prompt: The prompt specification to resolve. Can be:- - Callable (sync): Function taking (state, runtime) returning message list.- - Callable (async): Async function taking (state, runtime) returning- awaitable message list.- - str: A system message string.- - None: Use the provided default system message.- state: Current state, passed to callable prompts.- runtime: LangGraph runtime instance, passed to callable prompts.- default_user_content: User content to include (e.g., document text).- default_system_content: Default system message when prompt is None.-- Returns:- List of message dictionaries for language models, typically containing- a system message and user message with content.-- Raises:- TypeError: If prompt type is not str, None, or callable.-- Example:- ```python- async def async_prompt(state, runtime):- return [{"role": "system", "content": "Async"}]--- def sync_prompt(state, runtime):- return [{"role": "system", "content": "Sync"}]--- messages = await aresolve_prompt(async_prompt, state, runtime, "content", "default")- messages = await aresolve_prompt(sync_prompt, state, runtime, "content", "default")- messages = await aresolve_prompt("Custom", state, runtime, "content", "default")- ```-- !!! note- Callable prompts have full control over message structure and content parameter- is ignored. Automatically detects and handles async callables.-- """- if callable(prompt):- result = prompt(state, runtime)- # Check if the result is awaitable (async function)- if inspect.isawaitable(result):- return await result- return result- if isinstance(prompt, str):- system_msg = prompt- elif prompt is None:- system_msg = default_system_content- else:- msg = f"Invalid prompt type: {type(prompt)}. Expected str, None, or callable."- raise TypeError(msg)-- return [- {"role": "system", "content": system_msg},- {"role": "user", "content": default_user_content},- ]diff --git a/libs/langchain_v1/langchain/_internal/_typing.py b/libs/langchain_v1/langchain/_internal/_typing.pydeleted file mode 100644index 0fa401e657..0000000000--- a/libs/langchain_v1/langchain/_internal/_typing.py+++ /dev/null@@ -1,70 +0,0 @@-"""Private typing utilities for langchain."""--from __future__ import annotations--from typing import TYPE_CHECKING, Any, ClassVar, Protocol, TypeAlias, TypeVar--from langgraph.graph._node import StateNode-from pydantic import BaseModel--if TYPE_CHECKING:- from dataclasses import Field---class TypedDictLikeV1(Protocol):- """Protocol to represent types that behave like ``TypedDict``s.-- Version 1: using ``ClassVar`` for keys.-- """-- __required_keys__: ClassVar[frozenset[str]]- __optional_keys__: ClassVar[frozenset[str]]---class TypedDictLikeV2(Protocol):- """Protocol to represent types that behave like ``TypedDict``s.-- Version 2: not using ``ClassVar`` for keys.-- """-- __required_keys__: frozenset[str]- __optional_keys__: frozenset[str]---class DataclassLike(Protocol):- """Protocol to represent types that behave like dataclasses.-- Inspired by the private ``_DataclassT`` from dataclasses that uses a similar- protocol as a bound.-- """-- __dataclass_fields__: ClassVar[dict[str, Field[Any]]]---StateLike: TypeAlias = TypedDictLikeV1 | TypedDictLikeV2 | DataclassLike | BaseModel-"""Type alias for state-like types.--It can either be a ``TypedDict``, ``dataclass``, or Pydantic ``BaseModel``.--!!! note- We cannot use either ``TypedDict`` or ``dataclass`` directly due to limitations in- type checking.--"""--StateT = TypeVar("StateT", bound=StateLike)-"""Type variable used to represent the state in a graph."""--ContextT = TypeVar("ContextT", bound=StateLike | None)-"""Type variable for context types."""---__all__ = [- "ContextT",- "StateLike",- "StateNode",- "StateT",-]diff --git a/libs/langchain_v1/langchain/_internal/_utils.py b/libs/langchain_v1/langchain/_internal/_utils.pydeleted file mode 100644index 9f3d930b2a..0000000000--- a/libs/langchain_v1/langchain/_internal/_utils.py+++ /dev/null@@ -1,7 +0,0 @@-# Re-exporting internal utilities from LangGraph for internal use in LangChain.-# A different wrapper needs to be created for this purpose in LangChain.-from langgraph._internal._runnable import RunnableCallable--__all__ = [- "RunnableCallable",-]diff --git a/libs/langchain_v1/langchain/agents/_internal/__init__.py b/libs/langchain_v1/langchain/agents/_internal/__init__.pydeleted file mode 100644index b4ff9ac2ba..0000000000--- a/libs/langchain_v1/langchain/agents/_internal/__init__.py+++ /dev/null@@ -1 +0,0 @@-"""Internal utilities for agents."""diff --git a/libs/langchain_v1/langchain/agents/_internal/_typing.py b/libs/langchain_v1/langchain/agents/_internal/_typing.pydeleted file mode 100644index 855c12f61d..0000000000--- a/libs/langchain_v1/langchain/agents/_internal/_typing.py+++ /dev/null@@ -1,13 +0,0 @@-"""Typing utilities for agents."""--from __future__ import annotations--from collections.abc import Awaitable, Callable-from typing import TypeVar--from typing_extensions import ParamSpec--P = ParamSpec("P")-R = TypeVar("R")--SyncOrAsync = Callable[P, R | Awaitable[R]]