__init__() — langchain Function Reference
Architecture documentation for the __init__() function in shell_tool.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9["__init__()"] 4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a["ShellToolMiddleware"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|defined in| 4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a cd3a99ac_4203_742a_4ebe_94e38caddc16["_normalize_shell_command()"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| cd3a99ac_4203_742a_4ebe_94e38caddc16 048bbd8b_6ac4_806a_f4c0_f28cd49dcbd0["_normalize_env()"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| 048bbd8b_6ac4_806a_f4c0_f28cd49dcbd0 9cd58e2d_78c3_3591_9799_a08e2aea6fd2["_normalize_commands()"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| 9cd58e2d_78c3_3591_9799_a08e2aea6fd2 d039cdea_065a_8bce_2925_ec6f88d67fb1["_get_or_create_resources()"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| d039cdea_065a_8bce_2925_ec6f88d67fb1 8b644660_40e4_465a_3e51_e1a3166de4f9["_run_shell_tool()"] bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| 8b644660_40e4_465a_3e51_e1a3166de4f9 style bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 508–591
def __init__(
self,
workspace_root: str | Path | None = None,
*,
startup_commands: tuple[str, ...] | list[str] | str | None = None,
shutdown_commands: tuple[str, ...] | list[str] | str | None = None,
execution_policy: BaseExecutionPolicy | None = None,
redaction_rules: tuple[RedactionRule, ...] | list[RedactionRule] | None = None,
tool_description: str | None = None,
tool_name: str = SHELL_TOOL_NAME,
shell_command: Sequence[str] | str | None = None,
env: Mapping[str, Any] | None = None,
) -> None:
"""Initialize an instance of `ShellToolMiddleware`.
Args:
workspace_root: Base directory for the shell session.
If omitted, a temporary directory is created when the agent starts and
removed when it ends.
startup_commands: Optional commands executed sequentially after the session
starts.
shutdown_commands: Optional commands executed before the session shuts down.
execution_policy: Execution policy controlling timeouts, output limits, and
resource configuration.
Defaults to `HostExecutionPolicy` for native execution.
redaction_rules: Optional redaction rules to sanitize command output before
returning it to the model.
!!! warning
Redaction rules are applied post execution and do not prevent
exfiltration of secrets or sensitive data when using
`HostExecutionPolicy`.
tool_description: Optional override for the registered shell tool
description.
tool_name: Name for the registered shell tool.
Defaults to `"shell"`.
shell_command: Optional shell executable (string) or argument sequence used
to launch the persistent session.
Defaults to an implementation-defined bash command.
env: Optional environment variables to supply to the shell session.
Values are coerced to strings before command execution. If omitted, the
session inherits the parent process environment.
"""
super().__init__()
self._workspace_root = Path(workspace_root) if workspace_root else None
self._tool_name = tool_name
self._shell_command = self._normalize_shell_command(shell_command)
self._environment = self._normalize_env(env)
if execution_policy is not None:
self._execution_policy = execution_policy
else:
self._execution_policy = HostExecutionPolicy()
rules = redaction_rules or ()
self._redaction_rules: tuple[ResolvedRedactionRule, ...] = tuple(
rule.resolve() for rule in rules
)
self._startup_commands = self._normalize_commands(startup_commands)
self._shutdown_commands = self._normalize_commands(shutdown_commands)
# Create a proper tool that executes directly (no interception needed)
description = tool_description or DEFAULT_TOOL_DESCRIPTION
@tool(self._tool_name, args_schema=_ShellToolInput, description=description)
def shell_tool(
*,
runtime: ToolRuntime[None, ShellToolState],
command: str | None = None,
restart: bool = False,
) -> ToolMessage | str:
resources = self._get_or_create_resources(runtime.state)
return self._run_shell_tool(
resources,
{"command": command, "restart": restart},
tool_call_id=runtime.tool_call_id,
)
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py.
Where is __init__() defined?
__init__() is defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py at line 508.
What does __init__() call?
__init__() calls 5 function(s): _get_or_create_resources, _normalize_commands, _normalize_env, _normalize_shell_command, _run_shell_tool.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free