AS AgentScopeAPI 手册 / API Reference

ContextTracker

public final class ContextTracker
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:36–216

上下文 Tracker,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.controlplane.model 包。核心成员包括 getSessionId、getContextHash、getMessageCount、getEffectiveMessageCount、getTokensIn、getTokensOut。

Incrementally maintains one session's effective-context view and its contextHash from the Level-2 event stream.

A compaction event resets the view down to a single summary message, matching what the framework itself will send to the model afterwards.

This is an approximation rebuilt from events; the authoritative context still comes from FrameworkAdapter.extractContext(). Its value is that it is always available in memory, so Level-1 snapshots and change detection cost nothing.

Not thread-safe: the bridge serializes access under its own lock.

构造器摘要Constructor Summary

构造器Constructor说明Description
public ContextTracker(String sessionId, String framework)
初始化 `ContextTracker` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public String getSessionId()
获取会话标识。
Returns the session id.
public String getContextHash()
获取 `getContextHash`。
Returns the context hash.
public int getMessageCount()
获取消息数量。
Returns the message count.
public int getEffectiveMessageCount()
获取 `getEffectiveMessageCount`。
Returns the effective message count.
public int getTokensIn()
获取令牌数 In。
Returns the tokens in.
public int getTokensOut()
获取 `getTokensOut`。
Returns the tokens out.
public int getContextUsedTokens()
获取 `getContextUsedTokens`。
Returns the context used tokens.
public void setContextUsedTokens(int contextUsedTokens)
设置 `setContextUsedTokens`。
Tokens in the live effective context; used for pressure = used / maxTokens.
public boolean isCompacted()
判断是否 `isCompacted`。
Returns whether the compacted.
public int getMaxTokens()
获取最大令牌数。
Returns the max tokens.
public void setMaxTokens(int maxTokens)
设置最大令牌数。
Context window size of the model behind this session, used for pressure ratios.
public String getModel()
获取模型。
Returns the model.
public void setModel(String model)
设置模型。
Model name from agent config, when known.
public void setSystemPrompt(String systemPrompt)
设置系统提示词。
Sets the system prompt.
public void setEffectiveSystemPrompt(String effectiveSystemPrompt)
设置 `setEffectiveSystemPrompt`。
Last middleware-composed system prompt observed for this session (may differ from the builder base prompt).
public String getEffectiveSystemPrompt()
获取 `getEffectiveSystemPrompt`。
Returns the effective system prompt.
public String resolveSystemPrompt()
解析系统提示词。
Prefer the last effective prompt; fall back to the builder base.
public void setTools(List<ToolInfo> tools)
设置工具。
Sets the tools.
public boolean onEvent(SessionEvent event)
处理事件事件。
Consumes one event.
public ContextSnapshot snapshot()
返回快照。
Returns the snapshot.

构造器详情Constructor Detail

ContextTracker

public ContextTracker(String sessionId, String framework)

初始化 ContextTracker 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
frameworkStringframework(类型 `String`)。The framework.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:62–66

方法详情Method Detail

getSessionId

public String getSessionId()

获取会话标识。

Returns the session id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:68–70

getContextHash

public String getContextHash()

获取 getContextHash。

Returns the context hash.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:72–74

getMessageCount

public int getMessageCount()

获取消息数量。

Returns the message count.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:76–78

getEffectiveMessageCount

public int getEffectiveMessageCount()

获取 getEffectiveMessageCount。

Returns the effective message count.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:80–82

getTokensIn

public int getTokensIn()

获取令牌数 In。

Returns the tokens in.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:84–86

getTokensOut

public int getTokensOut()

获取 getTokensOut。

Returns the tokens out.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:88–90

getContextUsedTokens

public int getContextUsedTokens()

获取 getContextUsedTokens。

Returns the context used tokens.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:92–94

setContextUsedTokens

public void setContextUsedTokens(int contextUsedTokens)

设置 setContextUsedTokens。

Tokens in the live effective context; used for pressure = used / maxTokens.

参数Parameters
名称Name类型Type说明Description
contextUsedTokensint上下文 Used 令牌数(类型 `int`)。The context used tokens.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:97–99

isCompacted

public boolean isCompacted()

判断是否 isCompacted。

Returns whether the compacted.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:101–103

getMaxTokens

public int getMaxTokens()

获取最大令牌数。

Returns the max tokens.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:105–107

setMaxTokens

public void setMaxTokens(int maxTokens)

设置最大令牌数。

Context window size of the model behind this session, used for pressure ratios.

参数Parameters
名称Name类型Type说明Description
maxTokensint最大令牌数(类型 `int`)。The max tokens.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:110–112

getModel

public String getModel()

获取模型。

Returns the model.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:114–116

setModel

public void setModel(String model)

设置模型。

Model name from agent config, when known.

参数Parameters
名称Name类型Type说明Description
modelString模型实例(类型 `String`)。The model.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:119–121

setSystemPrompt

public void setSystemPrompt(String systemPrompt)

设置系统提示词。

Sets the system prompt.

参数Parameters
名称Name类型Type说明Description
systemPromptString系统提示词(类型 `String`)。The system prompt.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:123–125

setEffectiveSystemPrompt

public void setEffectiveSystemPrompt(String effectiveSystemPrompt)

设置 setEffectiveSystemPrompt。

Last middleware-composed system prompt observed for this session (may differ from the builder base prompt).

参数Parameters
名称Name类型Type说明Description
effectiveSystemPromptStringeffective 系统提示词(类型 `String`)。The effective system prompt.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:131–133

getEffectiveSystemPrompt

public String getEffectiveSystemPrompt()

获取 getEffectiveSystemPrompt。

Returns the effective system prompt.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:135–137

resolveSystemPrompt

public String resolveSystemPrompt()

解析系统提示词。

Prefer the last effective prompt; fall back to the builder base.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:140–142

setTools

public void setTools(List<ToolInfo> tools)

设置工具。

Sets the tools.

参数Parameters
名称Name类型Type说明Description
toolsList<ToolInfo>工具列表(类型 `List`)。The tools.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:144–146

onEvent

public boolean onEvent(SessionEvent event)

处理事件事件。

Consumes one event.

参数Parameters
名称Name类型Type说明Description
eventSessionEvent事件(类型 `SessionEvent`)。The event.
返回Returns boolean
返回布尔值,表示判断结果。`true` when the context hash changed, which is what gates Level-4 pushes
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:153–198

snapshot

public ContextSnapshot snapshot()

返回快照。

Returns the snapshot.

返回Returns ContextSnapshot
返回ContextSnapshot。Returns context snapshot.
源码Source io/agentscope/extensions/controlplane/model/ContextTracker.java:200–215
基于官方固定版本源码静态生成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.