Authdog

LangChain

Last updated Oct 22, 2026
View as Markdown

LangChain keeps its own auth hook. Authdog stays the identity provider. The planned sample attaches an agent access token there and refuses the run when that token is missing or userinfo rejects it.

Sample planned at langchain/python in authdog/agents-samples. That folder is not published yet, so this page does not pin langchain. Python 3.10+.

Channel auth, machine credentials, tool checks, and instructions for this framework are the other pages under LangChain in AI.

The hook

@wrap_tool_call
def require_authdog(request, handler):
    token = request.runtime.context.get("authdog_token")
    subject = subject_if_accepted(token)
    if subject is None:
        return ToolMessage(
            content="unauthorized",
            tool_call_id=request.tool_call["id"],
            status="error",
        )
    return handler(request)

Pass the middleware to create_agent(..., middleware=[require_authdog]). The token is on runtime context, which the host set. It is not request.tool_call["args"]. Skipping handler means the tool does not run. Tests call the middleware with a stand-in request. They do not call a model. Read the token from the runtime field the pinned langchain actually exposes. The current docs name that request.runtime.context.

This is agent identity: client_credentials, then this hook. It is not Agent Sign-In. A browser sign-in does not replace the hook.

What you should see

A tool call with no token returns a tool message unauthorized and does not call the handler.

A tool call with a bearer userinfo accepts calls the handler. whoami returns that subject.

pytest in langchain/python is how the sample will prove both. It does not call a model.

Configure

Name Purpose
Runtime context authdog_token Access token the host sets. Not a tool argument.

The shared exchange is in Agent frameworks. There is no refresh token. Repeat it before expires_in.

Read To learn how to
Agent frameworks Mint the bearer this hook checks
Strands Agents The previous hook
Custom channel auth for LangChain The same check, as the auth boundary

Learn more