AS AgentScopeAPI 手册 / API Reference

Builder

public static class Builder
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:142–290

构建器,用于构建并配置目标实例。位于 io.agentscope.core.memory.autocontext 包。核心成员包括 largePayloadThreshold、maxToken、tokenRatio、offloadSinglePreview、msgThreshold、lastKeep。

Builder class for constructing AutoContextConfig instances.

This builder provides a fluent API for configuring AutoContextMemory parameters. All fields have default values matching those in AutoContextConfig.

Example usage:

`AutoContextConfig config = AutoContextConfig.builder()
.msgThreshold(50)
.maxToken(64 * 1024)
.lastKeep(20)
.build();
`

方法摘要Method Summary

方法Method说明Description
public Builder largePayloadThreshold(long largePayloadThreshold)
设置该配置项。
Sets the threshold (in characters) for large payload messages to be offloaded.
public Builder maxToken(long maxToken)
设置最大令牌。
Sets the maximum token limit for context window.
public Builder tokenRatio(double tokenRatio)
设置该配置项。
Sets the token ratio threshold (0.0-1.0) to trigger compression.
public Builder offloadSinglePreview(int offloadSinglePreview)
设置该配置项。
Sets the preview length (in characters) for offloaded messages.
public Builder msgThreshold(int msgThreshold)
设置消息阈值。
Sets the message count threshold to trigger compression.
public Builder lastKeep(int lastKeep)
设置该配置项。
Sets the number of recent messages to keep uncompressed.
public Builder minConsecutiveToolMessages(int minConsecutiveToolMessages)
设置该配置项。
Sets the minimum number of consecutive tool messages required for compression.
public Builder currentRoundCompressionRatio(double currentRoundCompressionRatio)
设置该配置项。
Sets the compression ratio (0.0-1.0) for current round messages.
public Builder minCompressionTokenThreshold(int minCompressionTokenThreshold)
设置最小压缩令牌阈值。
Sets the minimum token count required for compression to proceed.
public Builder customPrompt(PromptConfig customPrompt)
设置自定义提示词配置。
Sets custom prompt configuration.
public AutoContextConfig build()
构建并返回最终实例。
Builds and returns a new AutoContextConfig instance with the configured values.

方法详情Method Detail

largePayloadThreshold

public Builder largePayloadThreshold(long largePayloadThreshold)

设置该配置项。

Sets the threshold (in characters) for large payload messages to be offloaded.

参数Parameters
名称Name类型Type说明Description
largePayloadThresholdlonglarge 负载阈值(类型 `long`)。the threshold in characters
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:160–163

maxToken

public Builder maxToken(long maxToken)

设置最大令牌。

Sets the maximum token limit for context window.

参数Parameters
名称Name类型Type说明Description
maxTokenlong最大令牌(类型 `long`)。the maximum token count
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:171–174

tokenRatio

public Builder tokenRatio(double tokenRatio)

设置该配置项。

Sets the token ratio threshold (0.0-1.0) to trigger compression.

参数Parameters
名称Name类型Type说明Description
tokenRatiodouble令牌 Ratio(类型 `double`)。the token ratio (0.0-1.0)
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:182–185

offloadSinglePreview

public Builder offloadSinglePreview(int offloadSinglePreview)

设置该配置项。

Sets the preview length (in characters) for offloaded messages.

参数Parameters
名称Name类型Type说明Description
offloadSinglePreviewint卸载 Single 预览(类型 `int`)。the preview length in characters
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:193–196

msgThreshold

public Builder msgThreshold(int msgThreshold)

设置消息阈值。

Sets the message count threshold to trigger compression.

参数Parameters
名称Name类型Type说明Description
msgThresholdint消息数量阈值。the message count threshold
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:204–207

lastKeep

public Builder lastKeep(int lastKeep)

设置该配置项。

Sets the number of recent messages to keep uncompressed.

参数Parameters
名称Name类型Type说明Description
lastKeepint最后 Keep(类型 `int`)。the number of messages to keep
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:215–218

minConsecutiveToolMessages

public Builder minConsecutiveToolMessages(int minConsecutiveToolMessages)

设置该配置项。

Sets the minimum number of consecutive tool messages required for compression.

参数Parameters
名称Name类型Type说明Description
minConsecutiveToolMessagesint最小 Consecutive 工具消息(类型 `int`)。the minimum consecutive tool messages count
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:226–229

currentRoundCompressionRatio

public Builder currentRoundCompressionRatio(double currentRoundCompressionRatio)

设置该配置项。

Sets the compression ratio (0.0-1.0) for current round messages.

参数Parameters
名称Name类型Type说明Description
currentRoundCompressionRatiodouble当前 Round 压缩 Ratio(类型 `double`)。the compression ratio (0.0-1.0)
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:239–242

minCompressionTokenThreshold

public Builder minCompressionTokenThreshold(int minCompressionTokenThreshold)

设置最小压缩令牌阈值。

Sets the minimum token count required for compression to proceed.

参数Parameters
名称Name类型Type说明Description
minCompressionTokenThresholdint最小压缩令牌阈值(类型 `int`)。the minimum token count threshold
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:252–255

customPrompt

public Builder customPrompt(PromptConfig customPrompt)

设置自定义提示词配置。

Sets custom prompt configuration.

参数Parameters
名称Name类型Type说明Description
customPromptPromptConfig自定义提示词(类型 `PromptConfig`)。the custom prompt configuration, or null to use defaults
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance for method chaining
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:266–269

build

public AutoContextConfig build()

构建并返回最终实例。

Builds and returns a new AutoContextConfig instance with the configured values.

返回Returns AutoContextConfig
一种新的AutoContextConfig 实例。a new AutoContextConfig instance
源码Source io/agentscope/core/memory/autocontext/AutoContextConfig.java:276–289
基于官方固定版本源码静态生成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.