Home / File/ types.py — langchain Source File

types.py — langchain Source File

Architecture documentation for types.py, a python file in the langchain codebase. 16 imports, 0 dependents.

File python CoreAbstractions Serialization 16 imports 10 functions 14 classes

Entity Profile

Dependency Diagram

graph LR
  fb1284e2_76fc_661f_c16d_e084e8c2b175["types.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf["dataclasses"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> d758344f_537f_649e_f467_b9d7442e86df
  8f650520_1af3_e9db_26ec_add39c408556["langgraph.channels.ephemeral_value"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 8f650520_1af3_e9db_26ec_add39c408556
  b7cbb3eb_6ad1_594c_69fe_7b83f3767136["langgraph.graph.message"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> b7cbb3eb_6ad1_594c_69fe_7b83f3767136
  150b7407_e6a8_2f45_0640_25bc6d2bfbfb["langgraph.prebuilt.tool_node"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 150b7407_e6a8_2f45_0640_25bc6d2bfbfb
  63cd4255_468c_f8b4_547c_beb43ec9a0f1["langgraph.typing"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 63cd4255_468c_f8b4_547c_beb43ec9a0f1
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 91721f45_4909_e489_8c1f_084f8bd87145
  2312f229_c199_ac88_c29f_62e2a2958404["langchain_core.language_models.chat_models"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 2312f229_c199_ac88_c29f_62e2a2958404
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 43d88577_548b_2248_b01b_7987bae85dcc
  5dbfd558_f2f2_9663_3a3f_c317926ac1c1["langgraph.runtime"]
  fb1284e2_76fc_661f_c16d_e084e8c2b175 --> 5dbfd558_f2f2_9663_3a3f_c317926ac1c1
  style fb1284e2_76fc_661f_c16d_e084e8c2b175 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""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,
    Protocol,
    cast,
    overload,
)

if TYPE_CHECKING:
    from collections.abc import Awaitable

# Needed as top level import for Pydantic schema generation on AgentState
import warnings
from typing import TypeAlias

from langchain_core.messages import (
    AIMessage,
    AnyMessage,
    BaseMessage,
    SystemMessage,
    ToolMessage,
)
from langgraph.channels.ephemeral_value import EphemeralValue
from langgraph.graph.message import add_messages
from langgraph.prebuilt.tool_node import ToolCallRequest, ToolCallWrapper
from langgraph.typing import ContextT
from typing_extensions import NotRequired, Required, TypedDict, TypeVar, Unpack

if TYPE_CHECKING:
    from langchain_core.language_models.chat_models import BaseChatModel
    from langchain_core.tools import BaseTool
    from langgraph.runtime import Runtime
    from langgraph.types import Command

    from langchain.agents.structured_output import ResponseFormat

__all__ = [
    "AgentMiddleware",
    "AgentState",
    "ContextT",
    "ExtendedModelResponse",
    "ModelCallResult",
    "ModelRequest",
    "ModelResponse",
    "OmitFromSchema",
    "ResponseT",
    "StateT_co",
    "ToolCallRequest",
    "ToolCallWrapper",
    "after_agent",
// ... (1993 more lines)

Subdomains

Dependencies

  • collections.abc
  • dataclasses
  • inspect
  • langchain.agents.structured_output
  • langchain_core.language_models.chat_models
  • langchain_core.messages
  • langchain_core.tools
  • langgraph.channels.ephemeral_value
  • langgraph.graph.message
  • langgraph.prebuilt.tool_node
  • langgraph.runtime
  • langgraph.types
  • langgraph.typing
  • typing
  • typing_extensions
  • warnings

Frequently Asked Questions

What does types.py do?
types.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in types.py?
types.py defines 10 function(s): after_agent, after_model, before_agent, before_model, collections, dynamic_prompt, hook_config, langchain_core, wrap_model_call, wrap_tool_call.
What does types.py depend on?
types.py imports 16 module(s): collections.abc, dataclasses, inspect, langchain.agents.structured_output, langchain_core.language_models.chat_models, langchain_core.messages, langchain_core.tools, langgraph.channels.ephemeral_value, and 8 more.
Where is types.py in the architecture?
types.py is located at libs/langchain_v1/langchain/agents/middleware/types.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain_v1/langchain/agents/middleware).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free