Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 14 additions & 53 deletions src/strands/types/interrupt.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
"""Interrupt related type definitions for human-in-the-loop workflows.

Interrupt Flow:
┌─────────────────┐
│ Agent Invoke │
└────────┬────────┘
┌─────────────────┐
│ Hook Calls │
| on Event |
└────────┬────────┘
┌─────────────────┐ No ┌─────────────────┐
│ Interrupts │ ────────► │ Continue │
│ Raised? │ │ Execution │
└────────┬────────┘ └─────────────────┘
│ Yes
┌─────────────────┐
│ Stop Event Loop │◄───────────────────┐
└────────┬────────┘ |
│ |
▼ |
┌─────────────────┐ |
│ Return | |
| Interrupts │ |
└────────┬────────┘ |
│ |
▼ |
┌─────────────────┐ |
│ Agent Invoke │ |
│ with Responses │ |
└────────┬────────┘ |
│ |
▼ |
┌─────────────────┐ |
│ Hook Calls │ |
| on Event | |
| with Responses | |
└────────┬────────┘ |
│ |
▼ |
┌─────────────────┐ Yes ┌────────┴────────┐
│ New Interrupts │ ────────► │ Store State │
│ Raised? │ │ │
└────────┬────────┘ └─────────────────┘
│ No
┌─────────────────┐
│ Continue │
│ Execution │
└─────────────────┘
```mermaid
flowchart TD
A[Invoke Agent] --> B[Execute Hook/Tool]
B --> C{Interrupts Raised?}
C -->|No| D[Continue Agent Loop]
C -->|Yes| E[Stop Agent Loop]
E --> F[Return Interrupts]
F --> G[Respond to Interrupts]
G --> H[Execute Hook/Tool with Responses]
H --> I{New Interrupts?}
I -->|Yes| E
I -->|No| D
```

Example:
```
```Python
from typing import Any

from strands import Agent, tool
Expand Down Expand Up @@ -99,7 +61,6 @@ def approve(self, event: BeforeToolCallEvent) -> None:
```

Details:

- User raises interrupt on their hook event by calling `event.interrupt()`.
- User can raise one interrupt per hook callback.
- Interrupts stop the agent event loop.
Expand Down
Loading