Streaming & UX

Stop / Cancel

Let the user interrupt an in-flight agent run cleanly, releasing resources and surfacing partial state.

Problem

Without a real cancellation path, the user has only bad options: wait for the run to finish, abandon the page (which leaves orphaned tool calls and partial writes in flight), or kill the process and hope nothing important was mid-write. Meanwhile the agent keeps spending tokens, tool calls, and external API quota on work the user already knows is wrong. Implementing a stop button on the user-interface alone is not enough either — the cancellation has to propagate through the agent loop, through each tool call, and into the streaming connection to the model provider, or the run continues invisibly underneath a stopped-looking interface.

Solution

Surface a stop control in the UI. On click, propagate a cancellation token through the agent loop, tool calls, and provider streams. Clean up partial state. Show what was done. Optionally save partial output for later resumption.

When to use

  • Long-running agents where the user may notice a wrong direction mid-run.
  • A cancellation token can be propagated through agent loop, tools, and provider streams.
  • Partial state can be cleaned up and surfaced cleanly.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related