AS AgentScopeAPI 手册 / API Reference

Builder

public static class Builder
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:271–402

构建器,用于构建并配置目标实例。位于 io.agentscope.harness.agent.memory.compaction 包。核心成员包括 triggerMessages、triggerTokens、reserved、keepMessages、keepTokens、keepTokensMin。

A class in io.agentscope.harness.agent.memory.compaction that persists and restores session and memory data across calls. Declared in io.agentscope.harness.agent.memory.compaction.

方法摘要Method Summary

方法Method说明Description
public Builder triggerMessages(int triggerMessages)
设置该配置项。
Trigger compaction when conversation has at least this many messages (0 = disabled).
public Builder triggerTokens(int triggerTokens)
设置该配置项。
Trigger compaction when estimated token count exceeds this value.
public Builder reserved(int reserved)
设置该配置项。
Token buffer reserved for the compaction process (default 20 000).
public Builder keepMessages(int keepMessages)
设置该配置项。
Number of recent messages to keep verbatim after compaction.
public Builder keepTokens(int keepTokens)
设置该配置项。
Token budget for the preserved tail.
public Builder keepTokensMin(int keepTokensMin)
设置该配置项。
Performs the keep tokens min operation.
public Builder keepTokensMax(int keepTokensMax)
设置该配置项。
Performs the keep tokens max operation.
public Builder keepTokensRatio(double keepTokensRatio)
设置该配置项。
Performs the keep tokens ratio operation.
public Builder summaryPrompt(String summaryPrompt)
设置摘要提示词。
Custom summary prompt.
public Builder flushBeforeCompact(boolean flushBeforeCompact)
设置该配置项。
Whether to flush long-term memories before compaction (default true).
public Builder offloadBeforeCompact(boolean offloadBeforeCompact)
设置该配置项。
Whether to offload raw messages to session JSONL before compaction (default true).
public Builder truncateArgs(TruncateArgsConfig config)
设置该配置项。
Enables lightweight pre-summarization argument truncation.
public Builder prune(PruneConfig config)
设置修剪。
Configures aggregate tool-result pruning.
public Builder model(Model model)
设置模型。
Sets a dedicated model for compaction (summarization), allowing a lighter/cheaper model than the agent's primary reasoning model.
public Builder model(String modelId)
设置模型。
Sets a dedicated model for compaction by model id string (e.g.
public CompactionConfig build()
构建并返回最终实例。
Creates and returns an instance.

方法详情Method Detail

triggerMessages

public Builder triggerMessages(int triggerMessages)

设置该配置项。

Trigger compaction when conversation has at least this many messages (0 = disabled).

参数Parameters
名称Name类型Type说明Description
triggerMessagesinttrigger 消息(类型 `int`)。The trigger messages.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:289–292

triggerTokens

public Builder triggerTokens(int triggerTokens)

设置该配置项。

Trigger compaction when estimated token count exceeds this value.

参数Parameters
名称Name类型Type说明Description
triggerTokensinttrigger 令牌数(类型 `int`)。The trigger tokens.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:299–302

reserved

public Builder reserved(int reserved)

设置该配置项。

Token buffer reserved for the compaction process (default 20 000).

参数Parameters
名称Name类型Type说明Description
reservedintreserved(类型 `int`)。The reserved.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:308–311

keepMessages

public Builder keepMessages(int keepMessages)

设置该配置项。

Number of recent messages to keep verbatim after compaction.

参数Parameters
名称Name类型Type说明Description
keepMessagesintkeep 消息(类型 `int`)。The keep messages.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:314–317

keepTokens

public Builder keepTokens(int keepTokens)

设置该配置项。

Token budget for the preserved tail.

参数Parameters
名称Name类型Type说明Description
keepTokensintkeep 令牌数(类型 `int`)。The keep tokens.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:323–326

keepTokensMin

public Builder keepTokensMin(int keepTokensMin)

设置该配置项。

Performs the keep tokens min operation.

参数Parameters
名称Name类型Type说明Description
keepTokensMinintkeep 令牌数最小(类型 `int`)。The keep tokens min.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:328–331

keepTokensMax

public Builder keepTokensMax(int keepTokensMax)

设置该配置项。

Performs the keep tokens max operation.

参数Parameters
名称Name类型Type说明Description
keepTokensMaxintkeep 令牌数最大(类型 `int`)。The keep tokens max.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:333–336

keepTokensRatio

public Builder keepTokensRatio(double keepTokensRatio)

设置该配置项。

Performs the keep tokens ratio operation.

参数Parameters
名称Name类型Type说明Description
keepTokensRatiodoublekeep 令牌数 Ratio(类型 `double`)。The keep tokens ratio.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:338–341

summaryPrompt

public Builder summaryPrompt(String summaryPrompt)

设置摘要提示词。

Custom summary prompt.

参数Parameters
名称Name类型Type说明Description
summaryPromptString摘要提示词(类型 `String`)。The summary prompt.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:344–347

flushBeforeCompact

public Builder flushBeforeCompact(boolean flushBeforeCompact)

设置该配置项。

Whether to flush long-term memories before compaction (default true).

参数Parameters
名称Name类型Type说明Description
flushBeforeCompactboolean刷新之前 Compact(类型 `boolean`)。The flush before compact.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:350–353

offloadBeforeCompact

public Builder offloadBeforeCompact(boolean offloadBeforeCompact)

设置该配置项。

Whether to offload raw messages to session JSONL before compaction (default true).

参数Parameters
名称Name类型Type说明Description
offloadBeforeCompactboolean卸载之前 Compact(类型 `boolean`)。The offload before compact.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:356–359

truncateArgs

public Builder truncateArgs(TruncateArgsConfig config)

设置该配置项。

Enables lightweight pre-summarization argument truncation.

参数Parameters
名称Name类型Type说明Description
configTruncateArgsConfig配置对象(类型 `TruncateArgsConfig`)。The config.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:365–368

prune

public Builder prune(PruneConfig config)

设置修剪。

Configures aggregate tool-result pruning.

参数Parameters
名称Name类型Type说明Description
configPruneConfig配置对象(类型 `PruneConfig`)。The config.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:374–377

model

public Builder model(Model model)

设置模型。

Sets a dedicated model for compaction (summarization), allowing a lighter/cheaper model than the agent's primary reasoning model.

参数Parameters
名称Name类型Type说明Description
modelModel模型实例(类型 `Model`)。The model.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:383–386

model

public Builder model(String modelId)

设置模型。

Sets a dedicated model for compaction by model id string (e.g.

另见See also @see ModelRegistry#resolve(String)
参数Parameters
名称Name类型Type说明Description
modelIdString模型标识(类型 `String`)。The model id.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:394–397

build

public CompactionConfig build()

构建并返回最终实例。

Creates and returns an instance.

返回Returns CompactionConfig
返回CompactionConfig。Returns compaction config.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:399–401
基于官方固定版本源码静态生成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.