From ac2736f18e4bd475c132e40ecc307c744bad912a Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 3 Mar 2025 17:31:45 -0800 Subject: [PATCH] When retrying a previously attempted run, resume from previous checkpoint - Ignore input if being passed in when a checkpoint already exists for that run_id --- libs/langgraph/langgraph/pregel/loop.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/pregel/loop.py b/libs/langgraph/langgraph/pregel/loop.py index 278994126..5d1e61aef 100644 --- a/libs/langgraph/langgraph/pregel/loop.py +++ b/libs/langgraph/langgraph/pregel/loop.py @@ -55,6 +55,7 @@ from langgraph.constants import ( ERROR, INPUT, INTERRUPT, + MISSING, NS_SEP, NULL_TASK_ID, PUSH, @@ -566,7 +567,10 @@ class PregelLoop(LoopProtocol): is_resuming = bool(self.checkpoint["channel_versions"]) and bool( configurable.get( CONFIG_KEY_RESUMING, - self.input is None or isinstance(self.input, Command), + self.input is None + or isinstance(self.input, Command) + or self.config.get("metadata", {}).get("run_id") + == self.checkpoint_metadata.get("run_id", MISSING), ) ) @@ -939,6 +943,8 @@ class SyncPregelLoop(PregelLoop, ContextManager): self.prev_checkpoint_config = saved.parent_config self.checkpoint = saved.checkpoint self.checkpoint_metadata = saved.metadata + if self.config.get("metadata").get("run_id") == saved.metadata.get("run_id"): + self.resuming = True self.checkpoint_pending_writes = ( [(str(tid), k, v) for tid, k, v in saved.pending_writes] if saved.pending_writes is not None