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 Blood and Roses
Book + Immersive Experience£7.99

Blood and Roses

Pen & Muse

In the decaying court of King Henry VI, ambition and anxiety fester in the shadows, as courtiers whisper of the king's failing health and grip on power. Amidst the heavy grandeur and unspoken tensions, a single white rose is discovered – a dying symbol of the House of York, an omen of the kingdom's sickness. Meanwhile, across the land, Richard, Duke of York, sharpens his own ambitions, viewing power as a falcon's eye, capable of seeing weakness and striking with precision. Queen Margaret of Anjou, a formidable force in a world of men, recognizes the threats posed by York and the grasping nobles like Somerset. As alliances shift and loyalties fray, she faces the brutal reality of a kingdom on the brink, where she must become a creature of cunning and strength to protect her son's inheritance, even if it means staining the Lancastrian rose with blood.

Platform Access

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