adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Stop a Running Agent / Edit a previous prompt

Open sertacakdogan opened this issue 11 months ago • 9 comments

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

  1. Configure stopping a running agent.
  2. Provide editing feature to targeted prompts.

sertacakdogan avatar Dec 06 '25 08:12 sertacakdogan

@adk-bot Any ETA for this?

ananthanarayanan431 avatar Feb 02 '26 05:02 ananthanarayanan431

@sertacakdogan do you have any workaround for this? until they implement

ananthanarayanan431 avatar Feb 02 '26 05:02 ananthanarayanan431

@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 avatar Feb 11 '26 08:02 klateefa

@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! :)

ecanlar avatar Mar 12 '26 15:03 ecanlar

This one would be good to add. I can take this up if reviewed already, @klateefa @wuliang229.

patrasap0908 avatar Apr 18 '26 08:04 patrasap0908

How is this issue going? @klateefa @wuliang229.

ecanlar avatar Jul 06 '26 13:07 ecanlar

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:

  1. Stop a running agent. Once run_async / /run_sse is 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.
  2. 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_async already 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 persist interrupted=True)
  • Runner.edit_message_async(...) — cancel if needed, rewind to that user turn, re-run with the edited prompt
  • POST /apps/{app}/users/{user}/sessions/{session}/cancel
  • POST /apps/{app}/users/{user}/sessions/{session}/edit

PR incoming.

a2105z avatar Aug 21 '26 03:08 a2105z

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.

a2105z avatar Aug 21 '26 04:08 a2105z

Execution cancellation for running agents and /run_sse streams has now landed on main (#4796):

  • d99b23fb: abort_signal / is_aborted primitives on InvocationContext and Context
  • ef5bbcfe51670bd211645a043914c162e7c1cd60: abort_signal: Optional[asyncio.Event] = None in Runner.run_async(), Workflow, NodeRunner, and AgentTool
  • da65851a9e25005480db8164f8f0fff92ba31922: synthetic abort event and automatic FunctionResponse sealing for unclosed FunctionCalls so sessions remain valid for subsequent turns
  • 3d73603deb180a6518982b2b60f036c764f0cf7e: /run_sse automatically triggers abort_signal when 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!

DeanChensj avatar Oct 01 '26 00:10 DeanChensj