constants.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import sys
  2. from typing import Any
  3. from warnings import warn
  4. from langgraph._internal._constants import (
  5. CONF,
  6. CONFIG_KEY_CHECKPOINTER,
  7. TASKS,
  8. )
  9. from langgraph.warnings import LangGraphDeprecatedSinceV10
  10. __all__ = (
  11. "TAG_NOSTREAM",
  12. "TAG_HIDDEN",
  13. "START",
  14. "END",
  15. # retained for backwards compatibility (mostly langgraph-api), should be removed in v2 (or earlier)
  16. "CONF",
  17. "TASKS",
  18. "CONFIG_KEY_CHECKPOINTER",
  19. )
  20. # --- Public constants ---
  21. TAG_NOSTREAM = sys.intern("nostream")
  22. """Tag to disable streaming for a chat model."""
  23. TAG_HIDDEN = sys.intern("langsmith:hidden")
  24. """Tag to hide a node/edge from certain tracing/streaming environments."""
  25. END = sys.intern("__end__")
  26. """The last (maybe virtual) node in graph-style Pregel."""
  27. START = sys.intern("__start__")
  28. """The first (maybe virtual) node in graph-style Pregel."""
  29. def __getattr__(name: str) -> Any:
  30. if name in ["Send", "Interrupt"]:
  31. warn(
  32. f"Importing {name} from langgraph.constants is deprecated. "
  33. f"Please use 'from langgraph.types import {name}' instead.",
  34. LangGraphDeprecatedSinceV10,
  35. stacklevel=2,
  36. )
  37. from importlib import import_module
  38. module = import_module("langgraph.types")
  39. return getattr(module, name)
  40. try:
  41. from importlib import import_module
  42. private_constants = import_module("langgraph._internal._constants")
  43. attr = getattr(private_constants, name)
  44. warn(
  45. f"Importing {name} from langgraph.constants is deprecated. "
  46. f"This constant is now private and should not be used directly. "
  47. "Please let the LangGraph team know if you need this value.",
  48. LangGraphDeprecatedSinceV10,
  49. stacklevel=2,
  50. )
  51. return attr
  52. except AttributeError:
  53. pass
  54. raise AttributeError(f"module has no attribute '{name}'")