Class ContextTracker

java.lang.Object
io.agentscope.extensions.aistio.model.ContextTracker

public final class ContextTracker extends Object
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 Details

    • ContextTracker

      public ContextTracker(String sessionId, String framework)
  • Method Details

    • getSessionId

      public String getSessionId()
    • getContextHash

      public String getContextHash()
    • getMessageCount

      public int getMessageCount()
    • getEffectiveMessageCount

      public int getEffectiveMessageCount()
    • getTokensIn

      public int getTokensIn()
    • getTokensOut

      public int getTokensOut()
    • getContextUsedTokens

      public int getContextUsedTokens()
    • setContextUsedTokens

      public void setContextUsedTokens(int contextUsedTokens)
      Tokens in the live effective context; used for pressure = used / maxTokens.
    • isCompacted

      public boolean isCompacted()
    • getMaxTokens

      public int getMaxTokens()
    • setMaxTokens

      public void setMaxTokens(int maxTokens)
      Context window size of the model behind this session, used for pressure ratios.
    • getModel

      public String getModel()
    • setModel

      public void setModel(String model)
      Model name from agent config, when known.
    • setSystemPrompt

      public void setSystemPrompt(String systemPrompt)
    • setEffectiveSystemPrompt

      public void setEffectiveSystemPrompt(String effectiveSystemPrompt)
      Last middleware-composed system prompt observed for this session (may differ from the builder base prompt). Empty until the first turn completes onSystemPrompt.
    • getEffectiveSystemPrompt

      public String getEffectiveSystemPrompt()
    • resolveSystemPrompt

      public String resolveSystemPrompt()
      Prefer the last effective prompt; fall back to the builder base.
    • setTools

      public void setTools(List<ContextSnapshot.ToolInfo> tools)
    • onEvent

      public boolean onEvent(SessionEvent event)
      Consumes one event.
      Returns:
      true when the context hash changed, which is what gates Level-4 pushes
    • snapshot

      public ContextSnapshot snapshot()