Home / Function/ test_run_limit_resets_between_invocations() — langchain Function Reference

test_run_limit_resets_between_invocations() — langchain Function Reference

Architecture documentation for the test_run_limit_resets_between_invocations() function in test_model_call_limit.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1c77729d_fccd_3143_6068_3d23b37ec1df["test_run_limit_resets_between_invocations()"]
  43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a["test_model_call_limit.py"]
  1c77729d_fccd_3143_6068_3d23b37ec1df -->|defined in| 43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a
  style 1c77729d_fccd_3143_6068_3d23b37ec1df fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py lines 204–227

def test_run_limit_resets_between_invocations() -> None:
    """Test run limit resets between invocations.

    Test that run_model_call_count resets between invocations, but
    thread_model_call_count accumulates.
    """
    # First: No tool calls per invocation, so model does not increment call counts internally
    middleware = ModelCallLimitMiddleware(thread_limit=3, run_limit=1, exit_behavior="error")
    model = FakeToolCallingModel(
        tool_calls=[[], [], [], []]
    )  # No tool calls, so only model call per run

    agent = create_agent(model=model, middleware=[middleware], checkpointer=InMemorySaver())

    thread_config = {"configurable": {"thread_id": "test_thread"}}
    agent.invoke({"messages": [HumanMessage("Hello")]}, thread_config)
    agent.invoke({"messages": [HumanMessage("Hello again")]}, thread_config)
    agent.invoke({"messages": [HumanMessage("Hello third")]}, thread_config)

    # Fourth run: should raise, thread_model_call_count == 3 (limit)
    with pytest.raises(ModelCallLimitExceededError) as exc_info:
        agent.invoke({"messages": [HumanMessage("Hello fourth")]}, thread_config)
    error_msg = str(exc_info.value)
    assert "thread limit (3/3)" in error_msg

Domain

Subdomains

Frequently Asked Questions

What does test_run_limit_resets_between_invocations() do?
test_run_limit_resets_between_invocations() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py.
Where is test_run_limit_resets_between_invocations() defined?
test_run_limit_resets_between_invocations() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py at line 204.

Analyze Your Own Codebase

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

Try Supermodel Free