sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[FEATURE] Provide officially supported method for force stopping agent execution

Open nagabharann opened this issue 10 months ago • 2 comments

Problem Statement

The current approach to force stop an agent requires setting interrupt state on context and flag to true. This is not an officially supported pattern and may break with future SDK updates. We need a stable, documented method for force stopping agent execution.

Proposed Solution

Provide a first-class API for force stopping agents, such as:

  1. agent.force_stop() method
  2. context.request_stop() method available in hooks
  3. A dedicated event type for stop requests

The mechanism should cleanly terminate the agent loop and allow for proper cleanup.

Use Case

Force stop is needed for:

  1. Timeout handling in production workloads
  2. User-initiated cancellation of long-running agents
  3. Error recovery scenarios where continuing execution is unsafe
  4. Resource management when agents exceed limits

Alternatives Solutions

Our current workaround manipulates internal state, which is fragile and undocumented.

Additional Context

No response

nagabharann avatar Jan 29 '26 20:01 nagabharann

Hi @nagabharann, thanks for reaching out!

We recently added a cancellation feature as a part of this pull request: https://github.com/strands-agents/sdk-python/pull/1772

There are some docs here as well covering this feature: https://strandsagents.com/docs/user-guide/concepts/agents/agent-loop/#cancellation

Does this cover your use case? If not, can you help me understand what features are missing? Thanks!

Unshure avatar Apr 13 '26 17:04 Unshure

This issue has been automatically closed as it was marked for auto-closure by the team and no additional responses was received within 7 days.

github-actions[bot] avatar Apr 21 '26 14:04 github-actions[bot]