strands.interrupt
¶
Human-in-the-loop interrupt system for agent workflows.
AgentInput = str | list[ContentBlock] | list[InterruptResponseContent] | Messages | None
module-attribute
¶
Interrupt
dataclass
¶
Represents an interrupt that can pause agent execution for human-in-the-loop workflows.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier. |
name |
str
|
User defined name. |
reason |
Any
|
User provided reason for raising the interrupt. |
response |
Any
|
Human response provided when resuming the agent after an interrupt. |
Source code in strands/interrupt.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
to_dict()
¶
Serialize to dict for session management.
Source code in strands/interrupt.py
27 28 29 | |
InterruptException
¶
Bases: Exception
Exception raised when human input is required.
Source code in strands/interrupt.py
32 33 34 35 36 37 | |
__init__(interrupt)
¶
Set the interrupt.
Source code in strands/interrupt.py
35 36 37 | |
InterruptResponseContent
¶
Bases: TypedDict
Content block containing a user response to an interrupt.
Attributes:
| Name | Type | Description |
|---|---|---|
interruptResponse |
InterruptResponse
|
User response to an interrupt event. |
Source code in strands/types/interrupt.py
138 139 140 141 142 143 144 145 | |
_InterruptState
dataclass
¶
Track the state of interrupt events raised by the user.
Note, interrupt state is cleared after resuming.
Attributes:
| Name | Type | Description |
|---|---|---|
interrupts |
dict[str, Interrupt]
|
Interrupts raised by the user. |
context |
dict[str, Any]
|
Additional context associated with an interrupt event. |
activated |
bool
|
True if agent is in an interrupt state, False otherwise. |
Source code in strands/interrupt.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
activate()
¶
Activate the interrupt state.
Source code in strands/interrupt.py
57 58 59 60 | |
deactivate()
¶
Deacitvate the interrupt state.
Interrupts and context are cleared.
Source code in strands/interrupt.py
62 63 64 65 66 67 68 69 70 | |
from_dict(data)
classmethod
¶
Initiailize interrupt state from serialized interrupt state.
Interrupt state can be serialized with the to_dict method.
Source code in strands/interrupt.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
resume(prompt)
¶
Configure the interrupt state if resuming from an interrupt event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
AgentInput
|
User responses if resuming from interrupt. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If in interrupt state but user did not provide responses. |
Source code in strands/interrupt.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
to_dict()
¶
Serialize to dict for session management.
Source code in strands/interrupt.py
120 121 122 123 124 125 126 | |