# Give the model the right working packet

LockedIn Labs · Original 40-minute context exercise · Updated 20 October 2026

You ask a teammate to write a client update. What do they need in front of them?
The current incident, the next step, any restriction and the deadline. They do
not need every old conversation. They cannot use a current fact you never
supplied. Preparing that working packet is the starting point for context
management.

This guide builds an actual JSON request plan in Python. All incidents are
fictional. No model runs, no account is needed, and no request leaves your
computer. The plan is a provider-neutral teaching envelope, not a ready-made
Claude, OpenAI or LangChain API call.

## 1. Understand context before optimizing it

**Context** is the information supplied for one model request. It can include
instructions, the task, conversation, tool descriptions and evidence.
**Context management** selects and maintains that information. It is an
engineering practice, not a programming language or a model.

Three different things often get called memory:

| Thing | What it means here |
| --- | --- |
| Learned model parameters | Patterns learned during model training |
| Saved application state | Records or messages the application retains |
| Current context | Information selected into this request |

Putting a file in a repository or a note in a database does not automatically
make it part of a model call. The application or framework must select it.
Retrieval helps find material; a context builder decides what to include.

Think of a colleague receiving an incident packet. That analogy helps explain
selection, but it does not mean a model has the same memory or judgment as a
person.

## 2. Run the local context builder

Download [the original Python exercise](/templates/fde-first-context.py) into a
new practice folder. Use Python 3.11 or newer. The exercise uses only the standard
library, so there are no packages, credentials or model downloads to install.
It reads no local project files or account state and writes no files.

```shell
python3 fde-first-context.py test
python3 fde-first-context.py demo
python3 fde-first-context.py inspect --case compact
```

On Windows, use `py -3` instead of `python3`.

Nine checks cover useful compression, lost constraints, stale facts, false
relabeling, refreshed evidence, source scope, excluded state, task preservation
and byte counts. A successful test run ends with `OK`. An observed failing
packet is an expected exercise result, not a command failure.

The application-side scope in this small program is an explicit synthetic
project marker. It demonstrates checking before copying; it is not an
authentication system.

## 3. Follow the information into the request

The task is to **draft** an update about incident `INC-17`, without sending it.
The model-visible request plan has three parts:

```text
APPLICATION                         REQUEST PLAN
                                    ┌─────────────────────────────┐
Task + host instruction ───────────►│ Instruction + current task  │
                                    ├─────────────────────────────┤
Incident INC-17                     │ Evidence                    │
  check scope                       │   source_id + revision      │
  select relevant fields ──────────►│   problem + next_step       │
                                    │   restriction + deadline    │
                                    └─────────────────────────────┘
Old unrelated conversation ── leave out
Runtime permission checks  ── stay in the application
```

The source restriction says to keep the import paused until the service owner
approves a retry. That is essential to the update. The deadline includes UTC
(`Z`); dropping the zone changes what the reader knows.

Open `assemble` in the file. It checks the source scope and explicitly copies
the permitted fields. Adding an unrelated field to the source does not
automatically put it in the packet. This is different from serializing the
whole runtime object into a prompt.

## 4. Compare shorter with useful

Predict each case before inspecting it:

```shell
python3 fde-first-context.py inspect --case full
python3 fde-first-context.py inspect --case compact
python3 fde-first-context.py inspect --case lossy
```

| Case | Serialized size | Observation |
| --- | --- | --- |
| full | 1,002 UTF-8 bytes | All required fields and six diagnostic lines |
| compact | 565 UTF-8 bytes | All required fields; no diagnostic repetition |
| lossy | 450 UTF-8 bytes | Restriction and deadline missing |

The useful summary saves 437 bytes while preserving the fields needed for this
draft. The shortest version saves another 115 bytes and loses two decision
constraints. Size and usefulness are separate questions.

These sizes come from compact JSON serialization followed by UTF-8 encoding.
They are **not token counts**, window limits, model timings or billed usage.
Use the [token lab](/training/guides/tokens) to understand that separate
representation.

Compaction is reducing what you carry forward. This exercise uses a hand-written
field-selection rule. A model-generated prose summary needs its own evaluation:
can another person recover the important facts, sources and restrictions?
There is no model-generated summary in this program.

## 5. Refresh facts, not just the label

The incident now advances to revision 2. There is a replacement file, a revised
restriction and a new deadline. Compare:

```shell
python3 fde-first-context.py inspect --case stale
python3 fde-first-context.py inspect --case refreshed
```

The stale packet has no missing fields, yet `revision`, `next_step`,
`restriction` and `deadline` differ from the current record. Completeness
does not imply freshness.

The refreshed packet is 568 bytes and preserves the current record. The
program's `test_relabeling_is_not_refreshing` test changes just the old revision
label to `2`: the version matches, but three fields still disagree.
Re-read the record and rebuild the packet instead.

A source can change again after a model drafts an answer. Before a consequential
action, the application needs a current permission and source check. A prompt
cannot make that later action atomic.

## 6. Make one controlled change

Keep the original exercise. Work in a separate copy.

1. In the lossy branch, keep the deadline but still delete the restriction.
2. Predict the `missing` list, then inspect that case. The original two-field
   loss test should now fail because you intentionally changed its fixture.
3. Record the actual missing field and explain what the draft could omit.
4. Restore the restriction and compare with `compact`.
5. Inspect the relabeling test. Explain why its version match does not pass the
   whole contract.

Retain a small before/after packet, the observed result and your explanation.
Do not reduce a failure to a headline score.

The inspection code compares exact fields with a known synthetic source.
It cannot judge arbitrary prose or prove that a model follows instructions.
Marking source text as evidence also does not establish prompt-injection
resistance. Real source access, model evaluation and action enforcement remain
distinct checks.

## 7. Bring the method to an FDE task

Your coding agent resumes from a note saying the tests passed. The repository
has changed since that note was written.

Draw what goes into the next request: the task, relevant files, current revision
and new test observations. Keep the old note as dated evidence. Explain what
would invalidate it. Do not treat a remembered success as a test of new code.

Keep these artifacts:

- A plain explanation of context, retained state and retrieval.
- A diagram showing selected input and application-owned authority.
- Five observed cases, including lost and stale facts.
- One controlled repair and the next model or integration check.

Continue into the guided Academy lesson for the interactive packet comparison,
knowledge checks and saved practice. Program access is checked on sign-in.

## 8. Read the primary references

Checked 20 October 2026. This is original instruction and exercise code, not a
copy of provider courseware.

- [Claude: context windows](https://platform.claude.com/docs/en/build-with-claude/context-windows)
  explains request context and provider counting rules.
- [Anthropic Engineering: effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)
  discusses selecting and maintaining useful information.
- [LangChain: short-term memory](https://docs.langchain.com/oss/python/langchain/short-term-memory)
  describes conversation-state handling and strategies such as trimming and
  summarizing.
