Interface MemoryFilter

All Known Implementing Classes:
MemoryFilter.Exclude, MemoryFilter.Include

public sealed interface MemoryFilter permits MemoryFilter.Include, MemoryFilter.Exclude
Filters for controlling which messages are included when retrieving session history from memory.

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:
  • Method Details

    • includeFromAgentId

      static MemoryFilter.MemoryFilterSupplier includeFromAgentId(String id)
      Creates a filter supplier that includes only messages from the specified agent component id.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier includeFromAgentIds(Set<String> ids)
      Creates a filter supplier that includes only messages from the specified agent component ids.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier excludeFromAgentId(String id)
      Creates a filter supplier that excludes messages from the specified agent component id.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier excludeFromAgentIds(Set<String> ids)
      Creates a filter supplier that excludes messages from the specified agent component ids.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier includeFromAgentRole(String role)
      Creates a filter supplier that includes only messages from agents with the specified role.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier includeFromAgentRoles(Set<String> roles)
      Creates a filter supplier that includes only messages from agents with the specified roles.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier excludeFromAgentRole(String role)
      Creates a filter supplier that excludes messages from agents with the specified role.

      Returns a MemoryFilter.MemoryFilterSupplier that 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

      static MemoryFilter.MemoryFilterSupplier excludeFromAgentRoles(Set<String> roles)
      Creates a filter supplier that excludes messages from agents with the specified roles.

      Returns a MemoryFilter.MemoryFilterSupplier that 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