test_model_retry.py — langchain Source File
Architecture documentation for test_model_retry.py, a python file in the langchain codebase. 14 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7c130104_2efd_c177_65ba_e6008641650d["test_model_retry.py"] 0c1d9a1b_c553_0388_dbc1_58af49567aa2["time"] 7c130104_2efd_c177_65ba_e6008641650d --> 0c1d9a1b_c553_0388_dbc1_58af49567aa2 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] 7c130104_2efd_c177_65ba_e6008641650d --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 7c130104_2efd_c177_65ba_e6008641650d --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 7c130104_2efd_c177_65ba_e6008641650d --> 120e2591_3e15_b895_72b6_cb26195e40a6 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] 7c130104_2efd_c177_65ba_e6008641650d --> f3bc7443_c889_119d_0744_aacc3620d8d2 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 7c130104_2efd_c177_65ba_e6008641650d --> d758344f_537f_649e_f467_b9d7442e86df ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"] 7c130104_2efd_c177_65ba_e6008641650d --> ac2a9b92_4484_491e_1b48_ec85e71e1d58 1fe3d0c5_4963_3c08_63e9_108cefcdbab5["langgraph.checkpoint.memory"] 7c130104_2efd_c177_65ba_e6008641650d --> 1fe3d0c5_4963_3c08_63e9_108cefcdbab5 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 7c130104_2efd_c177_65ba_e6008641650d --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 6f5e6c4b_1a3f_fd09_4697_631c27ef1033["langchain.agents.factory"] 7c130104_2efd_c177_65ba_e6008641650d --> 6f5e6c4b_1a3f_fd09_4697_631c27ef1033 7d6aee3c_3a42_328c_cd7f_a72407a5159d["langchain.agents.middleware._retry"] 7c130104_2efd_c177_65ba_e6008641650d --> 7d6aee3c_3a42_328c_cd7f_a72407a5159d 0629a810_566c_5c95_3afe_62d6f81069ce["langchain.agents.middleware.model_retry"] 7c130104_2efd_c177_65ba_e6008641650d --> 0629a810_566c_5c95_3afe_62d6f81069ce 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] 7c130104_2efd_c177_65ba_e6008641650d --> 50acc543_e5f0_2162_cf07_c2bf50723e0c d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"] 7c130104_2efd_c177_65ba_e6008641650d --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5 style 7c130104_2efd_c177_65ba_e6008641650d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Tests for ModelRetryMiddleware functionality."""
import time
from collections.abc import Callable
from typing import Any
import pytest
from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from langchain_core.outputs import ChatGeneration, ChatResult
from langgraph.checkpoint.memory import InMemorySaver
from pydantic import Field
from langchain.agents.factory import create_agent
from langchain.agents.middleware._retry import calculate_delay
from langchain.agents.middleware.model_retry import ModelRetryMiddleware
from langchain.agents.middleware.types import (
ModelCallResult,
ModelRequest,
ModelResponse,
wrap_model_call,
)
from tests.unit_tests.agents.model import FakeToolCallingModel
class TemporaryFailureModel(FakeToolCallingModel):
"""Model that fails a certain number of times before succeeding."""
fail_count: int = Field(default=0)
attempt: int = Field(default=0)
def _generate(
self,
messages: list[BaseMessage],
stop: list[str] | None = None,
run_manager: CallbackManagerForLLMRun | None = None,
**kwargs: Any,
) -> ChatResult:
"""Execute the model.
Args:
messages: Input messages.
stop: Optional stop sequences.
run_manager: Optional callback manager.
**kwargs: Additional keyword arguments.
Returns:
ChatResult with success message if attempt >= fail_count.
Raises:
ValueError: If attempt < fail_count.
"""
self.attempt += 1
if self.attempt <= self.fail_count:
msg = f"Temporary failure {self.attempt}"
raise ValueError(msg)
# Return success message
ai_msg = AIMessage(content=f"Success after {self.attempt} attempts", id=str(self.index))
self.index += 1
return ChatResult(generations=[ChatGeneration(message=ai_msg)])
// ... (639 more lines)
Domain
Subdomains
Functions
- test_model_retry_async_backoff_timing()
- test_model_retry_async_failing_model()
- test_model_retry_async_succeeds_after_retries()
- test_model_retry_async_working_model()
- test_model_retry_backoff_timing()
- test_model_retry_constant_backoff()
- test_model_retry_custom_exception_filter()
- test_model_retry_custom_failure_formatter()
- test_model_retry_failing_model_raises()
- test_model_retry_failing_model_returns_message()
- test_model_retry_initialization_custom()
- test_model_retry_initialization_defaults()
- test_model_retry_invalid_backoff_factor()
- test_model_retry_invalid_initial_delay()
- test_model_retry_invalid_max_delay()
- test_model_retry_invalid_max_retries()
- test_model_retry_jitter_variation()
- test_model_retry_max_delay_cap()
- test_model_retry_multiple_middleware_composition()
- test_model_retry_specific_exceptions()
- test_model_retry_succeeds_after_retries()
- test_model_retry_working_model_no_retry_needed()
- test_model_retry_zero_retries()
Dependencies
- collections.abc
- langchain.agents.factory
- langchain.agents.middleware._retry
- langchain.agents.middleware.model_retry
- langchain.agents.middleware.types
- langchain_core.callbacks
- langchain_core.messages
- langchain_core.outputs
- langgraph.checkpoint.memory
- pydantic
- pytest
- tests.unit_tests.agents.model
- time
- typing
Source
Frequently Asked Questions
What does test_model_retry.py do?
test_model_retry.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_model_retry.py?
test_model_retry.py defines 23 function(s): test_model_retry_async_backoff_timing, test_model_retry_async_failing_model, test_model_retry_async_succeeds_after_retries, test_model_retry_async_working_model, test_model_retry_backoff_timing, test_model_retry_constant_backoff, test_model_retry_custom_exception_filter, test_model_retry_custom_failure_formatter, test_model_retry_failing_model_raises, test_model_retry_failing_model_returns_message, and 13 more.
What does test_model_retry.py depend on?
test_model_retry.py imports 14 module(s): collections.abc, langchain.agents.factory, langchain.agents.middleware._retry, langchain.agents.middleware.model_retry, langchain.agents.middleware.types, langchain_core.callbacks, langchain_core.messages, langchain_core.outputs, and 6 more.
Where is test_model_retry.py in the architecture?
test_model_retry.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free