Context, compaction, and token usage

Understand how the context window, token usage, compaction, and restore work in a chat in Cloudera Agent Studio, so that you can read the results of the slash commands correctly.

Context occupancy

The /context command shows how full the context window is. The card shows the context percentage, the number of context tokens, the size of the context window, the number of messages, the model, and the auto-compaction threshold when one is available. If a restore paused automatic compaction, the threshold tile shows paused.

Agent Studio calculates the occupancy from the input that it shapes for the model. It does not add up the token usage of all earlier turns. The percentage is the number of context tokens divided by the size of the context window. After a compaction or a restore, the context meter updates immediately. After an automatic compaction, the meter refreshes.

The thresholds and the window sizes depend on the runtime and model configuration, so no percentage is the same in every deployment.

Token usage

The /usage command shows the cumulative tokens that Agent Studio recorded for the conversation. The card shows the input and output token totals, the number of messages, the model, and the cost.

Token usage is the total spend over the completed turns. It is not the current context occupancy. Do not compare it directly with the percentage that /context shows.

Compaction

Compaction folds older history into a summary and keeps a recent part of the conversation in its original form. The runtime chooses where the fold ends according to its configured token budget, and it keeps each tool call together with its result. Compaction does not delete the original stored messages.

A compaction can run in two ways:

  • Automatic compaction is part of the runtime behavior. You do not enter a command for it.
  • Manual compaction runs when you submit /compact. It is also the action that resumes automatic compaction after a restore.

Compaction asks the model to summarize the history, so it can use model resources, and it can fail if the model or the runtime is not available. A fold needs enough eligible history. A conversation that is not empty does not always have enough.

Compaction differs from /clear. Compaction keeps the same conversation and a summary of the earlier context. /clear opens a new chat.

Restore

A restore undoes the most recent active compaction. Agent Studio adds a revert marker, and because the original messages still exist, the earlier view of the context returns without a rebuild from the summary. If the conversation has more than one active compaction, repeated restores undo them one at a time.

A successful restore pauses automatic compaction until you submit /compact again. The context usage can rise sharply after the history unfolds, so check /context before you continue a large conversation.

A restore is not a message rewind, it does not roll back the effects of tools, and it does not delete a session.

Active runs

The runtime refuses a compaction or a restore while a run on the conversation is active. A run that is paused and waits for your input is also active. To change the context, resolve the pause, wait for the run to finish, or stop the run.