Practised 0 / 16Next →
15 / 16 · MODULE 04 · WORKFLOW, SKILL & SUB-AGENT ISOLATION

Workflows, Skills, and Sub-agents: context isolation engineering

If we already have Agents and MCP, why did engineers invent Workflows, Skills (SKILL.md), and Sub-agents?

TAKE AWAYSwitch across 4 orchestration patterns in the sandbox to compare main-window token consumption (48.5K vs 2.8K) and flexibility

When developers attach 50 MCP tools and massive rulebooks to an Agent, disaster strikes: tool schemas alone eat tens of thousands of tokens before work even starts, and 15 turns of search/debug logs flood the main context window—causing sky-high costs and degraded reasoning.

Three patterns tame context bloat: 1) Workflow: lock deterministic steps into fixed code scripts; 2) Skill (SKILL.md): keep only a 1-line index in the main prompt and lazy-load detailed instructions/scripts only when triggered; 3) Sub-agent: delegate noisy 20-turn search/debug subtasks to an isolated child context that returns only a clean 200-word summary!

DIAGRAM · CONTEXT ENGINEERING FOUR DEFENSES

Attention sums to 100%: prune noise, sandbox untrusted data, compact logs, and enforce JSON schemas

Upgrade from ad-hoc prompt tweaking to rigorous signal-to-noise engineering over the context window.

DEFENSE 1 · MAXIMIZE SNRFilter Low-Score RAG Chunks & Compact Verbose Tool LogsEvery irrelevant token dilutes Softmax attention away from critical constraints.→DEFENSE 2 · INJECTION SANDBOXINGWrap Untrusted Documents in Data Tags and Enforce Privilege HierarchyPrevents indirect prompt injection hidden inside retrieved web pages or files.→DEFENSE 3 · CONSTRAINED DECODINGMask Invalid Grammar Tokens at Sampling Time for 100% Valid JSONGuarantees machine-parsable payloads without brittle regex post-processing.
DEFENSE 1 · MAXIMIZE SNR

Filter Low-Score RAG Chunks & Compact Verbose Tool Logs

Every irrelevant token dilutes Softmax attention away from critical constraints.

DEFENSE 2 · INJECTION SANDBOXING

Wrap Untrusted Documents in Data Tags and Enforce Privilege Hierarchy

Prevents indirect prompt injection hidden inside retrieved web pages or files.

DEFENSE 3 · CONSTRAINED DECODING

Mask Invalid Grammar Tokens at Sampling Time for 100% Valid JSON

Guarantees machine-parsable payloads without brittle regex post-processing.

First-principles breakdown: three steps
  1. Deterministic Steps → Lock into Workflows

    Never pay an LLM to improvise a fixed pipeline; lock deterministic file parsing and formatting into scripts.

  2. Long Domain Rules → Package as Lazy-Loaded Skills

    Instead of stuffing every SOP into the system prompt, let the Agent read the relevant SKILL.md and helper scripts only when needed.

  3. Noisy Multi-Turn Exploration → Isolate in Sub-agents

    A Sub-agent runs file searches and retries in its own disposable context window, returning only the distilled answer to the parent.

Switch between [Monolith All-In], [Fixed Workflow], [On-Demand Skill], and [Isolated Sub-agent] in the sandbox to compare main context token watermarks and adaptability.

TRY IT YOURSELF · LIVE CODE SANDBOXLIVE CALCULATION
Main Context Tokens4,200
Window Utilization9%
Dynamic Format Adaptability✓ Adaptive
Main context holds only a tiny skill index; reads SKILL.md and scripts on demand when triggered.

Compare all 4 patterns: Skills lazy-load instructions on demand, while Sub-agents isolate noisy multi-turn tool logs in a separate context.

JARGON BUSTER · STRIP AWAY THE HYPE

Workflow vs. Autonomous Agent

In a Workflow, code dictates the step order; in an Agent, the model loops and decides which tool to call next.

If a task follows a fixed recipe, use a deterministic Workflow rather than an unconstrained Agent.

Agent Skill (SKILL.md)

A folder holding domain instructions (SKILL.md) and scripts that the Agent reads on demand instead of bloating every prompt.

Stripped of hype, a Skill is simply lazy-loaded modular prompting plus helper scripts.

Sub-agent & Agent Harness

Sub-agents are disposable workers for context isolation; the Harness is the outer runtime managing loops, permissions, and retries.

Clean context isolation and a rock-solid harness are the real secrets behind top coding agents.
ONE IDEA TO KEEP

Workflows hardcode deterministic steps; Skills lazy-load instructions on demand; Sub-agents isolate noisy multi-turn work from the main context.

CHECK YOUR UNDERSTANDING

When a parent Agent delegates “search 30 files to locate a function definition” to a Sub-agent, what is the primary architectural benefit?

When a parent Agent delegates “search 30 files to locate a function definition” to a Sub-agent, what is the primary architectural benefit?
REFERENCES & FURTHER LEARNING

Explanations, cases, and exercises are authored by Reallier. Links provide further learning. The workplace activity and people are fictional.