[PR #5467] Add runtime-configurable tool support to ToolNode #4453

Closed
opened 2026-02-20 17:50:13 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/5467

State: closed
Merged: No


Related discussion/feature request

Description

This PR adds the ability to configure ToolNode tools at runtime via the config parameter, enabling dynamic tool selection without graph recompilation. This is particularly useful for multi-tenant applications or scenarios where different users/contexts require different tool sets.

Changes

Core Implementation
Modified ToolNode to accept an optional config_tools_key parameter (default: "tools")
Made the tools parameter optional - can now be None if config_tools_key is provided
Added runtime tool merging logic that combines compile-time and runtime tools
Updated all relevant methods (_func, _afunc, _run_one, _arun_one) to work with merged tool mappings
Documentation
Updated ToolNode docstring with new parameter documentation and usage example
Added new section "Provide/Swap tool lists from graph configuration" in docs/docs/how-tos/tool-calling.md
Documented the merging behavior and validation requirements
Tests
Added comprehensive tests in test_tool_node.py:
test_tool_node_runtime_tools_from_config: Tests runtime-only tool configuration
test_tool_node_merge_init_and_runtime_tools: Tests merging of compile-time and runtime tools
test_tool_node_constructor_requires_tool_source: Tests validation requiring at least one tool source

Motivation

Currently, changing the tool list requires recompiling the entire graph, which is inefficient for applications that need to:

Provide different tools to different users/tenants
Enable/disable features via feature flags
Dynamically adjust available tools based on runtime conditions

Usage Example

# Define tools
@tool
def add(a: int, b: int) -> int:
    """Return a + b"""
    return a + b

@tool
def multiply(a: int, b: int) -> int:
    """Return a * b"""
    return a * b

Create ToolNode with runtime configuration

tool_node = ToolNode(config_tools_key="tools")

# Use with different tool sets at runtime
graph.invoke(
    {"messages": messages},
    config={"configurable": {"tools": [add, multiply]}}
)

Breaking Changes

None. The changes are fully backward compatible:

Existing ToolNode(tools=[...]) usage continues to work unchanged
The new config_tools_key parameter defaults to "tools"
Runtime tools are only used if explicitly provided in the config

Testing

All existing tests pass
New tests cover the runtime configuration scenarios
Tested both sync and async execution paths

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/5467 **State:** closed **Merged:** No --- [Related discussion/feature request](https://github.com/langchain-ai/langgraph/discussions/5468) ### Description This PR adds the ability to configure ToolNode tools at runtime via the config parameter, enabling dynamic tool selection without graph recompilation. This is particularly useful for multi-tenant applications or scenarios where different users/contexts require different tool sets. ### Changes **Core Implementation** Modified ToolNode to accept an optional config_tools_key parameter (default: "tools") Made the tools parameter optional - can now be None if config_tools_key is provided Added runtime tool merging logic that combines compile-time and runtime tools Updated all relevant methods (_func, _afunc, _run_one, _arun_one) to work with merged tool mappings **Documentation** Updated ToolNode docstring with new parameter documentation and usage example Added new section "Provide/Swap tool lists from graph configuration" in docs/docs/how-tos/tool-calling.md Documented the merging behavior and validation requirements **Tests** Added comprehensive tests in test_tool_node.py: test_tool_node_runtime_tools_from_config: Tests runtime-only tool configuration test_tool_node_merge_init_and_runtime_tools: Tests merging of compile-time and runtime tools test_tool_node_constructor_requires_tool_source: Tests validation requiring at least one tool source ### Motivation Currently, changing the tool list requires recompiling the entire graph, which is inefficient for applications that need to: Provide different tools to different users/tenants Enable/disable features via feature flags Dynamically adjust available tools based on runtime conditions ### Usage Example ``` # Define tools @tool def add(a: int, b: int) -> int: """Return a + b""" return a + b @tool def multiply(a: int, b: int) -> int: """Return a * b""" return a * b ``` # Create ToolNode with runtime configuration ``` tool_node = ToolNode(config_tools_key="tools") # Use with different tool sets at runtime graph.invoke( {"messages": messages}, config={"configurable": {"tools": [add, multiply]}} ) ``` ### Breaking Changes None. The changes are fully backward compatible: Existing ToolNode(tools=[...]) usage continues to work unchanged The new config_tools_key parameter defaults to "tools" Runtime tools are only used if explicitly provided in the config ### Testing All existing tests pass New tests cover the runtime configuration scenarios Tested both sync and async execution paths
yindo added the pull-request label 2026-02-20 17:50:13 -05:00
yindo closed this issue 2026-02-20 17:50:13 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4453