From 07e1b7a29e7c34978d3a05349c8289b01765baa4 Mon Sep 17 00:00:00 2001 From: giulio-leone Date: Fri, 13 Mar 2026 01:45:18 +0100 Subject: [PATCH] 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 --- src/strands/agent/agent.py | 8 ++++++++ tests/strands/agent/test_agent.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/strands/agent/agent.py b/src/strands/agent/agent.py index f378a886a..ecfb2eb59 100644 --- a/src/strands/agent/agent.py +++ b/src/strands/agent/agent.py @@ -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: diff --git a/tests/strands/agent/test_agent.py b/tests/strands/agent/test_agent.py index 967a0dafb..b0633f597 100644 --- a/tests/strands/agent/test_agent.py +++ b/tests/strands/agent/test_agent.py @@ -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