The Context Pack: Turning Inputs Into a Quality Contract

zhulinsen/daily_stock_analysis has already separated market time, source route, and capability from the headline recommendation. The AnalysisContextPack gives those distinctions a shared form. Its job is not to fetch more data or to make a prediction by itself. Its job is to describe what the pipeline already collected, how trustworthy and complete each part appears, and what different consumers are allowed to see. That makes the pack a quality contract between retrieval, model synthesis, and user-facing transparency.

The design solves two problems at once. Without a common contract, the traditional analyzer, Agent path, history view, and API could each interpret “missing” or “fallback” differently. Without a visibility boundary, making the system transparent could mean exposing raw news, private context, or credentials. The pack addresses both by separating assembly from retrieval and by projecting the same underlying state into different surfaces.

A contract built from what the pipeline already has

The pack builder is deliberately zero-fetch. By the time it runs, the pipeline may already have a realtime quote, stored daily bars, a trend result, chip data, fundamentals, news context, a phase summary, and optional portfolio context. The builder takes those artifacts as inputs and assembles them into one versioned envelope. It does not call the database, a provider, a search service, or an Agent tool to fill gaps.

That boundary is easy to underestimate. A second fetch would appear convenient: the builder could ask again for a missing quote or retrieve a fresh news result. But it would create a second data path with its own timing, retries, provider choice, and failure semantics. The model might then see one value while the report or diagnostics record another. A zero-fetch assembler keeps ownership clear. Retrieval services own acquisition. The pack builder owns representation. The pipeline remains the place where the artifacts are gathered and combined.

The envelope has a subject and a phase, then groups evidence into blocks. The main blocks are quote, daily bars, technical data, fundamentals, news, and chip information. A portfolio block can be added for a holding-related analysis, but it is auxiliary and does not change the fixed quality score. The block names are not merely categories for a user interface. They identify the claims each kind of evidence can support. A quote block speaks to price and freshness. Daily bars speak to a completed historical window. Technical data speaks to indicators and overlays. News speaks to current information and catalysts. Fundamentals speak to valuation, earnings, and related company data. Chip data speaks to the distribution of holders or cost structure when the market path supplies it.

Each block and item can carry several kinds of metadata at once:

  • Status says whether the field is available, missing, unsupported, a fallback, stale, estimated, partial, or confirmed fetch failure.
  • Source identifies where the value came from, rather than assuming every provider is interchangeable.
  • Timestamp anchors the value to a provider or acquisition time when that time is available.
  • Fallback information records that an earlier route failed or was bypassed before a later source supplied the result.
  • Warnings carry stable explanations such as a realtime overlay or a stale quote.
  • Missing reason explains why a needed field is absent, such as no daily bars or an unsupported capability.

These fields answer different questions. A source name cannot tell us whether the value is fresh. A timestamp cannot tell us whether a market supports the requested fundamental field.