MaxRetriesMiddleware Class — langchain Architecture
Architecture documentation for the MaxRetriesMiddleware class in test_wrap_model_call.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f946da87_64e8_0696_2e9f_c42c17274a5a["MaxRetriesMiddleware"] 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"] f946da87_64e8_0696_2e9f_c42c17274a5a -->|extends| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e 573473e5_eb93_a7d7_84ba_c975071c09af["test_wrap_model_call.py"] f946da87_64e8_0696_2e9f_c42c17274a5a -->|defined in| 573473e5_eb93_a7d7_84ba_c975071c09af 2607c55b_dc33_1646_9ad2_ffc253d094c3["__init__()"] f946da87_64e8_0696_2e9f_c42c17274a5a -->|method| 2607c55b_dc33_1646_9ad2_ffc253d094c3 6da6fb38_f7ae_6607_571b_1aadf1c0d558["wrap_model_call()"] f946da87_64e8_0696_2e9f_c42c17274a5a -->|method| 6da6fb38_f7ae_6607_571b_1aadf1c0d558
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py lines 168–190
class MaxRetriesMiddleware(AgentMiddleware):
def __init__(self, max_retries: int = 3):
super().__init__()
self.max_retries = max_retries
self.attempts = []
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelCallResult:
last_exception = None
for attempt in range(self.max_retries):
self.attempts.append(attempt + 1)
try:
return handler(request)
except Exception as e:
last_exception = e
continue
# Re-raise the last exception
if last_exception:
raise last_exception
pytest.fail("Should have raised an exception")
Extends
Source
Frequently Asked Questions
What is the MaxRetriesMiddleware class?
MaxRetriesMiddleware is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py.
Where is MaxRetriesMiddleware defined?
MaxRetriesMiddleware is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 168.
What does MaxRetriesMiddleware extend?
MaxRetriesMiddleware extends AgentMiddleware.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free