SessionCompactor
@FunctionalInterface public interface SessionCompactor
源码Source
io/agentscope/extensions/controlplane/adapter/SessionCompactor.java:48–59定义会话 Compactor契约的接口。位于 io.agentscope.extensions.controlplane.adapter 包。核心成员包括 compact。
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
| 方法Method | 说明Description |
|---|---|
public Mono<Void> compact(String sessionId, AgentState state) | 执行 `compact` 方法。 Compacts the session's conversation in place. |
方法详情Method Detail
compact
public Mono<Void> compact(String sessionId, AgentState state)
执行 compact 方法。
Compacts the session's conversation in place.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。the session to compact |
state | AgentState | 状态对象(类型 `AgentState`)。live agent state for that session; mutate `state.contextMutable()` to apply the compacted history |
Mono<Void>返回Mono。Returns mono.
源码Source
io/agentscope/extensions/controlplane/adapter/SessionCompactor.java:58