How to access langgraph_auth_user (RunnableConfig) inside a Middleware or Node?

Hi everyone,

I am deploying an app using LangGraph Platform and have successfully implemented custom authentication following the official documentation.

Current Situation:
I can successfully access the authenticated user information inside my Tools using the runtime object.
However, I am struggling to access the same RunnableConfig (specifically langgraph_auth_user) inside my Middleware (or Nodes, e.g., in a @before_model hook).

Code Example:

  1. In Tools (Works Fine)

  2. @tool
    def my_tool(runtime: ToolRuntime):
        # This works perfectly
        user = runtime.config["configurable"].get("langgraph_auth_user")
    
  3. In Middleware/Nodes (The Issue):slight_smile:

  4. @before_model
    def check_message_limit(state: AgentState, runtime: Runtime):
        # ERROR: 'Runtime' object has no attribute 'get' or 'config'
        # I cannot easily reach the 'configurable' dictionary here.
        user_config = runtime.config.get("configurable", {}).get("langgraph_auth_user")
    

Does this work?

 user_config = runtime.context.get("langgraph_auth_user")

It works fine in the Tool node, but it cannot obtain configurable information in the Middleware node.

I believe config should still be injectable:

from langchain_core.runnables import RunnableConfig

@before_model
def check_message_limit(state: AgentState, config: RunnableConfig, runtime: Runtime):
    user_config = runtime.config.get("configurable", {}).get("langgraph_auth_user")

Though another tip is that the config is available in context, so should be able to do this anywhere:

from langgraph.config import get_config

def some_func(state: AgentState):
    config = get_config()
    user_config = runtime.config.get("configurable", {}).get("langgraph_auth_user")