Home / Function/ after_agent() — langchain Function Reference

after_agent() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b37f648b_77a3_f369_ff04_cd19c43be87b["after_agent()"]
  4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a["ShellToolMiddleware"]
  b37f648b_77a3_f369_ff04_cd19c43be87b -->|defined in| 4e57a0ff_f1a5_e2e9_6949_569d7cd6d70a
  4ff436f6_bf09_1cb4_b4a9_04f4b90002cf["aafter_agent()"]
  4ff436f6_bf09_1cb4_b4a9_04f4b90002cf -->|calls| b37f648b_77a3_f369_ff04_cd19c43be87b
  a8939a21_12d2_1636_cdd0_de50dcefea64["_run_shutdown_commands()"]
  b37f648b_77a3_f369_ff04_cd19c43be87b -->|calls| a8939a21_12d2_1636_cdd0_de50dcefea64
  style b37f648b_77a3_f369_ff04_cd19c43be87b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 658–667

    def after_agent(self, state: ShellToolState[ResponseT], runtime: Runtime[ContextT]) -> None:
        """Run shutdown commands and release resources when an agent completes."""
        resources = state.get("shell_session_resources")
        if not isinstance(resources, _SessionResources):
            # Resources were never created, nothing to clean up
            return
        try:
            self._run_shutdown_commands(resources.session)
        finally:
            resources.finalizer()

Domain

Subdomains

Called By

Frequently Asked Questions

What does after_agent() do?
after_agent() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py.
Where is after_agent() defined?
after_agent() is defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py at line 658.
What does after_agent() call?
after_agent() calls 1 function(s): _run_shutdown_commands.
What calls after_agent()?
after_agent() is called by 1 function(s): aafter_agent.

Analyze Your Own Codebase

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

Try Supermodel Free