Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/strands/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,14 @@ async def _convert_prompt_to_messages(self, prompt: AgentInput) -> Messages:
# Treat as List[ContentBlock] input - convert to user message
# This allows invalid structures to be passed through to the model
messages = [{"role": "user", "content": cast(list[ContentBlock], prompt)}]

# Check if all items are interrupt responses
elif all("interruptResponse" in item for item in prompt):
raise ValueError(
"Received interrupt responses but agent is not in interrupt state. "
"Ensure the agent instance is preserved between calls, or use session "
"management to persist interrupt state across requests."
)
else:
messages = []
if messages is None:
Expand Down
9 changes: 9 additions & 0 deletions tests/strands/agent/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,15 @@ def test_agent__call__resume_interrupt_invalid_id():
agent([{"interruptResponse": {"interruptId": "invalid", "response": None}}])


def test_agent__call__resume_interrupt_not_activated():
"""Passing interrupt responses to an agent not in interrupt state should raise a clear error."""
agent = Agent()

exp_message = r"Received interrupt responses but agent is not in interrupt state"
with pytest.raises(ValueError, match=exp_message):
agent([{"interruptResponse": {"interruptId": "test-id", "response": "yes"}}])


def test_agent_structured_output_interrupt(user):
agent = Agent()
agent._interrupt_state.activated = True
Expand Down