Home / Function/ before_model() — langchain Function Reference

before_model() — langchain Function Reference

Architecture documentation for the before_model() function in types.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  5035a06c_c77b_7c86_b1e5_6e9c163797b3["before_model()"]
  949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"]
  5035a06c_c77b_7c86_b1e5_6e9c163797b3 -->|defined in| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e
  ed036ea2_7468_131b_6107_944e0f738c3a["before_model()"]
  ed036ea2_7468_131b_6107_944e0f738c3a -->|calls| 5035a06c_c77b_7c86_b1e5_6e9c163797b3
  4eca5a1b_aad4_a4cd_2874_86745b0b0e1c["hook_config()"]
  4eca5a1b_aad4_a4cd_2874_86745b0b0e1c -->|calls| 5035a06c_c77b_7c86_b1e5_6e9c163797b3
  ed036ea2_7468_131b_6107_944e0f738c3a["before_model()"]
  5035a06c_c77b_7c86_b1e5_6e9c163797b3 -->|calls| ed036ea2_7468_131b_6107_944e0f738c3a
  style 5035a06c_c77b_7c86_b1e5_6e9c163797b3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/types.py lines 430–439

    def before_model(self, state: StateT, runtime: Runtime[ContextT]) -> dict[str, Any] | None:
        """Logic to run before the model is called.

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

        Returns:
            Agent state updates to apply before model call.
        """

Domain

Subdomains

Frequently Asked Questions

What does before_model() do?
before_model() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/types.py.
Where is before_model() defined?
before_model() is defined in libs/langchain_v1/langchain/agents/middleware/types.py at line 430.
What does before_model() call?
before_model() calls 1 function(s): before_model.
What calls before_model()?
before_model() is called by 2 function(s): before_model, hook_config.

Analyze Your Own Codebase

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

Try Supermodel Free