fix: raise specific error for interrupt responses without active interrupt state#1885
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
Conversation
…rrupt 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 strands-agents#1644
3fb4ad2 to
07e1b7a
Compare
Contributor
Author
|
Friendly ping — raises a specific error when an interrupt response is received but no active interrupt state exists, replacing a confusing generic error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1644
When interrupt responses (
list[InterruptResponseContent]) are passed to an agent that is not in interrupt state (e.g. fresh instance, serverless handler without session management),_convert_prompt_to_messagesnow raises a clearValueErrorinstead of the generic:Root Cause
_convert_prompt_to_messagesvalidates the input prompt but did not recognize interrupt response payloads ([{"interruptResponse": {...}}]) as a valid input type. These dicts don't matchMessage(norole/contentkeys) orContentBlock(notext/image/etc. keys), so the method fell through tomessages is Noneand raised a genericValueError.When the interrupt state IS activated, this code path is never reached because line 926-927 returns
[]early. The bug only surfaces when the agent is not in interrupt state — typically in stateless/serverless setups where the agent is reconstructed per request.Fix
Added a detection branch in
_convert_prompt_to_messagesthat recognizesinterruptResponsepayloads and raises a specific, actionable error message guiding users to preserve the agent instance or use session management.Test
Added
test_agent__call__resume_interrupt_not_activated— verifies that passing interrupt responses to a non-interrupt agent raises the new specificValueErrorinstead of the generic one.All 114 agent tests + 16 interrupt tests pass.
Type of Change
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.