From a4a8934bd3563c8b0a36ba579b253f6422497ebf Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Tue, 10 Jun 2025 17:25:05 -0700 Subject: [PATCH] Avoid saving checkpoints for subgraphs when checkpoint_during=False - We can avoid saving checkpoints for successful subgraphs which do not request multi-turn memory --- libs/langgraph/langgraph/pregel/loop.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/pregel/loop.py b/libs/langgraph/langgraph/pregel/loop.py index 3031ec525..7d43ca445 100644 --- a/libs/langgraph/langgraph/pregel/loop.py +++ b/libs/langgraph/langgraph/pregel/loop.py @@ -60,6 +60,7 @@ from langgraph.constants import ( INPUT, INTERRUPT, MISSING, + NS_END, NS_SEP, NULL_TASK_ID, PUSH, @@ -868,7 +869,14 @@ class PregelLoop: traceback: TracebackType | None, ) -> bool | None: # persist current checkpoint and writes - if not self.checkpoint_during: + if not self.checkpoint_during and ( + # if it's a top graph + not self.is_nested + # or a nested graph with error or interrupt + or exc_value is not None + # or a nested graph with checkpointer=True + or all(NS_END not in part for part in self.checkpoint_ns) + ): self._put_checkpoint(self.checkpoint_metadata) self._put_pending_writes() # suppress interrupt