Home / Function/ hook_config() — langchain Function Reference

hook_config() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  4eca5a1b_aad4_a4cd_2874_86745b0b0e1c["hook_config()"]
  11af10c7_4150_b78c_f01b_9e5dfc840a42["types.py"]
  4eca5a1b_aad4_a4cd_2874_86745b0b0e1c -->|defined in| 11af10c7_4150_b78c_f01b_9e5dfc840a42
  5035a06c_c77b_7c86_b1e5_6e9c163797b3["before_model()"]
  4eca5a1b_aad4_a4cd_2874_86745b0b0e1c -->|calls| 5035a06c_c77b_7c86_b1e5_6e9c163797b3
  style 4eca5a1b_aad4_a4cd_2874_86745b0b0e1c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/types.py lines 856–907

def hook_config(
    *,
    can_jump_to: list[JumpTo] | None = None,
) -> Callable[[CallableT], CallableT]:
    """Decorator to configure hook behavior in middleware methods.

    Use this decorator on `before_model` or `after_model` methods in middleware classes
    to configure their behavior. Currently supports specifying which destinations they
    can jump to, which establishes conditional edges in the agent graph.

    Args:
        can_jump_to: Optional list of valid jump destinations.

            Can be:

            - `'tools'`: Jump to the tools node
            - `'model'`: Jump back to the model node
            - `'end'`: Jump to the end of the graph

    Returns:
        Decorator function that marks the method with configuration metadata.

    Examples:
        !!! example "Using decorator on a class method"

            ```python
            class MyMiddleware(AgentMiddleware):
                @hook_config(can_jump_to=["end", "model"])
                def before_model(self, state: AgentState) -> dict[str, Any] | None:
                    if some_condition(state):
                        return {"jump_to": "end"}
                    return None
            ```

        Alternative: Use the `can_jump_to` parameter in `before_model`/`after_model`
        decorators:

        ```python
        @before_model(can_jump_to=["end"])
        def conditional_middleware(state: AgentState) -> dict[str, Any] | None:
            if should_exit(state):
                return {"jump_to": "end"}
            return None
        ```
    """

    def decorator(func: CallableT) -> CallableT:
        if can_jump_to is not None:
            func.__can_jump_to__ = can_jump_to  # type: ignore[attr-defined]
        return func

    return decorator

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free