Skip to content

Commit

Permalink
Merge pull request #1118 from langchain-ai/nc/24jul/fix-recursion-lim…
Browse files Browse the repository at this point in the history
…it-thread

Fix recursion limit considering steps taken in previous runs on same thread
  • Loading branch information
nfcampos authored Jul 24, 2024
2 parents 19f6f7d + 03f9b27 commit 9fdbd0d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libs/langgraph/langgraph/pregel/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class PregelLoop:
checkpoint_pending_writes: List[PendingWrite]

step: int
stop: int
status: Literal[
"pending", "done", "interrupt_before", "interrupt_after", "out_of_steps"
]
Expand Down Expand Up @@ -203,7 +204,7 @@ def tick(
return False

# check if iteration limit is reached
if self.step > self.config["recursion_limit"]:
if self.step > self.stop:
self.status = "out_of_steps"
return False

Expand Down Expand Up @@ -419,6 +420,7 @@ def __enter__(self) -> Self:
)
self.status = "pending"
self.step = self.checkpoint_metadata["step"] + 1
self.stop = self.step + self.config["recursion_limit"] + 1

return self

Expand Down Expand Up @@ -497,6 +499,7 @@ async def __aenter__(self) -> Self:
)
self.status = "pending"
self.step = self.checkpoint_metadata["step"] + 1
self.stop = self.step + self.config["recursion_limit"] + 1

return self

Expand Down

0 comments on commit 9fdbd0d

Please sign in to comment.