test_max_tools_limits_selection() — langchain Function Reference
Architecture documentation for the test_max_tools_limits_selection() function in test_tool_selection.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 301e563b_befa_da9f_437f_2ad711bd4ff9["test_max_tools_limits_selection()"] f414d4bb_d578_5e97_a076_b6127f4f90dd["TestMaxToolsLimiting"] 301e563b_befa_da9f_437f_2ad711bd4ff9 -->|defined in| f414d4bb_d578_5e97_a076_b6127f4f90dd style 301e563b_befa_da9f_437f_2ad711bd4ff9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py lines 213–271
def test_max_tools_limits_selection(self) -> None:
"""Test that max_tools limits selection when model selects too many tools."""
model_requests = []
@wrap_model_call
def trace_model_requests(
request: ModelRequest, handler: Callable[[ModelRequest], ModelResponse]
) -> ModelResponse:
model_requests.append(request)
return handler(request)
# Selector model tries to select 4 tools
tool_selection_model = FakeModel(
messages=cycle(
[
AIMessage(
content="",
tool_calls=[
{
"name": "ToolSelectionResponse",
"id": "1",
"args": {
"tools": [
"get_weather",
"search_web",
"calculate",
"send_email",
]
},
}
],
),
]
)
)
model = FakeModel(messages=iter([AIMessage(content="Done")]))
# But max_tools=2, so only first 2 should be used
tool_selector = LLMToolSelectorMiddleware(max_tools=2, model=tool_selection_model)
agent = create_agent(
model=model,
tools=[get_weather, search_web, calculate, send_email],
middleware=[tool_selector, trace_model_requests],
)
agent.invoke({"messages": [HumanMessage("test")]})
# Verify only 2 tools were passed to the main model
assert len(model_requests) > 0
for request in model_requests:
assert len(request.tools) == 2
tool_names = []
for tool_ in request.tools:
assert isinstance(tool_, BaseTool)
tool_names.append(tool_.name)
# Should be first 2 from the selection
assert tool_names == ["get_weather", "search_web"]
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_max_tools_limits_selection() do?
test_max_tools_limits_selection() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py.
Where is test_max_tools_limits_selection() defined?
test_max_tools_limits_selection() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py at line 213.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free