Interface SessionCompactor

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface SessionCompactor
On-demand context compaction for a session, invoked when the control plane issues compress.

Compaction is deliberately not built in: it needs an LLM and a summarization policy, both of which belong to the application rather than to an observability SDK. Supply an implementation only if you want the control plane to be able to compress this agent; without one, compress honestly reports itself as unsupported instead of silently doing nothing.

A typical implementation delegates to ConversationCompactor from agentscope-harness:


 SessionCompactor compactor = (sessionId, state) ->
         conversationCompactor
                 .compactIfNeeded(RuntimeContext.builder().sessionId(sessionId).build(),
                         state.getContext().stream()
                                 .filter(m -> m.getRole() != MsgRole.SYSTEM)
                                 .toList(),
                         compactionConfig, agentId, sessionId)
                 .doOnNext(replacement -> replacement.ifPresent(msgs -> {
                     state.contextMutable().clear();
                     state.contextMutable().addAll(msgs);
                 }))
                 .then();
 
  • Method Summary

    Modifier and Type
    Method
    Description
    reactor.core.publisher.Mono<Void>
    compact(String sessionId, io.agentscope.core.state.AgentState state)
    Compacts the session's conversation in place.
  • Method Details

    • compact

      reactor.core.publisher.Mono<Void> compact(String sessionId, io.agentscope.core.state.AgentState state)
      Compacts the session's conversation in place.
      Parameters:
      sessionId - the session to compact
      state - live agent state for that session; mutate state.contextMutable() to apply the compacted history