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.

Principle:Langchain ai Langgraph Graph Constants

From Leeroopedia
Revision as of 17:20, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Langchain_ai_Langgraph_Graph_Constants.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Attribute Value
Type Principle
Knowledge Sources LangGraph
Domains Core, Constants, Graph_Topology
Last Updated 2026-02-11 15:00 GMT

Overview

Graph constants are the well-known sentinel string values that define the entry and exit boundaries of a LangGraph graph and control streaming and tracing visibility for individual nodes.

Description

LangGraph uses a small set of interned string constants to establish a canonical vocabulary for graph topology and node behavior configuration. These constants fall into two categories:

Graph topology constants define the virtual boundaries of every compiled graph:

  • `START` (`"__start__"`) -- the virtual entry node. Every graph begins execution by routing input through `START`. When building a `StateGraph`, the first edge typically connects `START` to the initial processing node.
  • `END` (`"__end__"`) -- the virtual exit node. Connecting a node to `END` signals that the graph execution should terminate after that node completes.

Tag constants provide declarative control over streaming and tracing behavior:

  • `TAG_NOSTREAM` (`"nostream"`) -- when applied to a node, suppresses that node's output from the streaming interface. Useful for background processing nodes whose intermediate results should not be surfaced to clients.
  • `TAG_HIDDEN` (`"langsmith:hidden"`) -- when applied to a node or edge, hides it from LangSmith tracing and certain streaming environments. This is useful for internal implementation details that should not clutter observability dashboards.

All four constants are interned via `sys.intern` for memory efficiency and fast identity comparison. The constants module also provides backward-compatible re-exports of internal constants and issues deprecation warnings when users import `Send` or `Interrupt` from the old location (these have moved to `langgraph.types`).

Usage

Use `START` and `END` whenever constructing a `StateGraph` to define where execution begins and ends. Use `TAG_NOSTREAM` and `TAG_HIDDEN` when you need fine-grained control over which nodes appear in streaming output or tracing. These constants should always be imported from `langgraph.constants` rather than hard-coded as string literals, ensuring forward compatibility if the underlying values ever change.

Theoretical Basis

The concept of sentinel entry and exit nodes is rooted in control flow graph (CFG) theory from compiler design. In a CFG, a unique entry node and exit node simplify analysis by guaranteeing that all execution paths have a common origin and destination. LangGraph applies this same principle: `START` and `END` act as the universal source and sink of the directed graph, enabling the Pregel execution engine to deterministically identify where to begin routing input and where to collect final output.

The tag-based visibility system follows the aspect-oriented programming principle of separating cross-cutting concerns (observability, streaming) from core node logic. Rather than embedding streaming or tracing decisions inside node implementations, developers annotate nodes declaratively with tags, keeping business logic clean.

Related Pages

Page Connections

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