Home / File/ _execution.py — langchain Source File

_execution.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 11 imports 4 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  c87722a4_9899_2937_c25c_b78516c8300b["_execution.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  c87722a4_9899_2937_c25c_b78516c8300b --> cccbe73e_4644_7211_4d55_e8fb133a8014
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  c87722a4_9899_2937_c25c_b78516c8300b --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"]
  c87722a4_9899_2937_c25c_b78516c8300b --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c
  a7f495f8_a546_d52e_f99a_98da076c977e["shutil"]
  c87722a4_9899_2937_c25c_b78516c8300b --> a7f495f8_a546_d52e_f99a_98da076c977e
  f02b765e_0b79_f1fa_161f_0492d5c24a46["subprocess"]
  c87722a4_9899_2937_c25c_b78516c8300b --> f02b765e_0b79_f1fa_161f_0492d5c24a46
  d76a28c2_c3ab_00a8_5208_77807a49449d["sys"]
  c87722a4_9899_2937_c25c_b78516c8300b --> d76a28c2_c3ab_00a8_5208_77807a49449d
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  c87722a4_9899_2937_c25c_b78516c8300b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  c87722a4_9899_2937_c25c_b78516c8300b --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf["dataclasses"]
  c87722a4_9899_2937_c25c_b78516c8300b --> aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  c87722a4_9899_2937_c25c_b78516c8300b --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  ac6a4073_822c_c063_be17_7cd9fe031bc4["resource"]
  c87722a4_9899_2937_c25c_b78516c8300b --> ac6a4073_822c_c063_be17_7cd9fe031bc4
  style c87722a4_9899_2937_c25c_b78516c8300b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""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 cover - optional dependency on POSIX platforms
    import resource

    _HAS_RESOURCE = True
except ImportError:  # pragma: no cover - non-POSIX systems
    _HAS_RESOURCE = False


SHELL_TEMP_PREFIX = "langchain-shell-"


def _launch_subprocess(
    command: Sequence[str],
    *,
    env: Mapping[str, str],
    cwd: Path,
    preexec_fn: typing.Callable[[], None] | None,
    start_new_session: bool,
) -> subprocess.Popen[str]:
    return subprocess.Popen(  # noqa: S603
        list(command),
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=cwd,
        text=True,
        encoding="utf-8",
        errors="replace",
        bufsize=1,
        env=env,
        preexec_fn=preexec_fn,  # noqa: PLW1509
        start_new_session=start_new_session,
    )


if typing.TYPE_CHECKING:
    from collections.abc import Mapping, Sequence
    from pathlib import Path


@dataclass
class BaseExecutionPolicy(abc.ABC):
    """Configuration contract for persistent shell sessions.

    Concrete subclasses encapsulate how a shell process is launched and constrained.
// ... (326 more lines)

Subdomains

Dependencies

  • abc
  • collections.abc
  • dataclasses
  • json
  • os
  • pathlib
  • resource
  • shutil
  • subprocess
  • sys
  • typing

Frequently Asked Questions

What does _execution.py do?
_execution.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 _execution.py?
_execution.py defines 4 function(s): _HAS_RESOURCE, _launch_subprocess, collections, resource.
What does _execution.py depend on?
_execution.py imports 11 module(s): abc, collections.abc, dataclasses, json, os, pathlib, resource, shutil, and 3 more.
Where is _execution.py in the architecture?
_execution.py is located at libs/langchain_v1/langchain/agents/middleware/_execution.py (domain: CoreAbstractions, subdomain: RunnableInterface, 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