A Lightweight Code Version of the Context Engine
Tutorials15 April 2026Published by Pen & Muse

A Lightweight Code Version of the Context Engine

Back to Dispatches
Part 9 of a 14-part series85 min read · 16,922 words total
Dispatch SeriesPart 9 of 14
The Context Engine

Smarter AI comes from engineered context structure, not more words—fewer degrees of freedom, more reliable decisions.

Series PositionPart 9 of 14
A Lightweight Code Version of the Context Engine
Build a Simple AI Context Sandbox in 20 Minutes (Free Tests, Real Comparisons)

Previous · Part 8

Build a Simple AI Context Sandbox in 20 Minutes (Free Tests, Real Comparisons)

The Cost Advantage: Build Context That’s Cheaper, Faster, and More Consistent

Next · Part 10

The Cost Advantage: Build Context That’s Cheaper, Faster, and More Consistent

This builds on Part 8: Build a Simple AI Context Sandbox in 20 Minutes (Free Tests, Real Comparisons)

Continue with Part 10: The Cost Advantage: Build Context That’s Cheaper, Faster, and More Consistent

At some point, this stops being a concept.

If you’re using this system consistently, you’ll start to notice something:

you’re already doing the same operations over and over.

  • summarising inputs
  • updating context
  • cleaning contradictions
  • running tasks with structured state

This part is about making that explicit.

Not with a full app.

Just enough code logic to show:

this can be systemised without becoming a project.


The two core operations

Everything you’ve done in this series reduces to two actions:

  1. Update context
  2. Run a task with context

That’s it.

So the simplest possible system is just two functions.


1) Updating context (the real engine)

This is your rolling context logic in code form.

function updateContext(oldContext, newData) {
  const summary = summarise(newData)

  const merged = mergeAndClean(oldContext, summary)

  return merged
}

That’s the entire idea.

But what matters is what those inner steps actually do.


summarise(newData)

This is not “shorten text.”

It is:

  • extract goals
  • extract constraints
  • extract decisions
  • extract open questions
  • ignore everything else

mergeAndClean(oldContext, summary)

This is where most people fail.

This function must:

  • overwrite outdated truths
  • preserve still-valid constraints
  • append new decisions (not duplicates)
  • remove contradictions
  • prune low-value noise

Conceptually:

function mergeAndClean(oldContext, summary) {
  return {
    goals: overwrite(oldContext.goals, summary.goals),
    constraints: overwrite(oldContext.constraints, summary.constraints),
    preferences: overwrite(oldContext.preferences, summary.preferences),

    decisions: appendUnique(oldContext.decisions, summary.decisions),

    openLoops: overwrite(oldContext.openLoops, summary.openLoops),

    // optional: prune anything stale or duplicated
  }
}
✦ Subscriber Exclusive

Continue reading with a subscription

Explorer and Immersion subscribers get full access to all premium dispatches, series, and long-form guides.

If this resonates, see how to apply it to your own work with the interactive Dispatch agent.

Be first to like this dispatch

More in TutorialsView all →
Keep Reading, Then Step Inside
Cover of No Gods Left Watching
Book + Immersive Experience£3.99

No Gods Left Watching

Pen & Muse

## No Gods Left Watching The world has not ended — it has simply been left alone. The voices that once bound the mountains have fallen silent. The old pacts are cracking. Whatever was sealed away in the high places is beginning to move again. You are not chosen. You are not prepared. And there is no one left to answer for what happens next. **No Gods Left Watching** is a living, choice-driven experience set at the edge of myth and consequence. You will move through isolation, revelation, refusal, and survival — shaping the path moment by moment as ancient forces stir and the cost of power becomes impossible to ignore. This is not a power fantasy. It is a test of restraint, resolve, and responsibility. Every decision echoes. Every silence carries weight. And when the world finally asks something of you, there will be no gods left to watch — only what you decide to do.

Platform Access

Interested in building narratives using our proprietary architecture? Join the creator waitlist.