Record Class MemoryProvider.LimitedWindowMemoryProvider
- All Implemented Interfaces:
MemoryProvider
- Enclosing interface:
MemoryProvider
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"));
-
Nested Class Summary
Nested classes/interfaces inherited from interface akka.javasdk.agent.MemoryProvider
MemoryProvider.CustomMemoryProvider, MemoryProvider.Disabled, MemoryProvider.FromConfig, MemoryProvider.LimitedWindowMemoryProvider -
Constructor Summary
ConstructorsConstructorDescriptionLimitedWindowMemoryProvider(Optional<Integer> readLastN, boolean read, boolean write, List<MemoryFilter> filters) Creates an instance of aLimitedWindowMemoryProviderrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.filtered(MemoryFilter.MemoryFilterSupplier filtersSupplier) Creates a new memory provider with multiple filters applied.filters()Returns the value of thefiltersrecord component.final inthashCode()Returns a hash code value for this object.booleanread()Returns the value of thereadrecord component.readLast(int onlyLastN) Creates a new memory provider with an updated history limit.readLast(int onlyLastN, MemoryFilter.MemoryFilterSupplier filtersSupplier) Creates a new memory provider with an updated history limit and multiple filters applied.Returns the value of thereadLastNrecord component.readOnly()Creates a read-only version of this memory provider.readOnly(MemoryFilter.MemoryFilterSupplier filtersSupplier) Creates a read-only version of this memory provider with multiple filters applied.final StringtoString()Returns a string representation of this record class.booleanwrite()Returns the value of thewriterecord component.Creates a write-only version of this memory provider.
-
Constructor Details
-
LimitedWindowMemoryProvider
public LimitedWindowMemoryProvider(Optional<Integer> readLastN, boolean read, boolean write, List<MemoryFilter> filters) Creates an instance of aLimitedWindowMemoryProviderrecord class.- Parameters:
readLastN- the value for thereadLastNrecord componentread- the value for thereadrecord componentwrite- the value for thewriterecord componentfilters- the value for thefiltersrecord component
-
-
Method Details
-
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
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
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
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
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 memoryfiltersSupplier- a supplier that provides the list of filters to apply- Returns:
- A new memory provider with the specified history limit and filters
-
filtered
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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
readLastN
Returns the value of thereadLastNrecord component.- Returns:
- the value of the
readLastNrecord component
-
read
public boolean read()Returns the value of thereadrecord component.- Returns:
- the value of the
readrecord component
-
write
public boolean write()Returns the value of thewriterecord component.- Returns:
- the value of the
writerecord component
-
filters
Returns the value of thefiltersrecord component.- Returns:
- the value of the
filtersrecord component
-