Skip to content
GitHub (opens in a new tab)

ContextWindow

How full the prompt context is and what uses the space, by segment, with a warning near the limit, Trim oldest and compaction with Undo. Compact form for a header.

stableOrganismcontracts/contextwindow.json

Preview

ContextWindow

How full the prompt context is. Not a usage meter. Not Progress.

Master

Near the limit, the thread compacts: earlier messages fold into a summary, the bar shrinks to its new fill and the freed tokens show. Undo brings the old context back. Variants shows normal, warning, full and compacted.

171K / 200KNear limit

Context window

Near limit

Tokens used/ 200,000 tokens86% used

  • System10.2K
  • Memory16.1K
  • Tools35.2K
  • Messages96.4K
  • Reserved13.2K

Oldest messages will be trimmed soon. Trim now to keep control.

Usage

ContextWindow is about one thread's prompt context. Plan usage is a different meter. Near limit and full are said in text and an icon, never colour alone. For a compaction, pass compaction with the count from before; once compacted, pass the new used and segments. To undo, clear compaction and put used back.

Do's

  • show a thread's context usage next to a chat or agent
  • warn before old messages are trimmed
  • explain what fills the context

Don'ts

  • plan or billing usage — UsageList or a usage meter
  • a generic progress value — Meter or Progress
<ContextWindow
  used={79000}
  limit={200000}
  segments={segments}
  compaction={{ status: "compacted", before: 171000, summary }}
  onUndo={undoCompaction}
  onTrim={trimOldest}
/>

When to use

  • show a thread's context usage next to a chat or agent
  • warn before old messages are trimmed
  • explain what fills the context

When not to use

  • plan or billing usage — UsageList or a usage meter
  • a generic progress value — Meter or Progress

What an agent reads

import { ContextWindow } from "agentic-ds-kit";
must
  • section aria-labelledby the title (compact: aria-label)
  • the stacked bar is role=meter with min, max, now and a text value
  • near limit and full are text and an icon, not colour alone; in compact the word is screen-reader text beside the icon
  • the number uses kit NumberTransition
  • aria-busy while loading; the error is a kit LoadError (role=alert)
  • a role=status live region announces only "Compacted, freed N tokens" and "Compaction undone", on live changes, never on first load
  • the fill glides, the summary row rises in and the label shimmers only on live compaction changes; prefers-reduced-motion keeps them static
defaults
  • warningAt 0.8
  • compact false
  • label Context window
  • loading false
stops if
  • Do not invent a local ContextMeter or TokenBar
  • Do not pass a percent as used
  • Do not signal near-limit by colour alone
  • Do not use raw hex

From contracts/contextwindow.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
usednumberYes—Tokens, not a percent.
limitnumberNo—Without it: "limit unknown", no percentage.
segmentsarrayNo—{ id, label, tokens }[] in display order; colours in order: grey (--border-strong), teal (--chart-2), blue (--chart-1), primary (--primary), light grey (--border-faint); a sixth starts again at grey. No violet.
warningAtnumberNo0.8—
compactbooleanNofalseOne line: kit Meter, used / limit, status icon.
labelstringNoContext window—
onTrimfunctionNo—Trim oldest: outline neutral sm Button in the footer, the same in every state.
compactionobjectNo—{ status: "compacting" | "compacted", before, summary? }. Compacting: a shimmer status line in place of the near-limit notice (compact: spinner). Compacted: freed tokens and %, the count before, and a Collapsible "Earlier context summarized" row with the summary (card only). Clear it and restore used to undo.
onUndofunctionNo—Undo, shown only when status is "compacted": ghost neutral Button before Trim; compact: icon-only Button with a Tooltip.
loadingbooleanNofalse—
errorstringNo——
onRetryfunctionNo——
  • Component
    →

    UsageList

    A list of usage limits, one a row: the limit's name, how much is used of it, a bar, and a short note.

  • Component
    →

    Meter

    How far along or how full something is, from 0 to 100, as a bar, a ring, or a half ring, with optional red, amber, and green zones.

  • Component
    →

    Progress

    Task completion as a bar or circle from 0 to 100, or an indeterminate bar when the percent is not known.

  • Component
    →

    Collapsible

    Single show/hide panel.