Home / Function/ test_limit_reached_but_not_exceeded() — langchain Function Reference

test_limit_reached_but_not_exceeded() — langchain Function Reference

Architecture documentation for the test_limit_reached_but_not_exceeded() function in test_tool_call_limit.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  28492ef2_aaa0_6f61_19b0_8759ecec7b58["test_limit_reached_but_not_exceeded()"]
  a75b8390_08d3_7137_c8a7_9d78fc0c4517["test_tool_call_limit.py"]
  28492ef2_aaa0_6f61_19b0_8759ecec7b58 -->|defined in| a75b8390_08d3_7137_c8a7_9d78fc0c4517
  style 28492ef2_aaa0_6f61_19b0_8759ecec7b58 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 393–418

def test_limit_reached_but_not_exceeded() -> None:
    """Test that limits are only triggered when exceeded (>), not when reached (==)."""
    middleware = ToolCallLimitMiddleware(thread_limit=3, run_limit=2, exit_behavior="end")
    runtime = None

    # Test when limit is reached exactly (count = limit) - should not trigger
    state = ToolCallLimitState(
        messages=[AIMessage("Response", tool_calls=[{"name": "search", "args": {}, "id": "1"}])],
        thread_tool_call_count={"__all__": 2},  # After +1 will be exactly 3
        run_tool_call_count={"__all__": 1},
    )
    result = middleware.after_model(state, runtime)  # type: ignore[arg-type]
    assert result is not None
    assert "jump_to" not in result
    assert result["thread_tool_call_count"]["__all__"] == 3

    # Test when limit is exceeded (count > limit) - should trigger
    state = ToolCallLimitState(
        messages=[AIMessage("Response", tool_calls=[{"name": "search", "args": {}, "id": "1"}])],
        thread_tool_call_count={"__all__": 3},  # After +1 will be 4 > 3
        run_tool_call_count={"__all__": 1},
    )
    result = middleware.after_model(state, runtime)  # type: ignore[arg-type]
    assert result is not None
    assert "jump_to" in result
    assert result["jump_to"] == "end"

Domain

Subdomains

Frequently Asked Questions

What does test_limit_reached_but_not_exceeded() do?
test_limit_reached_but_not_exceeded() 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_limit_reached_but_not_exceeded() defined?
test_limit_reached_but_not_exceeded() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py at line 393.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free