Home / Function/ _get_or_create_resources() — langchain Function Reference

_get_or_create_resources() — langchain Function Reference

Architecture documentation for the _get_or_create_resources() function in shell_tool.py from the langchain codebase.

Function python LangChainCore Runnables calls 1 called by 2

Entity Profile

Dependency Diagram

graph TD
  d039cdea_065a_8bce_2925_ec6f88d67fb1["_get_or_create_resources()"]
  4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a["ShellToolMiddleware"]
  d039cdea_065a_8bce_2925_ec6f88d67fb1 -->|defined in| 4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a
  bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9["__init__()"]
  bb8cdf05_0b11_e3e7_3c28_2a6ae5bfecb9 -->|calls| d039cdea_065a_8bce_2925_ec6f88d67fb1
  20d4e167_4099_4e6c_becf_8208277b1d06["before_agent()"]
  20d4e167_4099_4e6c_becf_8208277b1d06 -->|calls| d039cdea_065a_8bce_2925_ec6f88d67fb1
  3d2455b7_eaeb_053d_fc17_21aaa32050ca["_create_resources()"]
  d039cdea_065a_8bce_2925_ec6f88d67fb1 -->|calls| 3d2455b7_eaeb_053d_fc17_21aaa32050ca
  style d039cdea_065a_8bce_2925_ec6f88d67fb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 675–694

    def _get_or_create_resources(self, state: ShellToolState[ResponseT]) -> _SessionResources:
        """Get existing resources from state or create new ones if they don't exist.

        This method enables resumability by checking if resources already exist in the state
        (e.g., after an interrupt), and only creating new resources if they're not present.

        Args:
            state: The agent state which may contain shell session resources.

        Returns:
            Session resources, either retrieved from state or newly created.
        """
        resources = state.get("shell_session_resources")
        if isinstance(resources, _SessionResources):
            return resources

        new_resources = self._create_resources()
        # Cast needed to make state dict-like for mutation
        cast("dict[str, Any]", state)["shell_session_resources"] = new_resources
        return new_resources

Domain

Subdomains

Frequently Asked Questions

What does _get_or_create_resources() do?
_get_or_create_resources() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py.
Where is _get_or_create_resources() defined?
_get_or_create_resources() is defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py at line 675.
What does _get_or_create_resources() call?
_get_or_create_resources() calls 1 function(s): _create_resources.
What calls _get_or_create_resources()?
_get_or_create_resources() is called by 2 function(s): __init__, before_agent.

Analyze Your Own Codebase

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

Try Supermodel Free