Is CompiledStateGraph Thread safe and How to Use MemorySaver (checkpointer) #1454
-
I am trying to publish my graph using FastAPI, I have 2 questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
importantly, you have an anti-pattern in your code of getting the latest state from sessions/checkpointer, modifying it and passing it to i would recommend checking out these sections of documentation https://langchain-ai.github.io/langgraph/concepts/low_level/#threads and https://langchain-ai.github.io/langgraph/how-tos/persistence/ |
Beta Was this translation helpful? Give feedback.
-
Thanks vbarda, You are right. I ended up doing it as below:
|
Beta Was this translation helpful? Give feedback.
@Mohamed-AtiaB
thread_id
field, like you're already doing ingraphConfig
.importantly, you have an anti-pattern in your code of getting the latest state from sessions/checkpointer, modifying it and passing it to
graph.invoke
. you should not do that -- as long as you're using a checkpointer, graph will automatically have access to the state as of the last execution (for a given thread ID). instead, you should just simply invoke it with new inputs likegraph.invoke(inputs, config)
i wo…