Record Class MemoryProvider.LimitedWindowMemoryProvider

Object
Record
akka.javasdk.agent.MemoryProvider.LimitedWindowMemoryProvider
All Implemented Interfaces:
MemoryProvider
Enclosing interface:
MemoryProvider

public static record MemoryProvider.LimitedWindowMemoryProvider(Optional<Integer> readLastN, boolean read, boolean write, List<MemoryFilter> filters) extends Record implements MemoryProvider
Memory provider that limits session history based on size or message count.

This provider allows fine-grained control over memory usage by limiting:

  • Use only last N messages from the history
  • Whether reading from memory is enabled
  • Whether writing to memory is enabled
  • Applies memory filters MemoryFilter

Filter Ordering: When multiple filters are specified, filters of the same type are automatically merged. The merged filters are then applied in the order that each filter type first appears. Each filter type operates on the result of the previous filter type.

Example usage with filters:


 // Single filter - include only messages from a specific agent
 MemoryProvider.limitedWindow()
     .readOnly(MemoryFilter.includeFromAgentId("agent-1"));

 // Multiple filters - include messages from agent-1 but exclude internal role
 // includeFromAgentId is applied first, then excludeFromAgentRole
 MemoryProvider.limitedWindow()
     .readOnly(MemoryFilter.includeFromAgentId("agent-1")
                           .excludeFromAgentRole("internal"));

 // Combined with readLast - last 10 messages from specific agents
 // The two includeFromAgentId calls are merged, then filters applied, then limit to last 10
 MemoryProvider.limitedWindow()
     .readLast(10, MemoryFilter.includeFromAgentId("agent-1")
                               .includeFromAgentId("agent-2"));

 // Using filtered() for read-write with filters
 // The two excludeFromAgentRole calls are merged into a single filter
 MemoryProvider.limitedWindow()
     .filtered(MemoryFilter.excludeFromAgentRole("internal")
                           .excludeFromAgentRole("debug"));
 
  • Constructor Details

    • LimitedWindowMemoryProvider

      public LimitedWindowMemoryProvider(Optional<Integer> readLastN, boolean read, boolean write, List<MemoryFilter> filters)
      Creates an instance of a LimitedWindowMemoryProvider record class.
      Parameters:
      readLastN - the value for the readLastN record component
      read - the value for the read record component
      write - the value for the write record component
      filters - the value for the filters record component
  • Method Details

    • readOnly

      public MemoryProvider readOnly()
      Creates a read-only version of this memory provider.

      The returned provider will allow reading from memory but disable writing.

      Returns:
      A new memory provider with writing disabled
    • readOnly

      public MemoryProvider readOnly(MemoryFilter.MemoryFilterSupplier filtersSupplier)
      Creates a read-only version of this memory provider with multiple filters applied.

      The returned provider will allow reading from memory but disable writing. The specified filters control which messages are included when reading from memory.

      Filters of the same type are automatically merged. The merged filters are then applied in the order that each filter type first appears. Each filter type operates on the result of the previous filter type.

      Example usage:

      
       // Single filter
       MemoryProvider.limitedWindow()
           .readOnly(MemoryFilter.includeFromAgentId("agent-1"));
      
       // Multiple chained filters - same types are merged
       MemoryProvider.limitedWindow()
           .readOnly(MemoryFilter.includeFromAgentId("agent-1")
                                 .excludeFromAgentRole("internal"));
       
      Parameters:
      filtersSupplier - a supplier that provides the list of filters to apply
      Returns:
      A new memory provider with writing disabled and the specified filters
    • writeOnly

      public MemoryProvider writeOnly()
      Creates a write-only version of this memory provider.

      The returned provider will allow writing to memory but disable reading.

      Returns:
      A new memory provider with reading disabled
    • readLast

      public MemoryProvider readLast(int onlyLastN)
      Creates a new memory provider with an updated history limit.

      The history limit controls the maximum number of messages to retain in memory.

      Parameters:
      onlyLastN - parameter controls the maximum number of most recent messages to read from memory.
      Returns:
      A new memory provider with the specified history limit
    • readLast

      public MemoryProvider readLast(int onlyLastN, MemoryFilter.MemoryFilterSupplier filtersSupplier)
      Creates a new memory provider with an updated history limit and multiple filters applied.

      The history limit controls the maximum number of messages to read from memory. Filters of the same type are automatically merged, then applied in the order that each filter type first appears, and finally, the limit is enforced on the filtered results.

      Example usage:

      
       // Last 10 messages from a specific agent
       MemoryProvider.limitedWindow()
           .readLast(10, MemoryFilter.includeFromAgentId("agent-1"));
      
       // Last 5 messages excluding internal agents
       // Both excludeFromAgentRole calls are merged, applied, then limit to last 5
       MemoryProvider.limitedWindow()
           .readLast(5, MemoryFilter.excludeFromAgentRole("internal")
                                    .excludeFromAgentRole("debug"));
       
      Parameters:
      onlyLastN - the maximum number of most recent messages to read from memory
      filtersSupplier - a supplier that provides the list of filters to apply
      Returns:
      A new memory provider with the specified history limit and filters
    • filtered

      public MemoryProvider filtered(MemoryFilter.MemoryFilterSupplier filtersSupplier)
      Creates a new memory provider with multiple filters applied.

      The specified filters control which messages are included when reading from memory.

      Filters of the same type are automatically merged. The merged filters are then applied in the order that each filter type first appears. Each filter type operates on the result of the previous filter type.

      Example usage:

      
       // Filter to exclude internal messages while maintaining read-write
       MemoryProvider.limitedWindow()
           .filtered(MemoryFilter.excludeFromAgentRole("internal"));
      
       // Multiple filters - same types are merged
       // Both includeFromAgentId calls are merged, then excludeFromAgentRole applied
       MemoryProvider.limitedWindow()
           .filtered(MemoryFilter.includeFromAgentId("agent-1")
                                 .includeFromAgentId("agent-2")
                                 .excludeFromAgentRole("debug"));
       
      Parameters:
      filtersSupplier - a supplier that provides the list of filters to apply
      Returns:
      A new memory provider with the specified filters
    • toString

      public final 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 '=='.
      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.
    • readLastN

      public Optional<Integer> readLastN()
      Returns the value of the readLastN record component.
      Returns:
      the value of the readLastN record component
    • read

      public boolean read()
      Returns the value of the read record component.
      Returns:
      the value of the read record component
    • write

      public boolean write()
      Returns the value of the write record component.
      Returns:
      the value of the write record component
    • filters

      public List<MemoryFilter> filters()
      Returns the value of the filters record component.
      Returns:
      the value of the filters record component