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

Feature Request: Add an Endpoint to Explicitly Stop/Terminate a Conversation

Open limboinf opened this issue 1 year ago • 10 comments

Feature Request: Add an Endpoint to Explicitly Stop/Terminate a Conversation

Background

In many real-world applications that integrate LLMs or agent frameworks, managing the lifecycle of a conversation is essential. It's not just about "starting" or "continuing"—sometimes we need to gracefully end a session. For example, a user may want to abort a long-running inference, free up backend resources, or quickly reset state in the case of an error. Currently, ADK does not appear to provide an explicit API to terminate a conversation.

Why Is This Important?

  • Resource Management: Conversations left open for extended periods can consume memory, file handles, or external service connections, leading to potential resource leaks.
  • User Experience: Users expect to be able to "end" a conversation with a single action, rather than waiting for a timeout or closing the frontend window.
  • Error Handling: In cases of infinite loops or stuck streaming responses, both developers and users need a way to interrupt processing immediately.
  • Business Logic Alignment: Many business flows naturally require an "abort" function, such as escalating to a human agent or canceling a task.

What Would Be Ideal?

I suggest exposing a RESTful endpoint in ADK, such as:

POST /conversations/{conversation_id}/stop

Calling this endpoint would immediately terminate all backend processing for the specified conversation (including streaming outputs and async tasks) and release related resources. The API should return a confirmation that the conversation has been stopped.

Design Suggestions

  • The endpoint should be idempotent: repeated calls to stop the same conversation should not cause errors.
  • If the conversation is already ended, return an appropriate message.
  • If the conversation does not exist, return a 404.
  • Optionally, support proactively notifying the frontend (e.g., via SSE) that the conversation has been terminated.

Related Discussion

I have not found existing issues or discussions on this feature in the tracker. If I've missed something, please let me know.


If this feature is on the roadmap, it would be great to hear about the expected timeline or design considerations. If community contributions are welcome, please advise on the contribution process.

limboinf avatar Jun 24 '25 09:06 limboinf

I think this feature is really necessary. Currently, I'm wondering if there's any workaround to stop a runner?

hung12ct avatar Jun 25 '25 06:06 hung12ct

Thanks for raising this. An explicit stop endpoint makes sense for both resource management and user control. It would also simplify error handling and recovery. Supporting idempotency and clear feedback for stopped or non-existent conversations is a good idea. Looking forward to seeing this feature implemented.

limboinf avatar Jun 25 '25 08:06 limboinf

The same capability is needed, and research is currently underway on how to achieve it. The product requirement I received will soon require it.

I created a discussion, but it seems like no one in the community... pays attention to this ability. https://github.com/google/adk-python/discussions/1616

growmuye avatar Jun 26 '25 05:06 growmuye

You can try setting the end_invocation flag in the _invocation_context(InvocationContext) to true in the ToolContext(in tool calls) or CallbackContext(in before or after model callback). It does stop, but i've seen a few more messages come up before actual termination

sdivakarrajesh avatar Jul 12 '25 14:07 sdivakarrajesh

Is there any update on this?

kylebarone avatar Jul 26 '25 15:07 kylebarone

That's correct, the end_invocation property can terminate execution, but it's important to note that it terminates rather than pauses. You can check out the "Advanced: Direct InvocationContext Usage" section in https://google.github.io/adk-docs/context/#advanced-direct-invocationcontext-usage. It can be used in custom Agents and lifecycle callbacks between Agents and Tools, but its behavior doesn't meet expectations. I wrapped the termination logic in a custom Agent, but it throws an exception when executed. I haven't found a good solution yet.

firefox1918 avatar Aug 06 '25 09:08 firefox1918

That's correct, the end_invocation property can terminate execution, but it's important to note that it terminates rather than pauses. You can check out the "Advanced: Direct InvocationContext Usage" section in https://google.github.io/adk-docs/context/#advanced-direct-invocationcontext-usage. It can be used in custom Agents and lifecycle callbacks between Agents and Tools, but its behavior doesn't meet expectations. I wrapped the termination logic in a custom Agent, but it throws an exception when executed. I haven't found a good solution yet.

@firefox1918 hi,我自己做了一个stop,具体见https://github.com/google/adk-python/issues/2068 第一个comment,或许对你有用

growmuye avatar Aug 08 '25 08:08 growmuye

@limboinf Thanks for your request! We are looking into it,This feature is currently under review Thank you for understanding.

klateefa avatar Dec 09 '25 07:12 klateefa

Hi @klateefa I made this pull request for the JavaScript version of ADK. What do you think about aligning it with the Python version?

https://github.com/google/adk-js/pull/193#pullrequestreview-3940160133

davidmonterocrespo24 avatar Mar 14 '26 05:03 davidmonterocrespo24

folding this into #2425. it's the same ask, and that's where the design conversation actually happened.

yours is the older of the two, so this isn't about who filed first, just about keeping it in one place.

one thing from your write-up that isn't covered over there: the idempotency behaviour. the 404 is already in #2425's description, but idempotency isn't. add it to that thread if you can.

closing here.

GWeale avatar Sep 03 '26 22:09 GWeale