Skip to content

feat(langchain): rejection_response override for HumanInTheLoopMiddleware#37167

Open
Mason Daugherty (mdrxy) wants to merge 1 commit into
masterfrom
mdrxy/langchain-hitl-override
Open

feat(langchain): rejection_response override for HumanInTheLoopMiddleware#37167
Mason Daugherty (mdrxy) wants to merge 1 commit into
masterfrom
mdrxy/langchain-hitl-override

Conversation

@mdrxy
Copy link
Copy Markdown
Member

Warning

This feature is alpha and subject to change or removal without notice.

Let InterruptOnConfig callers customize the message that gets sent back to the model when a human rejects a tool call. The default reply uses status="error", which some providers might treat as a transient failure and immediately retry, looping the interrupt. This lets you swap in your own copy and status without forking the middleware.

Changes

  • New rejection_response option on InterruptOnConfig. Pass either a ToolMessage to reuse across tools (the middleware stamps the id and name for you) or a function that builds the message from the original tool call. Marked alpha.
  • Default behavior is unchanged when the option is left unset.
  • A factory that returns the wrong type or a ToolMessage with a mismatched id or name raises clearly, with the tool name in the error — so a typo surfaces immediately instead of confusing the model later.
  • Catches a common mistake at setup: setting rejection_response without including "reject" in allowed_decisions now raises, instead of silently ignoring the override.
  • Exports RejectionResponse and RejectionResponseFactory type aliases for users who want to type-annotate their own factories.

@github-actions github-actions Bot added feature For PRs that implement a new feature; NOT A FEATURE REQUEST internal langchain `langchain` package issues & PRs size: L 500-999 LOC labels May 3, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 3, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks
⏩ 13 skipped benchmarks1


Comparing mdrxy/langchain-hitl-override (40ed1e8) with master (5a9b1ec)2

Open in CodSpeed

Footnotes

  1. 13 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (1c08d47) during the generation of this report, so 5a9b1ec was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature For PRs that implement a new feature; NOT A FEATURE REQUEST internal langchain `langchain` package issues & PRs size: L 500-999 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant