fix(langgraph): Re-throw NodeInterrupt errors from ToolNode for HITL. #718
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.
This changes
ToolNode
to always re-throwNodeInterrupt
errors, rather than feeding errors back into the agent.As documented here, the intent of
NodeInterrupt
is to act as a breakpoint for when a human needs to be brought into the loop. This works as intended when thrown from a step function. However, when wrapped in aToolNode
, the default behavior trapsNodeInterrupt
and feeds it back to the agent. This is unexpected, since if a human is necessary the agent can't recover on its own.Furthermore, setting
handleToolErrors
tofalse
is a way to workaround this, but that then requires the developer to feed all other non-NodeInterrupt errors back manually (which is also unexpected).The best default behavior seems to be feeding all errors except NodeInterrupt back, and re-throwing NodeInterrupt so the application can handle it appropriately.
I discussed this with @jacoblee93 on an internal Slack channel.
Twitter: @jaredhanson