Skip to content

Commit 3fb4ad2

Browse files
giulio-leoneCopilot
andcommitted
fix: raise specific error for interrupt responses without active interrupt state
When interrupt responses (list of interruptResponse dicts) are passed to an agent that is not in interrupt state, _convert_prompt_to_messages now raises a clear ValueError explaining the cause instead of the generic 'Input prompt must be of type: str | list[Contentblock] | Messages | None' error. This helps users diagnose the issue when using stateless setups where the interrupt state is not preserved across requests (e.g. serverless), guiding them to use session management or preserve the agent instance. Closes #1644 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fca208b commit 3fb4ad2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/strands/agent/agent.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,14 @@ async def _convert_prompt_to_messages(self, prompt: AgentInput) -> Messages:
962962
# Treat as List[ContentBlock] input - convert to user message
963963
# This allows invalid structures to be passed through to the model
964964
messages = [{"role": "user", "content": cast(list[ContentBlock], prompt)}]
965+
966+
# Check if all items are interrupt responses
967+
elif all("interruptResponse" in item for item in prompt):
968+
raise ValueError(
969+
"Received interrupt responses but agent is not in interrupt state. "
970+
"Ensure the agent instance is preserved between calls, or use session "
971+
"management to persist interrupt state across requests."
972+
)
965973
else:
966974
messages = []
967975
if messages is None:

tests/strands/agent/test_agent.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,15 @@ def test_agent__call__resume_interrupt_invalid_id():
18661866
agent([{"interruptResponse": {"interruptId": "invalid", "response": None}}])
18671867

18681868

1869+
def test_agent__call__resume_interrupt_not_activated():
1870+
"""Passing interrupt responses to an agent not in interrupt state should raise a clear error."""
1871+
agent = Agent()
1872+
1873+
exp_message = r"Received interrupt responses but agent is not in interrupt state"
1874+
with pytest.raises(ValueError, match=exp_message):
1875+
agent([{"interruptResponse": {"interruptId": "test-id", "response": "yes"}}])
1876+
1877+
18691878
def test_agent_structured_output_interrupt(user):
18701879
agent = Agent()
18711880
agent._interrupt_state.activated = True

0 commit comments

Comments
 (0)