Skip to content

feat: add Stop button to halt agent without destroying context#1420

Open
abhinav-bhateja wants to merge 2 commits intoagent0ai:mainfrom
abhinav-bhateja:feature/stop-button
Open

feat: add Stop button to halt agent without destroying context#1420
abhinav-bhateja wants to merge 2 commits intoagent0ai:mainfrom
abhinav-bhateja:feature/stop-button

Conversation

@abhinav-bhateja
Copy link
Copy Markdown

Summary

Adds a Stop button that immediately halts a running agent while preserving conversation history. This fills the gap between Pause (too weak — just spins in a sleep loop) and Terminate (too destructive — nukes the entire context).

Closes #1099, Closes #1208

What changed

Backend

  • agent.py — New stop() method on AgentContext: calls kill_process(), clears pause state, resets streaming_agent, and logs an info message. History is fully preserved.
  • api/stop.py — New API handler, auto-discovered by the framework. Accepts a context ID and calls context.stop().

Frontend

  • input-store.js — New stopAgent() method that POSTs to /stop.
  • bottom-actions-bar.html — Red-tinted Stop button between Pause and Nudge, only visible when the agent is running (x-show="$store.chats?.selectedContext?.running").
  • index.jsglobalThis.stopAgent + Escape key listener that triggers stop only when the agent is running and the user is not focused on a textarea/input.

How it works

Action Kills process Preserves history Restarts agent Destroys context
Pause
Stop (new)
Nudge
Terminate

Testing

  • Click Stop while agent is processing → agent halts, chat history preserved, UI returns to idle
  • Press Escape while agent is running (not typing) → same as clicking Stop
  • Escape while typing in chat input → does nothing (expected)
  • Stop when agent is not running → button is hidden

Closes agent0ai#1099, agent0ai#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
- TestAgentContextStop: 9 unit tests for the stop() method
  - clears paused state, streaming agent, calls kill_process
  - logs info message, preserves conversation history
  - safe when not running, differs from nudge/reset behavior
- TestStopApiHandler: 3 tests for the /stop API endpoint
  - returns success, raises without context id, actually stops agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add ability to interrupt/stop an active chat response Agent Zero needs a STOP button

1 participant