Home / Function/ __init__() — langchain Function Reference

__init__() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  9dc9ccc0_1a4f_2a75_3c2c_9e8e1412fabf["__init__()"]
  747a705a_7ca0_fa0a_ac57_d0237478c286["AnthropicPromptCachingMiddleware"]
  9dc9ccc0_1a4f_2a75_3c2c_9e8e1412fabf -->|defined in| 747a705a_7ca0_fa0a_ac57_d0237478c286
  style 9dc9ccc0_1a4f_2a75_3c2c_9e8e1412fabf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py lines 41–69

    def __init__(
        self,
        type: Literal["ephemeral"] = "ephemeral",  # noqa: A002
        ttl: Literal["5m", "1h"] = "5m",
        min_messages_to_cache: int = 0,
        unsupported_model_behavior: Literal["ignore", "warn", "raise"] = "warn",
    ) -> None:
        """Initialize the middleware with cache control settings.

        Args:
            type: The type of cache to use, only `'ephemeral'` is supported.
            ttl: The time to live for the cache, only `'5m'` and `'1h'` are
                supported.
            min_messages_to_cache: The minimum number of messages until the
                cache is used.
            unsupported_model_behavior: The behavior to take when an
                unsupported model is used.

                `'ignore'` will ignore the unsupported model and continue without
                caching.

                `'warn'` will warn the user and continue without caching.

                `'raise'` will raise an error and stop the agent.
        """
        self.type = type
        self.ttl = ttl
        self.min_messages_to_cache = min_messages_to_cache
        self.unsupported_model_behavior = unsupported_model_behavior

Domain

Subdomains

Frequently Asked Questions

What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py.
Where is __init__() defined?
__init__() is defined in libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free