mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-13 13:17:52 +02:00
Fix behaviour of interrupt_before
- checkpoints are now copied before being mutated - compiled graph and compiled state graph no longer need to override get_state/update_state - pregel class now natively supports interrupt before/after
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from langchain_core.pydantic_v1 import Field
|
||||
|
||||
from langgraph.checkpoint.base import Checkpoint, CheckpointAt, copy_checkpoint
|
||||
from langgraph.checkpoint.memory import MemorySaver
|
||||
|
||||
|
||||
class MemorySaverAssertImmutable(MemorySaver):
|
||||
storage_for_copies: dict[str, Checkpoint] = Field(default_factory=dict)
|
||||
|
||||
at = CheckpointAt.END_OF_STEP
|
||||
|
||||
def put(self, config: dict, checkpoint: dict) -> None:
|
||||
# assert checkpoint hasn't been modified since last written
|
||||
thread_id = config["configurable"]["thread_id"]
|
||||
if saved := super().get(config):
|
||||
assert self.storage_for_copies[thread_id] == saved
|
||||
self.storage_for_copies[thread_id] = copy_checkpoint(checkpoint)
|
||||
# call super to write checkpoint
|
||||
super().put(config, checkpoint)
|
||||
Reference in New Issue
Block a user