LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    Chat LangChain

    What can I help with?

    Enter to send·Shift+Enter new line

    Menu

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph-sdkpriority
    Module●Since v0.4

    priority

    Custom run priority for LangGraph.

    .. warning:: This API is in beta and may change in future versions.

    This module lets developers decide the priority settings of each thread with an async function that the server calls at the first run on a thread with no settings. The function is registered on an object that langgraph.json names, and runs server-side.

    Classes

    class
    DuplicateHandlerError

    Raised when attempting to register a duplicate encryption/decryption handler.

    class
    LangGraphBetaWarning

    Warning for beta features in LangGraph SDK.

    class
    Priority

    Decide the priority settings of your LangGraph application's threads.

    .. warning:: This API is in beta and may change in future versions.

    To use, create a separate Python file and add the path to the file to your LangGraph API configuration file (langgraph.json). Within that file, create an instance of the Priority class and register an assign function with @priority.assign.

    Example langgraph.json file:

    {
      "dependencies": ["."],
      "graphs": {
        "agent": "./my_agent/agent.py:graph"
      },
      "env": ".env",
      "priority": {
        "path": "./priority.py:priority"
      }
    }

    The server calls the assign function at the first run on a thread with no settings, which can come long after the thread was created, and stores the settings it returns on the thread. Later runs on the thread use the stored settings. The function can be called more than once for one thread, for example after it raises, and only one result is stored, so keep it free of side effects.

    Basic Usage
    from langgraph_sdk import Priority, PriorityContext, PrioritySettings
    
    priority = Priority()
    
    @priority.assign
    async def assign(ctx: PriorityContext) -> PrioritySettings | None:
        return {
            "priority": 3 if "premium" in ctx.permissions else 0,
            # Stored unencrypted, so an opaque ID rather than personal data.
            "fairness_group": ctx.user["org_id"],
        }

    Modules

    module
    types

    Priority types for LangGraph.

    This module defines the context the server passes to the function registered with @priority.assign, and the settings that function returns.

    View source on GitHub