AS AgentScopeAPI 手册 / API Reference

SessionCompactor

@FunctionalInterface public interface SessionCompactor
源码Source io/agentscope/extensions/aistio/adapter/SessionCompactor.java:48–59

定义会话 Compactor契约的接口。位于 io.agentscope.extensions.aistio.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
sessionIdString会话标识(类型 `String`)。the session to compact
stateAgentState状态对象(类型 `AgentState`)。live agent state for that session; mutate `state.contextMutable()` to apply the compacted history
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/extensions/aistio/adapter/SessionCompactor.java:58
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.