Interface MemoryFilter
- All Known Implementing Classes:
MemoryFilter.Exclude,MemoryFilter.Include
Memory filters allow you to selectively include or exclude messages based on the agent component id or role that produced them. This is useful in multi-agent scenarios where you want to:
- Retrieve only messages from specific agents (e.g., only from a "summarizer" agent)
- Exclude messages from certain agents (e.g., exclude internal agents from user-facing history)
- Filter by agent role to group related functionality
Filters can be combined with other query parameters like lastN to retrieve the most
recent N messages that match the filter criteria.
The static factory methods return a MemoryFilter.MemoryFilterSupplier which provides a fluent
builder API for composing multiple filters. This supplier is designed to be used directly with
MemoryProvider methods.
These filters are used with MemoryProvider implementations (such as MemoryProvider.LimitedWindowMemoryProvider) or directly with SessionMemoryEntity.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordFilter that excludes messages from agents with the specified component IDs or roles.static final recordFilter that includes messages from agents with the specified component IDs or roles.static interfaceA fluent builder for composing multiple memory filters. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionCreates a filter supplier that excludes messages from the specified agent component id.excludeFromAgentIds(Set<String> ids) Creates a filter supplier that excludes messages from the specified agent component ids.excludeFromAgentRole(String role) Creates a filter supplier that excludes messages from agents with the specified role.excludeFromAgentRoles(Set<String> roles) Creates a filter supplier that excludes messages from agents with the specified roles.Creates a filter supplier that includes only messages from the specified agent component id.includeFromAgentIds(Set<String> ids) Creates a filter supplier that includes only messages from the specified agent component ids.includeFromAgentRole(String role) Creates a filter supplier that includes only messages from agents with the specified role.includeFromAgentRoles(Set<String> roles) Creates a filter supplier that includes only messages from agents with the specified roles.
-
Method Details
-
includeFromAgentId
Creates a filter supplier that includes only messages from the specified agent component id.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
id- the agent component id to include messages from- Returns:
- a filter supplier for building and composing filters
-
includeFromAgentIds
Creates a filter supplier that includes only messages from the specified agent component ids.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
ids- the set of agent component ids to include messages from- Returns:
- a filter supplier for building and composing filters
-
excludeFromAgentId
Creates a filter supplier that excludes messages from the specified agent component id.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
id- the agent component id to exclude messages from- Returns:
- a filter supplier for building and composing filters
-
excludeFromAgentIds
Creates a filter supplier that excludes messages from the specified agent component ids.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
ids- the set of agent component ids to exclude messages from- Returns:
- a filter supplier for building and composing filters
-
includeFromAgentRole
Creates a filter supplier that includes only messages from agents with the specified role.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
role- the agent role to include messages from- Returns:
- a filter supplier for building and composing filters
-
includeFromAgentRoles
Creates a filter supplier that includes only messages from agents with the specified roles.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
roles- the set of agent roles to include messages from- Returns:
- a filter supplier for building and composing filters
-
excludeFromAgentRole
Creates a filter supplier that excludes messages from agents with the specified role.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
role- the agent role to exclude messages from- Returns:
- a filter supplier for building and composing filters
-
excludeFromAgentRoles
Creates a filter supplier that excludes messages from agents with the specified roles.Returns a
MemoryFilter.MemoryFilterSupplierthat can be used to build additional filters via method chaining, or directly passed to methods accepting a filter supplier.- Parameters:
roles- the set of agent roles to exclude messages from- Returns:
- a filter supplier for building and composing filters
-