Context inspector #
The context inspector describes a prepared model request.
context_snapshot.from_request
builds sections for present instructions, conversation history, and encoded tool
schemas. The snapshot identifies the provider, model, protocol, and available
compaction observation. See compaction for how a strategy
prepares the conversation.
Request composition #
The instructions section contains the request instructions. The history section
represents the prepared inputs, and the tools section uses the provider's tool
encoding. Section metadata includes item and byte counts. History inspection
renders user text, assistant text, and tool output, but replaces images with
metadata and opaque provider replay items with a marker. The inspector does not
expose those payloads. See
inspection_entry and input_omission.
A snapshot can be pending before a request has been prepared. A ready snapshot
has an identity, section previews, and compaction information. Usage metadata
can update the snapshot.
session_run.gleam
captures the prepared request, and
session.gleam reads and can rebuild
the snapshot.
The compaction information carries the request's size, a
size.Total the
strategy reported, as an object: tokens, the measured part with its source
(count_endpoint or reported_usage), and the estimated part with its
correction. It is null while the strategy has none. Clients show each part for
what it is and label the estimate; they do not recover how a number was taken
from text.
A ready summary's media_tokens gives the tokens the request's pictures, audio
and video take, by kind, priced on the request's route with
size.image_tokens, the
pricer sizing uses: pictures by tiles, clips by how long they play where the
wire publishes a rate (see media). The numbers
are before any correction. Only what the request carries counts: clips a
compaction summarized or a model does not read are left out. A client cannot
price a clip itself, since it does not know how long the clip plays. The web
context meter weighs its images, audio and video slices by these numbers, and
falls back to its own estimate from the history only for a daemon that does not
send them.
Local API #
The session request handler in
http_sessions.gleam
serves the summary at /sessions/{id}/context and sections at
/sessions/{id}/context/{snapshot_id}/sections/{section_id}?page=0. A section
request requires its captured snapshot identity and a page. A changed snapshot
returns HTTP 410 with context_changed. An unknown section or page returns HTTP
404 with context_section_unknown. Request-list pagination parameters are
rejected for these resources.
context_snapshot.page
numbers pages from zero and caps each page at 8,000 Unicode scalars. A pending
snapshot cannot provide a page. The terminal inspector consumes this interface
in context_inspector.go.