Context memory — the sliding window

By default the runtime keeps the last N messages in context. Older messages are dropped when the window fills. This is fast and keeps token usage predictable.

Advertisement

Summary memory

For longer conversations, enable summary memory: old messages get compressed into a rolling summary that stays in context.

LlmAgent agent = new MyAgent();
agent.setMemoryStrategy(MemoryStrategy.rollingSummary()
    .keepRecent(10)
    .summarizeAfter(30));
Advertisement

Persistent memory backends

Bring your own store. Implement MemoryStore, wire it via agent.setMemoryStore(myStore).

public class RedisMemoryStore implements MemoryStore {
  @Override
  public void save(String sessionId, Session session) {
    jedis.set("sess:" + sessionId, serialize(session));
  }
  @Override
  public Optional load(String sessionId) {
    return Optional.ofNullable(jedis.get("sess:" + sessionId))
                   .map(this::deserialize);
  }
}