fix(serialization): stop stripping __interrupt__ from channel values (#3595) (#3605)

This commit is contained in:
Zhipeng Zheng
2026-06-17 15:29:22 +08:00
committed by GitHub
parent a72af8ea37
commit c81ab268fb
3 changed files with 94 additions and 5 deletions
@@ -35,6 +35,20 @@ def serialize_lc_object(obj: Any) -> Any:
return obj.dict()
except Exception:
pass
# Interrupt is a __slots__ class — no model_dump/dict/__dict__, so it
# would reach str() and produce a malformed payload.
try:
from langgraph.types import Interrupt
except ImportError:
pass
else:
if isinstance(obj, Interrupt):
return serialize_lc_object(
{
"value": obj.value,
"id": getattr(obj, "id", None),
}
)
# Last resort
try:
return str(obj)
@@ -45,12 +59,13 @@ def serialize_lc_object(obj: Any) -> Any:
def serialize_channel_values(channel_values: dict[str, Any]) -> dict[str, Any]:
"""Serialize channel values, stripping internal LangGraph keys.
Internal keys like ``__pregel_*`` and ``__interrupt__`` are removed
to match what the LangGraph Platform API returns.
Only ``__pregel_*`` keys are removed — ``__interrupt__`` is deliberately
preserved so the LangGraph SDK can detect interrupt events from values
chunks (see issue #3595).
"""
result: dict[str, Any] = {}
for key, value in channel_values.items():
if key.startswith("__pregel_") or key == "__interrupt__":
if key.startswith("__pregel_"):
continue
result[key] = serialize_lc_object(value)
return result