feat(agents): execute approved tool calls even when others are rejected#10186
Open
pawel-twardziak wants to merge 8 commits intolangchain-ai:mainfrom
Open
Conversation
🦋 Changeset detectedLatest commit: aaf0902 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
|
Christian Bromann (@christian-bromann) and Hunter Lovell (@hntrl) here is the python PR for this feature langchain-ai/langchain#32996 |
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.
humanInTheLoopMiddlewarecurrently uses an all-or-nothing approach for mixed-decision batches: if anytool call in a batch is rejected by the human operator, execution returns to the model and the
approved/edited calls are not executed in that round. This diverges from the Python SDK behavior where
rejected actions produce a
ToolMessagewithstatus: "error"while approved actions proceed to executionimmediately.
This PR adds an opt-in
executeApprovedOnRejectoption that aligns JS behavior with Python.Changes
libs/langchain/src/agents/middleware/hitl.tsexecuteApprovedOnReject: boolean(defaultfalse) toHumanInTheLoopMiddlewareConfig"tools"tocanJumpToso the middleware can jump directly to tool execution when applicableexecuteApprovedOnReject: trueand the batch contains a mix of approved/rejected decisions:ToolMessagewithstatus: "error"and the rejection message as contenttool_callsandjumpTois set to"tools"—ToolNodeautomatically skips calls that already have aToolMessage, so only the approved calls executejumpTofalls back to"model"(same as legacy behavior)executeApprovedOnReject: false(default) preserves the existing behavior exactly — no breaking changesBehavior comparison
executeApprovedOnReject: false(default)executeApprovedOnReject: trueToolMessage(status="error")Tests
Two new test cases added to
libs/langchain/src/agents/middleware/tests/hitl.test.ts:executeApprovedOnReject: true: asserts the approved tool function is called once, the rejected function is never called, and the resultingToolMessagefor the rejected call hasstatus: "error"with the rejection message as contentexecuteApprovedOnReject: true: asserts neither tool is called and the graph returns to the model (same as legacy)Related to #10176