Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langgraph Public Constants

From Leeroopedia
Attribute Value
Source `libs/langgraph/langgraph/constants.py` (64 lines)
Domain Core, Constants
Principle Graph_Constants
Library langgraph
Import `from langgraph.constants import START, END, TAG_HIDDEN, TAG_NOSTREAM`

Overview

The `constants.py` module defines the four public constants used throughout the LangGraph framework to identify graph boundaries and control streaming/tracing behavior. These constants are interned strings (via `sys.intern`) for memory efficiency and fast identity comparison.

Description

This module serves as the canonical source for the small set of constants that every LangGraph graph relies on. The constants fall into two categories:

Graph topology constants:

  • `START` -- the virtual entry node of every compiled graph (`"__start__"`).
  • `END` -- the virtual exit node of every compiled graph (`"__end__"`).

Tag constants:

  • `TAG_NOSTREAM` -- applied to a chat model or node to suppress its output from streaming (`"nostream"`).
  • `TAG_HIDDEN` -- applied to a node or edge to hide it from LangSmith tracing and certain streaming environments (`"langsmith:hidden"`).

The module also re-exports three internal constants (`CONF`, `TASKS`, `CONFIG_KEY_CHECKPOINTER`) for backward compatibility but these are not part of the public API.

A module-level `__getattr__` hook intercepts imports of `Send` and `Interrupt` (which were moved to `langgraph.types`) and any other private constant from `langgraph._internal._constants`, issuing a `LangGraphDeprecatedSinceV10` deprecation warning in both cases.

Usage

from langgraph.constants import START, END, TAG_HIDDEN, TAG_NOSTREAM

# Use START and END when building a StateGraph
from langgraph.graph import StateGraph

builder = StateGraph(dict)
builder.add_node("my_node", my_function)
builder.add_edge(START, "my_node")
builder.add_edge("my_node", END)
graph = builder.compile()
# Use TAG_NOSTREAM to suppress streaming output from a node
from langgraph.constants import TAG_NOSTREAM

builder.add_node("silent_node", my_function, tags=[TAG_NOSTREAM])
# Use TAG_HIDDEN to hide a node from tracing
from langgraph.constants import TAG_HIDDEN

builder.add_node("hidden_node", my_function, tags=[TAG_HIDDEN])

Code Reference

Constants

Constant Value Description
`START` `"__start__"` The first (possibly virtual) node in a graph-style Pregel execution.
`END` `"__end__"` The last (possibly virtual) node in a graph-style Pregel execution.
`TAG_NOSTREAM` `"nostream"` Tag to disable streaming for a chat model or node.
`TAG_HIDDEN` `"langsmith:hidden"` Tag to hide a node/edge from tracing and certain streaming environments.

Deprecated Re-exports

Constant Deprecation Note
`CONF` Internal constant retained for backward compatibility. Do not use directly.
`TASKS` Internal constant retained for backward compatibility. Do not use directly.
`CONFIG_KEY_CHECKPOINTER` Internal constant retained for backward compatibility. Do not use directly.
`Send` Moved to `langgraph.types`. Import from there instead.
`Interrupt` Moved to `langgraph.types`. Import from there instead.

I/O Contract

Aspect Detail
Input N/A -- this module only exports constants; no callable interface.
Output String constants used as sentinel values in graph topology and tag configuration.
Side Effects Importing deprecated names triggers a `LangGraphDeprecatedSinceV10` warning via `warnings.warn`.

Usage Examples

Defining a Simple Graph

from langgraph.constants import START, END
from langgraph.graph import StateGraph
from typing import TypedDict

class State(TypedDict):
    messages: list

def chatbot(state: State) -> State:
    return {"messages": state["messages"] + ["Hello!"]}

builder = StateGraph(State)
builder.add_node("chatbot", chatbot)
builder.add_edge(START, "chatbot")
builder.add_edge("chatbot", END)
graph = builder.compile()
result = graph.invoke({"messages": ["Hi"]})

Controlling Streaming Behavior

from langgraph.constants import TAG_NOSTREAM, TAG_HIDDEN

# A node tagged with TAG_NOSTREAM will not emit streaming chunks
builder.add_node("background_work", background_fn, tags=[TAG_NOSTREAM])

# A node tagged with TAG_HIDDEN will be invisible in LangSmith traces
builder.add_node("internal_step", internal_fn, tags=[TAG_HIDDEN])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment