Record Class ContextCacheConfig

java.lang.Object
java.lang.Record
com.google.adk.agents.ContextCacheConfig
Record Components:
maxInvocations - Maximum number of invocations to reuse the same cache before refreshing it. Defaults to 10.
ttl - Time-to-live for cache. Defaults to 1800 seconds (30 minutes).
minTokens - Minimum estimated request tokens required to enable caching. This compares against the estimated total tokens of the request (system instruction + tools + contents). Context cache storage may have cost. Set higher to avoid caching small requests where overhead may exceed benefits. Defaults to 0.

public record ContextCacheConfig(int maxInvocations, Duration ttl, int minTokens) extends Record
Configuration for context caching across all agents in an app.

This configuration enables and controls context caching behavior for all LLM agents in an app. When this config is present on an app, context caching is enabled for all agents. When absent (null), context caching is disabled.

Context caching can significantly reduce costs and improve response times by reusing previously processed context across multiple requests.

  • Constructor Details

    • ContextCacheConfig

      public ContextCacheConfig()
    • ContextCacheConfig

      public ContextCacheConfig(int maxInvocations, Duration ttl, int minTokens)
      Creates an instance of a ContextCacheConfig record class.
      Parameters:
      maxInvocations - the value for the maxInvocations record component
      ttl - the value for the ttl record component
      minTokens - the value for the minTokens record component
  • Method Details

    • getTtlString

      public String getTtlString()
      Returns TTL as string format for cache creation.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • maxInvocations

      public int maxInvocations()
      Returns the value of the maxInvocations record component.
      Returns:
      the value of the maxInvocations record component
    • ttl

      public Duration ttl()
      Returns the value of the ttl record component.
      Returns:
      the value of the ttl record component
    • minTokens

      public int minTokens()
      Returns the value of the minTokens record component.
      Returns:
      the value of the minTokens record component