strands.interrupt
Human-in-the-loop interrupt system for agent workflows.
Interrupt
Section titled “Interrupt”@dataclassclass Interrupt()Defined in: src/strands/interrupt.py:15
Represents an interrupt that can pause agent execution for human-in-the-loop workflows.
Attributes:
id- Unique identifier.name- User defined name.reason- User provided reason for raising the interrupt.response- Human response provided when resuming the agent after an interrupt.
to_dict
Section titled “to_dict”def to_dict() -> dict[str, Any]Defined in: src/strands/interrupt.py:30
Serialize to dict for session management.
InterruptException
Section titled “InterruptException”class InterruptException(Exception)Defined in: src/strands/interrupt.py:35
Exception raised when human input is required.
__init__
Section titled “__init__”def __init__(interrupt: Interrupt) -> NoneDefined in: src/strands/interrupt.py:38
Set the interrupt.
_InterruptState
Section titled “_InterruptState”@dataclassclass _InterruptState()Defined in: src/strands/interrupt.py:44
Track the state of interrupt events raised by the user.
Note, unanswered interrupts are cleared after resuming; an answered invocation-scoped response is retained for the rest of its interrupt cycle.
Attributes:
interrupts- Interrupts raised by the user. May be non-empty even whenactivatedis False because retained responses persist until their cycle ends.context- Additional context associated with an interrupt event.activated- True if agent is in an interrupt state, False otherwise.
has_pending_tool_execution
Section titled “has_pending_tool_execution”@propertydef has_pending_tool_execution() -> boolDefined in: src/strands/interrupt.py:63
Whether a tool execution is pending resume.
activate
Section titled “activate”def activate() -> NoneDefined in: src/strands/interrupt.py:67
Activate the interrupt state.
deactivate
Section titled “deactivate”def deactivate() -> NoneDefined in: src/strands/interrupt.py:72
Deacitvate the interrupt state.
Interrupts and context are cleared.
end_tool_cycle
Section titled “end_tool_cycle”def end_tool_cycle() -> NoneDefined in: src/strands/interrupt.py:82
Clear a completed tool cycle’s state, keeping answered invocation-scoped responses.
end_interrupt_cycle
Section titled “end_interrupt_cycle”def end_interrupt_cycle() -> NoneDefined in: src/strands/interrupt.py:93
Release invocation-scoped interrupts once their interrupt cycle is over.
resume
Section titled “resume”def resume(prompt: "AgentInput") -> NoneDefined in: src/strands/interrupt.py:106
Configure the interrupt state if resuming from an interrupt event.
Arguments:
prompt- User responses if resuming from interrupt.
Raises:
TypeError- If in interrupt state but user did not provide responses.
to_dict
Section titled “to_dict”def to_dict() -> dict[str, Any]Defined in: src/strands/interrupt.py:155
Serialize to dict for session management.
Exclude deactivated invocation-scoped responses — persisting them would give a restored agent a standing approval.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, data: dict[str, Any]) -> "_InterruptState"Defined in: src/strands/interrupt.py:176
Initiailize interrupt state from serialized interrupt state.
Interrupt state can be serialized with the to_dict method.