From 67a164ca2de8e19b1944b63310057b44a153ae02 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Wed, 4 Sep 2024 12:18:42 -0700 Subject: [PATCH] Run loop tick in bg thread - prepare_next_tasks, apply_writes do some cpu-heavy work --- libs/langgraph/langgraph/pregel/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/pregel/__init__.py b/libs/langgraph/langgraph/pregel/__init__.py index 089b729fa..2a132381b 100644 --- a/libs/langgraph/langgraph/pregel/__init__.py +++ b/libs/langgraph/langgraph/pregel/__init__.py @@ -1419,7 +1419,8 @@ class Pregel(Runnable[Union[dict[str, Any], Any], Union[dict[str, Any], Any]]): # channel updates from step N are only visible in step N+1 # channels are guaranteed to be immutable for the duration of the step, # with channel updates applied only at the transition between steps - while loop.tick( + while await asyncio.to_thread( + loop.tick, input_keys=self.input_channels, interrupt_before=interrupt_before, interrupt_after=interrupt_after,