Advanced context engineering
Week 2 · LO2, LO3 and LO9
How does a constraint survive a model's next step?
Today’s thread
Prompt → research → plan → implement → verify
MCP-style tools are contracts for a model reader.
One constraint
“Read reports/; never write there.”
Where can it disappear?
Four losses
- Research misses the permission test.
- Plan says only “add export.”
- Schema accepts any path.
- Test checks only that a CSV exists.
Generate, then verify
Write a one-paragraph plan.
Then underline the source, boundary and negative test.
Research artifact
| Question | Evidence |
|---|---|
| What is true? | path + symbol + revision |
| What is unknown? | explicit cannot tell |
Research records claims; it does not edit code.
Plan artifact
An ordered list of small steps:
- boundary
- acceptance case
- implementation point
- check and expected failure
Implement artifact
Patch only what the plan names.
Keep the command that exercises each case.
A specification that can fail
Given out/
When path is reports/summary.csv
Then no file is written
And the result says refused: read-only root
What would a passing test observe?
Three cases
- happy path
- forbidden or malformed input
- boundary value
A “works” sentence is not an acceptance case.
Context is a budget
Reads, logs, failed attempts and instructions accumulate.
A later turn can miss the one constraint that mattered.
Handoff before compaction
Keep:
- task and acceptance check
- constraint source
- current file state
- last failed check and revision
- unknown and next action
Restart or compact?
Compact when the next raw result still matters.
Restart with a written handoff when history is stale or contradictory.
Verify the handoff against the transcript.
A model-facing tool
{"name":"export_report",
"description":"Write below out/; never writes reports/.",
"inputSchema":{"type":"object",
"additionalProperties":false,
"required":["path","rows"]}}
Five contract checks
- Name: verb + object.
- Description: boundary and exclusion.
- Schema: types, required fields, closed object.
- Error: bad field + repair.
- Result: the next observation.
Which call is allowed?
{"path":"out/summary.csv","rows":[]}
{"path":"reports/summary.csv","rows":[]}
The first reaches the handler. The second is refused before an effect.
Errors are context
refused: path must start with out/
Short, actionable, and returned under the call's ID.
MCP is an interface family
A protocol name does not enforce a boundary.
The schema, handler and runtime each have a job.
Read a pinned source
Choose one rule from Source 1 or Source 2.
Ask: text, schema, code, runtime—or unknown?
Studio: cases first
Write three to five cases for your project proposal.
Predict one failure before running it.
Studio: tighten one schema
Save before and after.
Test one valid call, one invalid call and one unknown field.
Verify the revision
Run every case after the last write.
Record command, exit status, output and decision.
Common traps
Prompt first. No rejection case. Open schema. Vague error.
A fluent answer is not a check result.
Week 2 handoff
Due: A2 and project proposal.
Keep the acceptance cases, schema diff and evidence together.
Questions
Which constraint did your tool make visible?