Home / Function/ test_model_retry_constant_backoff() — langchain Function Reference

test_model_retry_constant_backoff() — langchain Function Reference

Architecture documentation for the test_model_retry_constant_backoff() function in test_model_retry.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2d2c6781_4171_d6a2_f3cc_1f2fb1451a0b["test_model_retry_constant_backoff()"]
  6a114635_155a_5b86_2f48_fb8ca99f7545["test_model_retry.py"]
  2d2c6781_4171_d6a2_f3cc_1f2fb1451a0b -->|defined in| 6a114635_155a_5b86_2f48_fb8ca99f7545
  style 2d2c6781_4171_d6a2_f3cc_1f2fb1451a0b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py lines 434–464

def test_model_retry_constant_backoff() -> None:
    """Test ModelRetryMiddleware with constant backoff (backoff_factor=0)."""
    model = TemporaryFailureModel(fail_count=2)

    retry = ModelRetryMiddleware(
        max_retries=2,
        initial_delay=0.1,
        backoff_factor=0.0,  # Constant backoff
        jitter=False,
    )

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

    start_time = time.time()
    result = agent.invoke(
        {"messages": [HumanMessage("Hello")]},
        {"configurable": {"thread_id": "test"}},
    )
    elapsed = time.time() - start_time

    ai_messages = [m for m in result["messages"] if isinstance(m, AIMessage)]
    assert len(ai_messages) >= 1

    # Expected delays: 0.1 + 0.1 = 0.2 seconds (constant)
    assert elapsed >= 0.15, f"Expected at least 0.15s, got {elapsed}s"
    assert elapsed < 0.5, f"Expected less than 0.5s (exponential would be longer), got {elapsed}s"

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free