Stop a Running Agent / Edit a previous prompt
Is your feature request related to a problem? Please describe. I want user to be able to stop the running agent to give a new prompt & or edit a prompt as they wished.
Describe the solution you'd like
- Configure stopping a running agent.
- Provide editing feature to targeted prompts.
@adk-bot Any ETA for this?
@sertacakdogan do you have any workaround for this? until they implement
@sertacakdogan Thanks for the update. The request is currently being reviewed, and I will let you know if anything further is needed. Thank you for your understanding.
@klateefa Hi! I'm really looking forward to this functionality. If there's a branch or a PR currently in progress, I'd be happy to help testing it in my environment and provide feedback to speed up the 'needs review' stage. Let me know! :)
This one would be good to add. I can take this up if reviewed already, @klateefa @wuliang229.
How is this issue going? @klateefa @wuliang229.
Taking this.
@klateefa @wuliang229 — claiming #3849. This has been open since December (8+ months). People keep asking for an ETA, a workaround, and a branch to test. Nobody has shipped it.
This is a ChatGPT-class UX hole, not a nice-to-have:
- Stop a running agent. Once
run_async//run_sseis in a long tool call or a slow model stream, the user cannot abort it. Closing the tab does not reliably free the server. That wastes tokens, hangs tools, and makes every custom front-end feel broken. Same gap as #2425 / #2853. - Edit a previous prompt. Users mistype, change their mind, or want to fork from an earlier turn. Today the only option is a new message on top of a polluted history.
rewind_asyncalready knows how to roll a session back to a given invocation — what is missing is wiring that to “replace this user turn and regenerate,” including cancelling if that turn is still running.
I am implementing both on Runner plus REST so adk web / Agent Engine clients can call them:
Runner.cancel_async(...)— stop the live invocation (and persistinterrupted=True)Runner.edit_message_async(...)— cancel if needed, rewind to that user turn, re-run with the edited promptPOST /apps/{app}/users/{user}/sessions/{session}/cancelPOST /apps/{app}/users/{user}/sessions/{session}/edit
PR incoming.
PR is up: https://github.com/google/adk-python/pull/6841
Stop (cancel_async + POST .../cancel) and edit-prompt (edit_message_async + POST .../edit) are implemented and tested.
Execution cancellation for running agents and /run_sse streams has now landed on main (#4796):
d99b23fb:abort_signal/is_abortedprimitives onInvocationContextandContextef5bbcfe51670bd211645a043914c162e7c1cd60:abort_signal: Optional[asyncio.Event] = NoneinRunner.run_async(),Workflow,NodeRunner, andAgentToolda65851a9e25005480db8164f8f0fff92ba31922: synthetic abort event and automaticFunctionResponsesealing for unclosedFunctionCalls so sessions remain valid for subsequent turns3d73603deb180a6518982b2b60f036c764f0cf7e:/run_sseautomatically triggersabort_signalwhen the SSE client disconnects (e.g. clicking Stop in a chat UI)4e48bb07292ac80a0c897bf1311454750bda8097: developer guide (docs/guides/runners/runner/abort.md)
Combined with Runner.rewind_async() to rewind session state before sending an edited prompt, this resolves the workflow described here. Closing as completed!