shell_tool.py — langchain Source File
Architecture documentation for shell_tool.py, a python file in the langchain codebase. 27 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 943b36d5_cd9f_c106_7d11_56e39e63078a["shell_tool.py"] be45a0bb_0276_f8f1_f985_55cddb92c224["contextlib"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> be45a0bb_0276_f8f1_f985_55cddb92c224 e27da29f_a1f7_49f3_84d5_6be4cb4125c8["logging"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> e27da29f_a1f7_49f3_84d5_6be4cb4125c8 0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3 e8f9a0ba_3ca1_3d44_504f_6788e6853665["queue"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> e8f9a0ba_3ca1_3d44_504f_6788e6853665 8b819397_c570_b511_64f6_8cbe99d2a807["signal"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 8b819397_c570_b511_64f6_8cbe99d2a807 1e712485_2e6d_569a_0ba8_66be0da75ea6["subprocess"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 1e712485_2e6d_569a_0ba8_66be0da75ea6 fae55357_8e00_f092_b2c8_957d1841a180["tempfile"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> fae55357_8e00_f092_b2c8_957d1841a180 115d9bf0_a63e_564c_f8d8_eb2c82bbd856["threading"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 115d9bf0_a63e_564c_f8d8_eb2c82bbd856 996b2db9_46dd_901f_f7eb_068bafab4b12["time"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 996b2db9_46dd_901f_f7eb_068bafab4b12 02f66451_d2a9_e7c3_9765_c3a7594721ad["uuid"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 02f66451_d2a9_e7c3_9765_c3a7594721ad f3dd15c9_5606_12f4_e598_8391e7994c20["weakref"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> f3dd15c9_5606_12f4_e598_8391e7994c20 cd5f8820_9b2e_4495_abb7_d76026ac826c["dataclasses"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> cd5f8820_9b2e_4495_abb7_d76026ac826c 927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> 927570d8_11a6_5c17_0f0d_80baae0c733e feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 943b36d5_cd9f_c106_7d11_56e39e63078a --> feec1ec4_6917_867b_d228_b134d0ff8099 style 943b36d5_cd9f_c106_7d11_56e39e63078a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""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 import Path
from typing import TYPE_CHECKING, Annotated, Any, Literal, cast
from langchain_core.messages import ToolMessage
from langchain_core.runnables import run_in_executor
from langchain_core.tools.base import ToolException
from langgraph.channels.untracked_value import UntrackedValue
from pydantic import BaseModel, model_validator
from pydantic.json_schema import SkipJsonSchema
from typing_extensions import NotRequired, override
from langchain.agents.middleware._execution import (
SHELL_TEMP_PREFIX,
BaseExecutionPolicy,
CodexSandboxExecutionPolicy,
DockerExecutionPolicy,
HostExecutionPolicy,
)
from langchain.agents.middleware._redaction import (
PIIDetectionError,
PIIMatch,
RedactionRule,
ResolvedRedactionRule,
)
from langchain.agents.middleware.types import (
AgentMiddleware,
AgentState,
ContextT,
PrivateStateAttr,
ResponseT,
)
from langchain.tools import ToolRuntime, tool
if TYPE_CHECKING:
from collections.abc import Mapping, Sequence
from langgraph.runtime import Runtime
LOGGER = logging.getLogger(__name__)
_DONE_MARKER_PREFIX = "__LC_SHELL_DONE__"
DEFAULT_TOOL_DESCRIPTION = (
"Execute a shell command inside a persistent session. Before running a command, "
// ... (823 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- collections.abc
- contextlib
- dataclasses
- langchain.agents.middleware._execution
- langchain.agents.middleware._redaction
- langchain.agents.middleware.types
- langchain.tools
- langchain_core.messages
- langchain_core.runnables
- langchain_core.tools.base
- langgraph.channels.untracked_value
- langgraph.runtime
- logging
- os
- pathlib
- pydantic
- pydantic.json_schema
- queue
- signal
- subprocess
- tempfile
- threading
- time
- typing
- typing_extensions
- uuid
- weakref
Source
Frequently Asked Questions
What does shell_tool.py do?
shell_tool.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in shell_tool.py?
shell_tool.py defines 2 function(s): _cleanup_resources, collections.
What does shell_tool.py depend on?
shell_tool.py imports 27 module(s): collections.abc, contextlib, dataclasses, langchain.agents.middleware._execution, langchain.agents.middleware._redaction, langchain.agents.middleware.types, langchain.tools, langchain_core.messages, and 19 more.
Where is shell_tool.py in the architecture?
shell_tool.py is located at libs/langchain_v1/langchain/agents/middleware/shell_tool.py (domain: LangChainCore, subdomain: MessageInterface, 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