I am looking for guidance on the right approach to stop the execution of a user prompt in a chat application, similar to how ChatGPT behaves when the user clicks the Stop button and the prompt execution is terminated.
In LangGraph, should this be implemented using interrupt / reject, or is it recommended to cancel the active run instead?
The goal is to immediately stop the ongoing execution (including model streaming and any tool calls) when the user clicks Stop in the UI.
Would appreciate any recommendations or best practices for implementing this pattern.
Since our company is not planning to use LangSmith deployments, I wanted to understand if there is an alternate recommended approach to implement a Stop execution capability for user prompts.
In our chat application design, double execution / multitasking is not applicable, because once a user submits a prompt, they are blocked from submitting another prompt until either:
they receive the full response, or
they explicitly click the Stop button to terminate the ongoing execution.
Given this constraint, what would be the best practice to terminate an in-flight LangGraph execution without relying on LangSmith run cancellation?
Any guidance or examples would be greatly appreciated.
In any case, you can have a cancel event in your server that cancels the in-flight task. And then you can have the option to either roll back to the previous run (delete the in-flight checkpoints) or interrupt while retaining whatever progress was made (would be the default in this scenario).
Thanks again for the quick responses , reason for not using LS deployment is mainly around licensing cost and already existing software for observability.
We are using python , when you say we can have a cancel event in the server , are you refering to the option of running the langraph task in asyncio.task … and then use the taks.cancel () or will you suggest using langraphs interupt behavior to stop the thread , we currently do not have a requirement to resume the stopped thread . I just want to use the correct solution , any guidance on this topic will be very helpful ,thanks