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

[FEATURE] Expand interrupt support to all hook events

Open nagabharann opened this issue 10 months ago • 3 comments

Problem Statement

Interrupts are currently only available for tools in one specific hook (AfterToolCallEvent). This limits the ability to implement checkpointing and branching capabilities at other points in the agent lifecycle. We need the ability to interrupt agent execution from any hook event to support advanced durability patterns.

Proposed Solution

Extend the interrupt mechanism to all hook events (e.g., BeforeModelInvocationEvent, AfterModelInvocationEvent, BeforeToolCallEvent, AgentInitializedEvent, etc.). This would allow hook implementations to signal an interrupt at any point in the agent execution flow.

Use Case

We are building a durability plugin that provides checkpointing and branching capabilities for Strands agents. To implement this, we need to be able to pause agent execution at various points—not just after tool calls. For example:

  1. Checkpoint before a model invocation to preserve state
  2. Interrupt before a tool call to implement approval workflows
  3. Branch execution paths based on conditions evaluated at different lifecycle stages

Alternatives Solutions

We have implemented workarounds by manipulating internal state, but this is fragile and not officially supported.

Additional Context

No response

nagabharann avatar Jan 29 '26 20:01 nagabharann

There are some cases where we have gaps, but also some places where interrupts don't make sense (specifically I'm a little concerned about AgentInitialized and MessagedAddedEvent).

These two make sense:

  1. Checkpoint before a model invocation to preserve state
  2. Interrupt before a tool call to implement approval workflows

Though my understanding is that both use case are already possible:

  • BeforeToolCallEvent is an interruptible event
  • BeforeModelCallEvent is not interruptible, but in theory once #1138 is implemented, you would be able to snapshot in BeforeModelCallEvent & resume later by not passing a prompt into the agent invocation.

Does that satisfy those use cases?

Could you expand on how you imagine this one being done?:

  • Branch execution paths based on conditions evaluated at different lifecycle stages

And then beyond that, are there additional gaps that you imagine?

zastrowm avatar Mar 17 '26 16:03 zastrowm

In the case of the BeforeModelCallEvent we'd still need a way to dynamically change the agent's prompt/model so I think interrupts are still a viable path for that so we can run experiments directly without a runtime deployment. I'll take a closer look at the snapshot one but surface level i think that solves a different issue though.

nagabharann avatar Apr 06 '26 21:04 nagabharann

Thanks for the detailed request. Closing as a duplicate of #1165, which tracks interrupts for any HookEvent, including BeforeModelCallEvent. Today BeforeToolCallEvent, BeforeToolsEvent, and BeforeNodeCallEvent are interruptible in both SDKs (Python source), and the interrupts guide shows how to raise one from a hook callback. Please add your BeforeModelCallEvent and checkpointing use cases to #1165, or open a new issue if something is still missing.

yonib05 avatar Oct 25 '26 23:10 yonib05