Skip to content

Skill · context · context-engineering

Own the context window

Treat the context window as a product you build every turn: pinned, working, recalled, compacted. Use when the agent forgets the goal, the window overflows, you need retrieval or a skill index, cache-stable prefixes, or the user says context engineering, 'stuff the PDF in', or context hoarding.

GET /api/canon/skills/context-engineering?format=md

Factor 3. The window is a working set, not a log. The goal is the first thing a naive FIFO drops. Anthropic, LangChain, and every serious harness converge on explicit context builders.

When

Hour two of a task, or any time the transcript is treated as the product.

Do

  1. 01

    Lay out the window

    Pinned: goal, constraints, skill index (name+description), tool schemas. Working: last N already-compacted events. Recalled: k retrieved hits. Compacted: running summary.

  2. 02

    Bulk to files

    HTML, CI logs, PDFs, JSON envelopes become files. The window gets a path and a byte count. Grep if needed.

  3. 03

    Keep the prefix stable

    Cacheable system prompt + skill index. Do not shuffle a timestamp into the prefix. Never drop the goal first.

Don't

  • Concatenate six PDFs 'just in case'.
  • Use the full transcript as long-term memory.
  • Silently truncate the goal to keep junk observations.

Hard rules

  • Pinned / working / recalled / compacted — name the four.
  • Skill index always; skill bodies on trigger.
  • Retrieved text is untrusted data, labeled as such.

Context builder

python
def build_window(state, skills, events):
    pinned = [
        state.goal,
        state.constraints,
        skill_index(skills),
        tool_schemas(state.allowed_tools),
    ]
    working = events[-8:]
    recalled = retrieve(state.goal, k=5)
    compacted = [state.running_summary]
    return concat(pinned, compacted, recalled, working)

Refuse

  • Context hoardingRaw HTML, full CI logs, six PDFs, entire JSON envelopes stuffed 'just in case'. The goal is the first thing forgotten.
  • Silent truncationThe goal is dropped to keep junk observations. The model continues confidently.
  • Memory as unfiltered logsSession transcripts stuffed into the next session. The user cannot inspect or delete them.

Load with this

Load next

Trigger tests

Should fire

  • The agent forgets the goal by turn 6
  • Design the context builder
  • We're stuffing whole HTML pages into the prompt

Should not

  • Increase the model's max tokens
  • Add Redis caching to the web app