From 240a87ca7946de5dcd973443968cc79d0a661de6 Mon Sep 17 00:00:00 2001 From: Abhinav Bhateja Date: Thu, 2 Apr 2026 23:26:08 +0530 Subject: [PATCH 1/2] feat: add Stop button to halt agent without destroying context Closes #1099, #1208 Adds a proper stop mechanism between pause (too weak) and terminate (too destructive): Backend: - AgentContext.stop() in agent.py: kills process, clears pause/streaming state, preserves history - api/stop.py: new auto-discovered API endpoint Frontend: - Stop button in bottom actions bar (red-tinted, only visible when agent is running) - stopAgent() method in input-store.js - Escape key shortcut in index.js (skips when typing in input/textarea) - globalThis.stopAgent for external access --- agent.py | 8 ++++++++ api/stop.py | 14 ++++++++++++++ .../components/chat/input/bottom-actions-bar.html | 15 +++++++++++++++ webui/components/chat/input/input-store.js | 12 ++++++++++++ webui/index.js | 14 ++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 api/stop.py diff --git a/agent.py b/agent.py index 68a5e1369..5dd377b76 100644 --- a/agent.py +++ b/agent.py @@ -240,6 +240,14 @@ class AgentContext: self.task = self.communicate(UserMessage(self.agent0.read_prompt("fw.msg_nudge.md"))) return self.task + @extension.extensible + def stop(self): + """Stop the running agent immediately, preserving conversation history.""" + self.kill_process() + self.paused = False + self.streaming_agent = None + self.log.log(type="info", content="Agent stopped by user.") + @extension.extensible def get_agent(self): return self.streaming_agent or self.agent0 diff --git a/api/stop.py b/api/stop.py new file mode 100644 index 000000000..041b2b0cd --- /dev/null +++ b/api/stop.py @@ -0,0 +1,14 @@ +from helpers.api import ApiHandler, Request, Response + + +class Stop(ApiHandler): + async def process(self, input: dict, request: Request) -> dict | Response: + ctxid = input.get("context", "") + if not ctxid: + raise Exception("No context id provided") + context = self.use_context(ctxid) + context.stop() + return { + "message": "Agent stopped.", + "context": context.id, + } diff --git a/webui/components/chat/input/bottom-actions-bar.html b/webui/components/chat/input/bottom-actions-bar.html index 2242ee6e0..5fd012dd9 100644 --- a/webui/components/chat/input/bottom-actions-bar.html +++ b/webui/components/chat/input/bottom-actions-bar.html @@ -2,6 +2,7 @@ @@ -22,6 +23,16 @@ + +