An agent that answers from yesterday's numbers without saying so is worse than one that answers nothing. Real-time context is not about making every query hit the warehouse; it is about every answer knowing, and saying, how current it is, and about the owner of the context choosing that on purpose.
In InsightCompose a context is served from a governed contract: SQL with typed parameters, a declared row scope, masking rules and a freshness promise. This post is about the last of those. It covers the three ways an answer can be produced (live, cached, snapshot), what the cache is keyed on so two callers never see each other's rows, and the as_of stamp that travels with every answer to whoever consumes it.
Freshness is part of the contract, not a property of the pipe
Most data platforms describe freshness from the pipeline's point of view: the job runs at two, the table lands at three. The consumer of an answer does not care about the job. It cares whether the open-claims count it is about to quote to an underwriter is current enough for the decision in front of it.
So freshness is declared on the contract itself, next to the SQL and the parameters:
- Cadence:
live,hourly,nightly,weeklyorstatic. This is how current the underlying rows are expected to be. - SLA in minutes: the owner's commitment that rows are never older than this. It is a number a consumer can hold the owner to.
- A description in plain words, for people reading the catalog and for the assistant deciding whether this context suits the question.
{
"key": "claims.ops.open_by_line",
"version": 3,
"freshness": { "cadence": "hourly", "sla_minutes": 90,
"description": "Claims system extract lands hourly" },
"cache_ttl_s": 300,
"cache_stale_s": 600
}
That declaration appears in the catalog row for the context, in the REST response and in the MCP tool description. An agent sees the promise before it calls and the stamp after.
Three ways an answer is produced
Live at request time
A context with no cache entry runs at the moment it is asked. The caller's scope is wrapped around the template, values are bound as parameters, the statement runs read-only with a timeout and a row cap, and the rows come back with their typed columns. This is the right default for operational questions where minutes matter: open submissions, claims reported today, stock on hand.
From a time-to-live cache
Twenty people opening the same dashboard at nine o'clock should cost one warehouse query, not twenty. Each contract can set cache_ttl_s, how long an answer is kept, and cache_stale_s, how long after that an older answer may still be served while one refresh runs in the background. That second window is stale-while-revalidate: the caller gets an answer immediately and the next caller gets a fresh one.
as_of and the contract's freshness.Concurrent misses for the same key share one call. This is single flight: if forty agents ask the same question in the same second after an entry expires, the warehouse sees one query and all forty get its answer.
From a snapshot
Some contexts should not be live at all. A book-of-business summary computed overnight, a month-end loss triangle, a peer benchmark rebuilt weekly: these read from tables a pipeline writes on a schedule, and their contract says nightly or weekly. Declaring it is what matters. An agent reading a nightly context at four in the afternoon knows it is reading last night's numbers, because the contract and the answer both say so.
What the cache is keyed on
A shared cache in front of governed data is only safe if two callers who would get different rows can never share an entry. The key for a cached answer is built from everything the answer depends on and nothing else:
| Part of the key | Why it is there |
|---|---|
| Namespace | The product, the tenant and the source that tenant is bound to. Tenants never share entries. |
| Contract key and version | A new version is a new answer, even for identical parameters. |
| Resolved parameters, normalised | Defaults filled in and keys sorted, so {"days": 30} and {"days": "30"} are one question. |
| Caller scope | The book (owners) and the organisation the caller is confined to. |
| Masking | Whether masked columns apply. A cleared caller and an uncleared one never share rows. |
| Row cap | The limit asked for is part of the answer. |
| Data version | Bumped after a load; every older entry becomes unreachable at once. |
That last line is the only refresh trigger we describe, because it is the one that exists: when a load finishes, the loader calls bump on the namespace and the cache stops serving anything computed before it. There is no separate invalidation list to maintain and no entry that survives a reload by accident.
What is never cached
Caching the wrong thing is how stale context does real damage. The rules are deliberately narrow:
- Only answers that came back are kept. A refusal, a bad parameter, a timeout or a failure is never cached, so a transient outage does not become a five-minute outage.
- An empty answer is kept for a shorter time than a full one, because a table that is still loading reads as empty.
- A contract can set
cache_ttl_sto zero. It is then always live. - A cache backend that fails falls back to memory and is retried after a pause. A cache outage never fails a query.
The as_of stamp, everywhere
Every answer, whichever path produced it, carries the same envelope: the contract key and version, the typed columns with labels and units, the rows, whether they were truncated or masked, how long they took, the freshness declaration and as_of, the time the rows were read.
{
"key": "claims.ops.open_by_line", "version": 3,
"columns": [{"name": "line", "label": "Line of business", "type": "text"},
{"name": "open_claims", "label": "Open claims", "unit": "count"}],
"rows": [["Commercial Auto", 412], ["General Liability", 268]],
"truncated": false, "masked": false, "duration_ms": 184,
"as_of": "2026-11-15T09:02:11+00:00",
"freshness": {"cadence": "hourly", "sla_minutes": 90}
}
Over REST the cache state is also in the headers: X-DataAPI-Cache is HIT, STALE or MISS, and a hit carries an Age in seconds. Over MCP the same stamp is in the tool result, so an agent can quote it: open commercial auto claims are 412 as of 09:02 UTC. A dashboard tile shows it under the number.
Teach the agent to say it. The most useful line in an agent's system prompt about context is often the simplest: when you quote a figure, quote its as_of. Because every answer carries one, the instruction always has something to point at.
Refreshing on demand
Sometimes a person knows the cache is behind: a correction just landed, a load was rerun. An administrator can ask for a refresh, which skips the cached answer and replaces it. Other callers cannot, by design; a refresh is a warehouse query on someone else's budget, and an agent in a loop should not be able to force one on every turn. The refresh is recorded in the call audit like any other call.
Choosing a freshness per context
The choice belongs to the owner of each context, and it is usually easy once it is asked explicitly:
| Kind of context | Typical choice |
|---|---|
| Operational queues (open submissions, claims reported today) | Live, or a cache of a minute or two |
| Executive KPIs viewed by many at once | Hourly cadence, a few minutes of TTL, a stale window |
| Book-of-business 360, peer benchmarks, loss triangles | Nightly or weekly snapshot tables, cached for hours |
| Reference data (lines, states, class codes) | Static, public scope, cached long |
What matters is that the choice is visible. An agent comparing a live queue with a nightly benchmark can tell they were read at different times, and say so. Read more about how the same context reaches each consumer in one context, many consumers, and about the real-time options on the real-time context page.
Where people stay in charge
- The owner sets the promise. Cadence, SLA, TTL and stale window are declared by the person accountable for the context, and reviewed when the contract is published.
- The loader decides when the old answers die. A bump after a load is an explicit step in the pipeline your team runs, not a guess by the cache.
- Only administrators force a refresh. Agents and applications cannot turn a cache off for themselves.
- Every answer is dated. People reading an agent's reply can see when the numbers were read, and challenge them.