awrap_model_call() — langchain Function Reference
Architecture documentation for the awrap_model_call() function in model_fallback.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6630279e_384e_3d22_e9c0_6389279280ff["awrap_model_call()"] eb36575f_ada3_a10f_f140_390f57f60565["ModelFallbackMiddleware"] 6630279e_384e_3d22_e9c0_6389279280ff -->|defined in| eb36575f_ada3_a10f_f140_390f57f60565 style 6630279e_384e_3d22_e9c0_6389279280ff fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/model_fallback.py lines 106–138
async def awrap_model_call(
self,
request: ModelRequest[ContextT],
handler: Callable[[ModelRequest[ContextT]], Awaitable[ModelResponse[ResponseT]]],
) -> ModelResponse[ResponseT] | AIMessage:
"""Try fallback models in sequence on errors (async version).
Args:
request: Initial model request.
handler: Async callback to execute the model.
Returns:
AIMessage from successful model call.
Raises:
Exception: If all models fail, re-raises last exception.
"""
# Try primary model first
last_exception: Exception
try:
return await handler(request)
except Exception as e:
last_exception = e
# Try fallback models
for fallback_model in self.models:
try:
return await handler(request.override(model=fallback_model))
except Exception as e:
last_exception = e
continue
raise last_exception
Domain
Subdomains
Source
Frequently Asked Questions
What does awrap_model_call() do?
awrap_model_call() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/model_fallback.py.
Where is awrap_model_call() defined?
awrap_model_call() is defined in libs/langchain_v1/langchain/agents/middleware/model_fallback.py at line 106.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free