agent-zero/api/stop.py
Abhinav Bhateja 240a87ca79
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
2026-04-02 23:26:08 +05:30

14 lines
444 B
Python

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,
}