Home / Function/ before_agent() — langchain Function Reference

before_agent() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 628–641

    def before_agent(
        self, state: ShellToolState[ResponseT], runtime: Runtime[ContextT]
    ) -> dict[str, Any] | None:
        """Start the shell session and run startup commands.

        Args:
            state: The current agent state.
            runtime: The runtime context.

        Returns:
            Shell session resources to be stored in the agent state.
        """
        resources = self._get_or_create_resources(state)
        return {"shell_session_resources": resources}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free