Home / Function/ test_anthropic_prompt_caching_middleware_async() — langchain Function Reference

test_anthropic_prompt_caching_middleware_async() — langchain Function Reference

Architecture documentation for the test_anthropic_prompt_caching_middleware_async() function in test_prompt_caching.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  035a8167_1c6b_1d44_2737_0514251964a2["test_anthropic_prompt_caching_middleware_async()"]
  80b9bbd1_b825_9778_a36c_351fbf1d2478["test_prompt_caching.py"]
  035a8167_1c6b_1d44_2737_0514251964a2 -->|defined in| 80b9bbd1_b825_9778_a36c_351fbf1d2478
  style 035a8167_1c6b_1d44_2737_0514251964a2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py lines 152–187

async def test_anthropic_prompt_caching_middleware_async() -> None:
    """Test AnthropicPromptCachingMiddleware async path."""
    # Test with custom values
    middleware = AnthropicPromptCachingMiddleware(
        type="ephemeral", ttl="1h", min_messages_to_cache=5
    )

    # Create a mock ChatAnthropic instance
    mock_chat_anthropic = MagicMock(spec=ChatAnthropic)

    fake_request = ModelRequest(
        model=mock_chat_anthropic,
        messages=[HumanMessage("Hello")] * 6,
        system_prompt=None,
        tool_choice=None,
        tools=[],
        response_format=None,
        state={"messages": [HumanMessage("Hello")] * 6},
        runtime=cast(Runtime, object()),
        model_settings={},
    )

    modified_request: ModelRequest | None = None

    async def mock_handler(req: ModelRequest) -> ModelResponse:
        nonlocal modified_request
        modified_request = req
        return ModelResponse(result=[AIMessage(content="mock response")])

    result = await middleware.awrap_model_call(fake_request, mock_handler)
    assert isinstance(result, ModelResponse)
    # Check that model_settings were passed through via the request
    assert modified_request is not None
    assert modified_request.model_settings == {
        "cache_control": {"type": "ephemeral", "ttl": "1h"}
    }

Domain

Subdomains

Frequently Asked Questions

What does test_anthropic_prompt_caching_middleware_async() do?
test_anthropic_prompt_caching_middleware_async() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py.
Where is test_anthropic_prompt_caching_middleware_async() defined?
test_anthropic_prompt_caching_middleware_async() is defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py at line 152.

Analyze Your Own Codebase

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

Try Supermodel Free