-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(langchain): relax tool node validation to allow unregistered tools #9236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This change allows middleware to intercept and handle tool calls for tools that aren't registered with ToolNode, enabling support for schema-less tools like Anthropic's text editor and memory tools. Key changes: - Updated ToolCallRequest.tool type to allow undefined - Deferred tool validation to allow wrapToolCall middleware to intercept - Added comprehensive tests for unregistered tool handling This is the JS equivalent of Python PR langchain-ai/langchain#33512 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
| /** | ||
| * skip as test requires primitives from `@langchain/core` that aren't released yet | ||
| * and fails in dependency range tests, remove after next release | ||
| */ | ||
| if (process.env.LC_DEPENDENCY_RANGE_TESTS) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary here? claude code thought it was but I don't have enough context to have an opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't as we have published @langchain/core by now. We can remove all these occurrences. Long term we will revisit these environment tests and disable them if a PR contains both, changes to langchain and @langchain/core.
Use the simpler array format [AIMessage(...)] for ToolNode.invoke() calls,
matching the Python test structure, instead of unnecessarily wrapping in
{ messages: [...] }.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Add test for dict format { messages: [...] } to verify both input formats
work with unregistered tool handling, matching Python's
test_interceptor_with_dict_input_format.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the if statements in these tests.
| /** | ||
| * skip as test requires primitives from `@langchain/core` that aren't released yet | ||
| * and fails in dependency range tests, remove after next release | ||
| */ | ||
| if (process.env.LC_DEPENDENCY_RANGE_TESTS) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't as we have published @langchain/core by now. We can remove all these occurrences. Long term we will revisit these environment tests and disable them if a PR contains both, changes to langchain and @langchain/core.
Relax tool node validation to allow middleware to intercept and handle unregistered tools.
This is the JS equivalent of Python PR langchain-ai/langchain#33512
Background
Some tools, like Anthropic's text editor and memory tools, use "schema-less" tool definitions that are added to model requests but not registered as actual tools with ToolNode. These tools exist only as type identifiers (e.g.,
{"type": "text_editor_20250728"}) that the Anthropic API understands natively.Previously, ToolNode would throw an error immediately if a tool wasn't registered, before middleware could intercept the call. This prevented middleware from handling these unregistered tools.
Changes
Type Updates
ToolCallRequest.tooltype fromClientTool | ServerTooltoClientTool | ServerTool | undefinedundefinedindicates an unregistered toolToolNode Changes
runTool(): Removed immediate error throw after tool lookup - undefined tools can now proceed to middlewarebaseHandler: Usestooldirectly from request instead of redundant lookup. Added validation that returns error ToolMessage (instead of throwing) if tool is undefinedThis allows
wrapToolCallmiddleware to intercept unregistered tools by checkingrequest.tool === undefinedand short-circuiting without calling the handlerRelated
This is a prerequisite for implementing Anthropic text editor and memory middleware (Python PR langchain-ai/langchain#33384).