test_middleware_with_specific_tool() — langchain Function Reference
Architecture documentation for the test_middleware_with_specific_tool() function in test_tool_call_limit.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD fcdbb81c_310a_98d6_dcd4_a2cb800454da["test_middleware_with_specific_tool()"] a75b8390_08d3_7137_c8a7_9d78fc0c4517["test_tool_call_limit.py"] fcdbb81c_310a_98d6_dcd4_a2cb800454da -->|defined in| a75b8390_08d3_7137_c8a7_9d78fc0c4517 style fcdbb81c_310a_98d6_dcd4_a2cb800454da fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py lines 196–225
def test_middleware_with_specific_tool() -> None:
"""Test middleware that limits a specific tool while ignoring others."""
middleware = ToolCallLimitMiddleware(
tool_name="search", thread_limit=2, run_limit=1, exit_behavior="end"
)
runtime = None
# Test search tool exceeding run limit
state = ToolCallLimitState(
messages=[
AIMessage("Response 2", tool_calls=[{"name": "search", "args": {}, "id": "3"}]),
],
thread_tool_call_count={"search": 1},
run_tool_call_count={"search": 1},
)
result = middleware.after_model(state, runtime) # type: ignore[arg-type]
assert result is not None
assert result["jump_to"] == "end"
assert "search" in result["messages"][0].content.lower()
# Test calculator tool - should be ignored by search-specific middleware
state = ToolCallLimitState(
messages=[
AIMessage("Response", tool_calls=[{"name": "calculator", "args": {}, "id": "1"}] * 10),
],
thread_tool_call_count={},
run_tool_call_count={},
)
result = middleware.after_model(state, runtime) # type: ignore[arg-type]
assert result is None, "Calculator calls shouldn't be counted by search-specific middleware"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_middleware_with_specific_tool() do?
test_middleware_with_specific_tool() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py.
Where is test_middleware_with_specific_tool() defined?
test_middleware_with_specific_tool() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py at line 196.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free