before_agent() — langchain Function Reference
Architecture documentation for the before_agent() function in types.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1962db8c_8abd_47e2_33b1_7245abf9c4ae["before_agent()"] 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"] 1962db8c_8abd_47e2_33b1_7245abf9c4ae -->|defined in| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e 6caeccd5_e24d_f046_a907_383ed9da89d9["before_agent()"] 6caeccd5_e24d_f046_a907_383ed9da89d9 -->|calls| 1962db8c_8abd_47e2_33b1_7245abf9c4ae 6caeccd5_e24d_f046_a907_383ed9da89d9["before_agent()"] 1962db8c_8abd_47e2_33b1_7245abf9c4ae -->|calls| 6caeccd5_e24d_f046_a907_383ed9da89d9 style 1962db8c_8abd_47e2_33b1_7245abf9c4ae fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/types.py lines 406–415
def before_agent(self, state: StateT, runtime: Runtime[ContextT]) -> dict[str, Any] | None:
"""Logic to run before the agent execution starts.
Args:
state: The current agent state.
runtime: The runtime context.
Returns:
Agent state updates to apply before agent execution.
"""
Domain
Subdomains
Calls
Called By
Source
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/types.py.
Where is before_agent() defined?
before_agent() is defined in libs/langchain_v1/langchain/agents/middleware/types.py at line 406.
What does before_agent() call?
before_agent() calls 1 function(s): before_agent.
What calls before_agent()?
before_agent() is called by 1 function(s): before_agent.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free