Home / Function/ awrap_model_call() — langchain Function Reference

awrap_model_call() — langchain Function Reference

Architecture documentation for the awrap_model_call() function in prompt_caching.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  970a7429_a57e_be43_2bab_421814cfcad8["awrap_model_call()"]
  747a705a_7ca0_fa0a_ac57_d0237478c286["AnthropicPromptCachingMiddleware"]
  970a7429_a57e_be43_2bab_421814cfcad8 -->|defined in| 747a705a_7ca0_fa0a_ac57_d0237478c286
  af09cbf7_14e8_e051_a561_13704e6d0806["_should_apply_caching()"]
  970a7429_a57e_be43_2bab_421814cfcad8 -->|calls| af09cbf7_14e8_e051_a561_13704e6d0806
  style 970a7429_a57e_be43_2bab_421814cfcad8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py lines 125–147

    async def awrap_model_call(
        self,
        request: ModelRequest,
        handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
    ) -> ModelCallResult:
        """Modify the model request to add cache control blocks (async version).

        Args:
            request: The model request to potentially modify.
            handler: The async handler to execute the model request.

        Returns:
            The model response from the handler.
        """
        if not self._should_apply_caching(request):
            return await handler(request)

        model_settings = request.model_settings
        new_model_settings = {
            **model_settings,
            "cache_control": {"type": self.type, "ttl": self.ttl},
        }
        return await handler(request.override(model_settings=new_model_settings))

Domain

Subdomains

Frequently Asked Questions

What does awrap_model_call() do?
awrap_model_call() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py.
Where is awrap_model_call() defined?
awrap_model_call() is defined in libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py at line 125.
What does awrap_model_call() call?
awrap_model_call() calls 1 function(s): _should_apply_caching.

Analyze Your Own Codebase

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

Try Supermodel Free