Skip to content

Commit 7ab956f

Browse files
authored
backend: Convert checkpointer.alist to async generator to fix async iteration in aget_state_history
## PR Description This PR converts `checkpointer.alist` into an async generator by using async for and yield inside the function. With this change, `alist` immediately returns an async iterator, allowing `agent.aget_state_history()` to iterate over it directly without needing to await the coroutine. ## Relevant issues #377 ## Type 🐛 Bug Fix ## Changes - Modified `checkpointer.alist` to use an async generator pattern python ## Tests Tested the flow by calling `get_thread_history()` which internally calls `agent.aget_state_history()`, confirming that the async iteration now functions as expected without errors. Thank you Team!
1 parent 2cf3bf7 commit 7ab956f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backend/app/checkpoint.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ async def alist(
8787
limit: Optional[int] = None,
8888
) -> AsyncIterator[CheckpointTuple]:
8989
"""List checkpoints from the database asynchronously."""
90-
return self.async_postgres_saver.alist(
90+
async for checkpoint in self.async_postgres_saver.alist(
9191
config, filter=filter, before=before, limit=limit
92-
)
92+
):
93+
yield checkpoint
9394

9495
async def aget_tuple(self, config: RunnableConfig) -> Optional[CheckpointTuple]:
9596
"""Get a checkpoint tuple from the database asynchronously."""

0 commit comments

Comments
 (0)