Autonomous agent runs can become unbounded — a reasoning loop that fails to converge, a tool call that takes too long, a user who closes the browser tab. Production deployments need a control surface that lets the application enforce timeout policies, resource budgets and circuit-breakers without crashing the agent or leaking back-end work.
This release adds explicit cancel() at the agent API level. Calling cancel propagates through every active step : the LLM call returns, in-flight tool calls cancel, partial results discard cleanly. The agent's session state preserves up to the cancellation point so the application can surface "what was done so far" without exposing the half-finished step.
- Timeout policy. Applications wrap the agent call in a deadline ; cancellation fires when the deadline expires.
- Resource budget. The agent's accumulated cost (tokens, tool invocations, time) is observable mid-run ; the application cancels when a per-session budget is exhausted.
- User-initiated. The end-user pressing a Stop button in the UI maps to
cancel(); the agent unwinds without orphaning back-end state. - Rate-limiting. Combined with MCP role-aware tool access, an agent can be denied a tool mid-session (the role's tool budget is exhausted) without restarting the conversation.