ContextTracker
public final class ContextTracker
io/agentscope/extensions/aistio/model/ContextTracker.java:36–216上下文 Tracker,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.aistio.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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
framework | String | framework(类型 `String`)。The framework. |
io/agentscope/extensions/aistio/model/ContextTracker.java:62–66方法详情Method Detail
getSessionId
public String getSessionId()
获取会话标识。
Returns the session id.
Stringio/agentscope/extensions/aistio/model/ContextTracker.java:68–70getContextHash
public String getContextHash()
获取 getContextHash。
Returns the context hash.
Stringio/agentscope/extensions/aistio/model/ContextTracker.java:72–74getMessageCount
public int getMessageCount()
获取消息数量。
Returns the message count.
intio/agentscope/extensions/aistio/model/ContextTracker.java:76–78getEffectiveMessageCount
public int getEffectiveMessageCount()
获取 getEffectiveMessageCount。
Returns the effective message count.
intio/agentscope/extensions/aistio/model/ContextTracker.java:80–82getTokensIn
public int getTokensIn()
获取令牌数 In。
Returns the tokens in.
intio/agentscope/extensions/aistio/model/ContextTracker.java:84–86getTokensOut
public int getTokensOut()
获取 getTokensOut。
Returns the tokens out.
intio/agentscope/extensions/aistio/model/ContextTracker.java:88–90getContextUsedTokens
public int getContextUsedTokens()
获取 getContextUsedTokens。
Returns the context used tokens.
intio/agentscope/extensions/aistio/model/ContextTracker.java:92–94setContextUsedTokens
public void setContextUsedTokens(int contextUsedTokens)
设置 setContextUsedTokens。
Tokens in the live effective context; used for pressure = used / maxTokens.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contextUsedTokens | int | 上下文 Used 令牌数(类型 `int`)。The context used tokens. |
io/agentscope/extensions/aistio/model/ContextTracker.java:97–99isCompacted
public boolean isCompacted()
判断是否 isCompacted。
Returns whether the compacted.
booleanio/agentscope/extensions/aistio/model/ContextTracker.java:101–103getMaxTokens
public int getMaxTokens()
获取最大令牌数。
Returns the max tokens.
intio/agentscope/extensions/aistio/model/ContextTracker.java:105–107setMaxTokens
public void setMaxTokens(int maxTokens)
设置最大令牌数。
Context window size of the model behind this session, used for pressure ratios.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
maxTokens | int | 最大令牌数(类型 `int`)。The max tokens. |
io/agentscope/extensions/aistio/model/ContextTracker.java:110–112getModel
public String getModel()
获取模型。
Returns the model.
Stringio/agentscope/extensions/aistio/model/ContextTracker.java:114–116setModel
public void setModel(String model)
设置模型。
Model name from agent config, when known.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。The model. |
io/agentscope/extensions/aistio/model/ContextTracker.java:119–121setSystemPrompt
public void setSystemPrompt(String systemPrompt)
设置系统提示词。
Sets the system prompt.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
systemPrompt | String | 系统提示词(类型 `String`)。The system prompt. |
io/agentscope/extensions/aistio/model/ContextTracker.java:123–125setEffectiveSystemPrompt
public void setEffectiveSystemPrompt(String effectiveSystemPrompt)
设置 setEffectiveSystemPrompt。
Last middleware-composed system prompt observed for this session (may differ from the builder base prompt).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
effectiveSystemPrompt | String | effective 系统提示词(类型 `String`)。The effective system prompt. |
io/agentscope/extensions/aistio/model/ContextTracker.java:131–133getEffectiveSystemPrompt
public String getEffectiveSystemPrompt()
获取 getEffectiveSystemPrompt。
Returns the effective system prompt.
Stringio/agentscope/extensions/aistio/model/ContextTracker.java:135–137resolveSystemPrompt
public String resolveSystemPrompt()
解析系统提示词。
Prefer the last effective prompt; fall back to the builder base.
Stringio/agentscope/extensions/aistio/model/ContextTracker.java:140–142setTools
public void setTools(List<ToolInfo> tools)
设置工具。
Sets the tools.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
tools | List<ToolInfo> | 工具列表(类型 `List`)。The tools. |
io/agentscope/extensions/aistio/model/ContextTracker.java:144–146onEvent
public boolean onEvent(SessionEvent event)
处理事件事件。
Consumes one event.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | SessionEvent | 事件(类型 `SessionEvent`)。The event. |
booleanio/agentscope/extensions/aistio/model/ContextTracker.java:153–198snapshot
public ContextSnapshot snapshot()
返回快照。
Returns the snapshot.
ContextSnapshotio/agentscope/extensions/aistio/model/ContextTracker.java:200–215