Cancel graph run

I have a graph, & after I invoke it, I want to be able to stop it midway. So how to cancel the graph run in Python sdk?

Usually Task.cancel()

E.g.
task = asyncio.create_task(graph.ainvoke(…))
Task.cancel()

here is also some solution when using FastAPI Stopping endpoint for deep agents

Thank you so much . I have been looking for this for quite a long.

1 Like