utils.py — langchain Source File
Architecture documentation for utils.py, a python file in the langchain codebase. 13 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ca66092c_447c_d201_0d3c_cfa6ca2cc9d3["utils.py"] d68b71f1_2253_da0f_5a2f_31c9bb5e42f0["ast"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> d68b71f1_2253_da0f_5a2f_31c9bb5e42f0 a327e534_84f6_5308_58ca_5727d5eda0cf["asyncio"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> a327e534_84f6_5308_58ca_5727d5eda0cf 614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 614e7b9f_ed51_0780_749c_ff40b74963fc d76a28c2_c3ab_00a8_5208_77807a49449d["sys"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> d76a28c2_c3ab_00a8_5208_77807a49449d 243100a0_4629_4394_a66b_1f67b00ce784["textwrap"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 243100a0_4629_4394_a66b_1f67b00ce784 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 c990f2d7_9509_7cea_ca95_51ad57dbe5c6["functools"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> c990f2d7_9509_7cea_ca95_51ad57dbe5c6 436f77bc_653d_0edb_555c_c2679d5a59ac["itertools"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 436f77bc_653d_0edb_555c_c2679d5a59ac 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 91721f45_4909_e489_8c1f_084f8bd87145 1014fe78_cb2c_fde4_a624_ae899aa7ca8e["langchain_core.utils.pydantic"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 1014fe78_cb2c_fde4_a624_ae899aa7ca8e e7c46dc4_ca3a_87ac_156f_0aa3d9b9d3f4["contextvars"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> e7c46dc4_ca3a_87ac_156f_0aa3d9b9d3f4 2079f0e4_f3be_a6ad_7bb7_1f09a33f1ec3["langchain_core.runnables.schema"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 --> 2079f0e4_f3be_a6ad_7bb7_1f09a33f1ec3 style ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Utility code for `Runnable` objects."""
from __future__ import annotations
import ast
import asyncio
import inspect
import sys
import textwrap
# Cannot move to TYPE_CHECKING as Mapping and Sequence are needed at runtime by
# RunnableConfigurableFields.
from collections.abc import Mapping, Sequence # noqa: TC003
from functools import lru_cache
from inspect import signature
from itertools import groupby
from typing import (
TYPE_CHECKING,
Any,
NamedTuple,
Protocol,
TypeGuard,
TypeVar,
)
from typing_extensions import override
# Re-export create-model for backwards compatibility
from langchain_core.utils.pydantic import create_model # noqa: F401
if TYPE_CHECKING:
from collections.abc import (
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Coroutine,
Iterable,
)
from contextvars import Context
from langchain_core.runnables.schema import StreamEvent
Input = TypeVar("Input", contravariant=True) # noqa: PLC0105
# Output type should implement __concat__, as eg str, list, dict do
Output = TypeVar("Output", covariant=True) # noqa: PLC0105
async def gated_coro(semaphore: asyncio.Semaphore, coro: Coroutine) -> Any:
"""Run a coroutine with a semaphore.
Args:
semaphore: The semaphore to use.
coro: The coroutine to run.
Returns:
The result of the coroutine.
"""
async with semaphore:
return await coro
// ... (700 more lines)
Domain
Subdomains
Functions
- aadd()
- accepts_config()
- accepts_context()
- accepts_run_manager()
- add()
- asyncio_accepts_context()
- collections()
- coro_with_context()
- gated_coro()
- gather_with_concurrency()
- get_function_first_arg_dict_keys()
- get_function_nonlocals()
- get_lambda_source()
- get_unique_config_specs()
- indent_lines_after_first()
- is_async_callable()
- is_async_generator()
Classes
Dependencies
- ast
- asyncio
- collections.abc
- contextvars
- functools
- inspect
- itertools
- langchain_core.runnables.schema
- langchain_core.utils.pydantic
- sys
- textwrap
- typing
- typing_extensions
Source
Frequently Asked Questions
What does utils.py do?
utils.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in utils.py?
utils.py defines 17 function(s): aadd, accepts_config, accepts_context, accepts_run_manager, add, asyncio_accepts_context, collections, coro_with_context, gated_coro, gather_with_concurrency, and 7 more.
What does utils.py depend on?
utils.py imports 13 module(s): ast, asyncio, collections.abc, contextvars, functools, inspect, itertools, langchain_core.runnables.schema, and 5 more.
Where is utils.py in the architecture?
utils.py is located at libs/core/langchain_core/runnables/utils.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/langchain_core/runnables).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free