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-sdkpriorityPriority
    Class●Since v0.4

    Priority

    Copy
    Priority(
        self,
    )

    Constructors

    Attributes

    Methods

    View source on GitHub
    constructor
    __init__
    attribute
    types: types
    method
    assign

    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"],
        }

    Reference to priority type definitions.

    Provides access to the type definitions used by the priority system: PriorityContext and PrioritySettings.

    Register the function that assigns a thread's priority settings.

    The function receives a PriorityContext and returns PrioritySettings, or None for the defaults.