Home / File/ test_shell_tool_integration.py — langchain Source File

test_shell_tool_integration.py — langchain Source File

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

File python LangChainCore Runnables 9 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  16cf511f_16f7_4874_8879_68a3622bd4eb["test_shell_tool_integration.py"]
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> feec1ec4_6917_867b_d228_b134d0ff8099
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4
  d9a6942a_c37a_07f8_ed13_74d0fdc117be["langchain.agents"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> d9a6942a_c37a_07f8_ed13_74d0fdc117be
  0f767285_fa0a_afed_9c89_dfda4eacfe4d["langchain.agents.middleware.shell_tool"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> 0f767285_fa0a_afed_9c89_dfda4eacfe4d
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  f6817272_d384_42bf_8dec_c3fd509a3342["langgraph.graph.state"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> f6817272_d384_42bf_8dec_c3fd509a3342
  a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"]
  16cf511f_16f7_4874_8879_68a3622bd4eb --> a681398d_ed44_c914_1a44_5d174223b069
  style 16cf511f_16f7_4874_8879_68a3622bd4eb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Integration tests for ShellToolMiddleware with create_agent."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

import pytest
from langchain_core.messages import HumanMessage
from langchain_core.tools import tool

from langchain.agents import create_agent
from langchain.agents.middleware.shell_tool import ShellToolMiddleware

if TYPE_CHECKING:
    from pathlib import Path

    from langgraph.graph.state import CompiledStateGraph

    from langchain.agents.middleware.types import _InputAgentState


def _get_model(provider: str) -> Any:
    """Get chat model for the specified provider."""
    if provider == "anthropic":
        return pytest.importorskip("langchain_anthropic").ChatAnthropic(
            model="claude-sonnet-4-5-20250929"
        )
    if provider == "openai":
        return pytest.importorskip("langchain_openai").ChatOpenAI(model="gpt-4o-mini")
    msg = f"Unknown provider: {provider}"
    raise ValueError(msg)


@pytest.mark.parametrize("provider", ["anthropic", "openai"])
def test_shell_tool_basic_execution(tmp_path: Path, provider: str) -> None:
    """Test basic shell command execution across different models."""
    workspace = tmp_path / "workspace"
    agent: CompiledStateGraph[Any, Any, _InputAgentState, Any] = create_agent(
        model=_get_model(provider),
        middleware=[ShellToolMiddleware(workspace_root=workspace)],
    )

    result = agent.invoke(
        {"messages": [HumanMessage("Run the command 'echo hello' and tell me what it outputs")]}
    )

    tool_messages = [msg for msg in result["messages"] if msg.type == "tool"]
    assert len(tool_messages) > 0, "Shell tool should have been called"

    tool_outputs = [msg.content for msg in tool_messages]
    assert any("hello" in output.lower() for output in tool_outputs), (
        "Shell output should contain 'hello'"
    )


@pytest.mark.requires("langchain_anthropic")
def test_shell_session_persistence(tmp_path: Path) -> None:
    """Test shell session state persists across multiple tool calls."""
    workspace = tmp_path / "workspace"
    agent: CompiledStateGraph[Any, Any, _InputAgentState, Any] = create_agent(
// ... (87 more lines)

Domain

Subdomains

Dependencies

  • langchain.agents
  • langchain.agents.middleware.shell_tool
  • langchain.agents.middleware.types
  • langchain_core.messages
  • langchain_core.tools
  • langgraph.graph.state
  • pathlib
  • pytest
  • typing

Frequently Asked Questions

What does test_shell_tool_integration.py do?
test_shell_tool_integration.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_shell_tool_integration.py?
test_shell_tool_integration.py defines 6 function(s): _get_model, pathlib, test_shell_session_persistence, test_shell_tool_basic_execution, test_shell_tool_error_handling, test_shell_tool_with_custom_tools.
What does test_shell_tool_integration.py depend on?
test_shell_tool_integration.py imports 9 module(s): langchain.agents, langchain.agents.middleware.shell_tool, langchain.agents.middleware.types, langchain_core.messages, langchain_core.tools, langgraph.graph.state, pathlib, pytest, and 1 more.
Where is test_shell_tool_integration.py in the architecture?
test_shell_tool_integration.py is located at libs/langchain_v1/tests/integration_tests/agents/middleware/test_shell_tool_integration.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain_v1/tests/integration_tests/agents/middleware).

Analyze Your Own Codebase

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

Try Supermodel Free