Understand deeply, then use frameworks wisely.
Context engineering decides what a model sees for one specific call. Not just the user's message - everything around it.
context engineering
This repo teaches that idea through 14 small, runnable examples. Each one shows exactly one piece of context and how it changes the model's answer. No frameworks, no production platform hiding behind the lessons - just Node.js and one local model, running on your machine.
mental model
The examples build this diagram one box at a time, then assemble it.
- Node.js 22+ (uses the built-in
node:sqlitemodule in example 12) - Basic JavaScript
- min ~8-16 GB of RAM and ~3 GB of disk for the local GGUF models
- No prior LLM experience, no API keys, no hosted services
git clone https://github.com/your-fork/context-engineering-from-scratch
cd context-engineering-from-scratch
npm install
npm run download-model # Qwen3.5 4B + BGE embeddings
npm run example -- 00Every example is self-contained. Run any of them directly:
npm run example -- 04
node examples/04_long_term_memory/example.js # equivalentExamples 12-13 also save a context trace you can reopen afterward:
npm run context # shows the most recent trace
npm run context -- --id <id> # shows a specific onecontext-engineering-from-scratch/
├── README.md
├── DOWNLOAD.md
├── package.json
├── examples/ 14 examples, 00-13
│ └── NN_topic/
│ ├── example.js the runnable lesson (never over 150 lines)
│ ├── CONCEPT.md the mental model - what this is, and isn't
│ └── CODE.md what gets sent to the model, and why
├── helper/ shared code: model, CLI output, tokens, traces
├── scripts/ npm run example / context / download-model
├── data/traces/ saved context traces (examples 12-13)
└── models/ your local GGUF model goes here
There is no parallel src/ production application. What you read in an
example is the whole idea - not a simplified preview of something
bigger hiding elsewhere.
| # | Example | Docs | What it makes visible |
|---|---|---|---|
| 00 | What Is Context Engineering? | concept · code | Same question, different context, different answer |
| # | Example | Docs | What it makes visible |
|---|---|---|---|
| 01 | System Instructions | concept · code | Instructions shape behavior, not knowledge |
| 02 | Tool Definitions | concept · code | A tool definition steers the decision to act |
| 03 | Few-Shot Examples | concept · code | Examples demonstrate behavior; instructions describe it |
| # | Example | Docs | What it makes visible |
|---|---|---|---|
| 04 | Long-Term Memory | concept · code | Memory lives outside the model until it's retrieved |
| 05 | External Knowledge with RAG | concept · code | Retrieval adds grounded facts the model didn't have |
| 06 | Tool Outputs | concept · code | A tool's result becomes knowledge, not just a decision |
| 07 | Sub-Agent Outputs | concept · code | A sub-agent's report becomes context for the next call |
| 08 | Artifacts | concept · code | A file only helps once something reads it |
| # | Example | Docs | What it makes visible |
|---|---|---|---|
| 09 | Conversation History | concept · code | History resolves what "it" or "which" refers to |
| 10 | State | concept · code | Structured state beats a wall of transcript |
| 11 | User Prompt | concept · code | The prompt decides which knowledge matters now |
| # | Example | Docs | What it makes visible |
|---|---|---|---|
| 12 | Context Orchestrator | concept · code | Question retrieves and scores; orchestrator packs what fits |
| 13 | Context Trace | concept · code | Inspect the context that produced an answer, not just the answer |
- Not a production memory system, vector database, or RAG pipeline
- Not a multi-agent orchestration framework
- Not an evaluation or benchmarking platform
- Not a scoring/ranking algorithm you should copy into production
Every example's CONCEPT.md ends with a Beyond this example
note that sketches the production gap that example deliberately does
not solve - what the toy mechanism is, what replaces it, and what
adjacent concerns remain out of scope. Retrieval, memory, and
multi-agent systems each deserve their own specialized resource -
this one exists to build the mental model first.
MIT - see LICENSE.
If this repo was useful and you have a project that needs ai workflows, context engineering, RAG, or local/production LLM work done properly, I'm open to freelance or contract engagements.
- Email: pguso@gmx.de
- LinkedIn: https://www.linkedin.com/in/patric-gutersohn-466046167/
No pressure either way - glad if the repo was useful on its own.
