Skip to content

Commit 66cef75

Browse files
authored
feat(context-engineering): add 9-lesson track, reference sheets, EPUB… (#6)
1 parent 975ecfd commit 66cef75

81 files changed

Lines changed: 9366 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ai-agents-mastery/lessons/0003-how-coding-agents-work.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ <h2>MCP — USB-C for tools</h2>
659659
<details class="iq">
660660
<summary>What is the difference between an MCP Tool, an MCP Resource, and an MCP Prompt?</summary>
661661
<div class="a">
662-
<b>Tool</b> = a function the agent can invoke to take an action or query data (read or write); it has a name, description, and JSON schema, and returns a result. <b>Resource</b> = a URI-addressable data source the agent can read passively — like a file or database row — it is not invoked, just fetched. <b>Prompt</b> = a pre-authored template for a common task the user or agent can invoke to get a structured starting prompt (e.g. "draft a support reply"). Tools are the most commonly used; Resources and Prompts add richness for advanced server-agent integration.
662+
<b>Tool</b> = a function the agent can invoke to take an action or query data (read or write); it has a name, description, and JSON schema, and returns a result. <b>Resource</b> = a URI-addressable, read-only data source (like a file or database row) that the host application chooses to surface to the model — fetched, not invoked. <b>Prompt</b> = a pre-authored template for a common task the user or agent can invoke to get a structured starting prompt (e.g. "draft a support reply"). Tools are the most commonly used; Resources and Prompts add richness for advanced server-agent integration.
663663
</div>
664664
</details>
665665
</section>
@@ -763,7 +763,7 @@ <h2 class="sec" id="interview">Interview questions — Modules 4–6</h2>
763763
<details class="iq">
764764
<summary>What is the difference between an MCP Tool, an MCP Resource, and an MCP Prompt?</summary>
765765
<div class="a">
766-
<b>Tool</b> = a function the agent can invoke to take an action or query data (read or write); it has a name, description, and JSON schema, and returns a result. <b>Resource</b> = a URI-addressable data source the agent can read passively — like a file or database row — it is not invoked, just fetched. <b>Prompt</b> = a pre-authored template for a common task the user or agent can invoke to get a structured starting prompt (e.g. "draft a support reply"). Tools are the most commonly used; Resources and Prompts add richness for advanced server-agent integration.
766+
<b>Tool</b> = a function the agent can invoke to take an action or query data (read or write); it has a name, description, and JSON schema, and returns a result. <b>Resource</b> = a URI-addressable, read-only data source (like a file or database row) that the host application chooses to surface to the model — fetched, not invoked. <b>Prompt</b> = a pre-authored template for a common task the user or agent can invoke to get a structured starting prompt (e.g. "draft a support reply"). Tools are the most commonly used; Resources and Prompts add richness for advanced server-agent integration.
767767
</div>
768768
</details>
769769

ai-agents-mastery/reference/agents-cheat-sheet.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ <h2>Definitions (compressed)</h2>
9292
<div>
9393
<h2>Mental models</h2>
9494
<pre class="dgm">LLM = Brain (no memory, no hands)
95-
Tool = Capability / hands
96-
Agent = Brain + Capabilities + Loop + Goal
95+
Tool = Hands / a callable function
96+
Agent = Brain + Tools + Loop + Goal
9797
Runtime = App server that runs the loop + rules
9898
Memory = What runtime reloads (RAM vs disk)
9999
Workflow = Developer chooses the path

assets/tokens.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
--track-transactions:#8a3fbf;
2929
--track-streaming:#d6455d;
3030
--track-applied:#0e7c98;
31+
--track-context:#b5179e;
3132

3233
/* fallback accent — a page overrides this to its own track token */
3334
--accent:#5b54e6;
@@ -60,6 +61,7 @@ html[data-theme="dark"]{
6061
--track-transactions:#c69ad6;
6162
--track-streaming:#ef8aa0;
6263
--track-applied:#5fb6cf;
64+
--track-context:#e879cf;
6365

6466
--accent:#9a93ff;
6567
}

context-engineering/GLOSSARY.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Glossary — Context Engineering
2+
3+
Covers Lessons 1–9. Grouped by where each term first lands.
4+
5+
## Foundations (L1–2)
6+
- **LLM (large language model)** — the reasoning model itself: the brain. Fixed weights, no memory
7+
between calls, no access to your data except what you place in its context window for that call.
8+
- **Context** — everything the model can see for a single call: system prompt + instructions +
9+
conversation history + retrieved data + tool definitions/results + the user's query. The model's
10+
*entire* world for that one inference. It has no other access to your data.
11+
- **Context window** — the model's fixed maximum number of tokens per call (input + output). A hard
12+
ceiling, like total RAM. Exceed it and content must be dropped, truncated, or summarized.
13+
- **Token** — the unit the model counts in. A sub-word chunk (~4 chars / ~0.75 words of English on
14+
average). Limits, latency, and cost are all measured in tokens, not characters or lines.
15+
- **Working context** — the curated subset actually assembled into the window for *this* turn: the
16+
few things relevant right now, not everything that exists. The output of context engineering.
17+
- **Context engineering** — selecting, retrieving, compressing, and assembling the window before the
18+
model runs. Decide what to put in the window (and what to leave out) so a fixed model produces the
19+
best answer it can.
20+
- **Context assembly** — the step that packs selected/retrieved content (plus prompt, history,
21+
tools) into the final window, within budget, in an order the model uses well.
22+
- **Context-as-query** — the mental model: in classic software the query (SQL) fetches from the DB;
23+
in AI the context-retrieval pipeline fetches what the LLM reasons over. The "query" moved from
24+
SQL into context assembly.
25+
- **Retrieval quality vs model quality** — past a baseline, *what you feed* the model usually moves
26+
answer quality more than *which model* you use. Right context + smaller model often beats wrong
27+
context + best model.
28+
29+
## Selection & retrieval (L2)
30+
- **Selection** — choosing the smallest set of content that still contains the answer, within the
31+
token budget. Candidate generation → ranking → packing.
32+
- **Lexical / keyword search (BM25)** — exact-term matching with TF-IDF/BM25 scoring. Precise on
33+
identifiers and exact terms; blind to synonyms (vocabulary mismatch).
34+
- **Semantic / vector search** — encode query and chunks as embeddings, retrieve by similarity.
35+
Captures meaning and paraphrase; can return "topically similar but wrong"; weak on rare exact tokens.
36+
- **Hybrid search** — run lexical + semantic and fuse results (e.g. Reciprocal Rank Fusion). Covers
37+
exact *and* semantic; more infra to tune.
38+
- **Ranking** — ordering candidates by a cheap score; first stage optimizes **recall** (don't miss it).
39+
- **Re-ranking** — a second, expensive, accurate stage (e.g. a cross-encoder) that re-scores the
40+
top-N jointly with the query; optimizes **precision**. Can't recover a doc the first stage missed.
41+
42+
## Codebase, chunking & RAG (L3)
43+
- **Repository indexing** — building a searchable representation of a codebase (embeddings and/or a
44+
symbol/dependency index) so relevant code can be retrieved.
45+
- **Read-on-demand (agentic) context** — fetching files live via tools (grep/glob/read) instead of a
46+
persistent embedding index. Always fresh; costs tool round-trips. (Claude Code's model.)
47+
- **Chunking** — splitting documents into retrievable units. Chunk on meaning/structure, not raw
48+
character count.
49+
- **Overlap** — sharing boundary text between chunks so a fact spanning a boundary survives.
50+
- **Context fragmentation** — a fact split across chunks so no single chunk is complete/retrievable.
51+
- **Contextual chunking/retrieval** — prepend a short doc/section-situating summary to each chunk
52+
before embedding (and index BM25 too) to cut retrieval failures.
53+
- **RAG (Retrieval-Augmented Generation)** — retrieve → assemble → LLM → answer. Grounds the model
54+
in your private or current data; only as good as its retrieval.
55+
56+
## Memory, compression & failure modes (L4)
57+
- **Memory** — persisted state (derived facts, decisions) about an ongoing task or relationship.
58+
Reachable only by retrieving it back into context — the model never reads it directly.
59+
- **Knowledge base** — the corpus of source documents/facts; usually read-only reference material.
60+
- **Compression** — fitting more useful signal into the budget via **summarization** (condense),
61+
**distillation** (extract salient facts), pruning redundancy, and **sliding windows** (recent
62+
verbatim + rolling summary). Lossy — keep recent turns and decisions verbatim.
63+
- **The 5 failure modes****missing** (never retrieved), **wrong** (irrelevant retrieved),
64+
**outdated** (stale index), **conflicting** (sources disagree), **excessive** (too much → noise /
65+
lost-in-the-middle). Diagnose by symptom → cause → fix.
66+
67+
## Evaluation & observability (L6)
68+
- **recall@k** — is at least one relevant doc in the top-k. The most important RAG retrieval metric;
69+
nothing downstream can use what wasn't retrieved.
70+
- **precision@k** — fraction of the top-k that are relevant.
71+
- **MRR (mean reciprocal rank)** — how high the first relevant result sits.
72+
- **nDCG** — graded, position-discounted relevance; rewards putting the best at the top.
73+
- **Faithfulness / groundedness** — is every claim in the answer supported by the retrieved context
74+
(detects hallucination).
75+
- **Context precision / recall** — are retrieved chunks relevant and well-ranked (precision); did
76+
retrieval capture everything the ideal answer needs (recall, needs ground truth). RAGAS vocabulary.
77+
- **Golden set** — a versioned eval set of (query, relevant doc IDs, ideal answer) for offline
78+
regression testing.
79+
- **Offline vs online eval** — offline = regression on the golden set before deploy; online =
80+
production signals (thumbs, deflection/escalation, citation-clicks, rephrase rate).
81+
- **LLM-as-judge** — using an LLM to score faithfulness/relevance at scale (needs calibration).
82+
83+
## Pre-retrieval & advanced RAG (L7)
84+
- **Query rewriting** — clean/expand/disambiguate the raw query before retrieval.
85+
- **Multi-query** — generate several paraphrases, retrieve for each, union the results (boosts recall).
86+
- **HyDE (Hypothetical Document Embeddings)** — embed a generated hypothetical *answer* (not the
87+
question) to bridge the query↔document vocabulary gap.
88+
- **Query decomposition** — split a complex question into sub-queries, retrieve each, combine.
89+
- **Step-back prompting** — ask a broader question first to pull grounding, then the specific one.
90+
- **Routing** — classify the query and send it to the right index/datasource/tool.
91+
- **Parent-document / small-to-big** — match small precise chunks but return the larger parent for context.
92+
- **GraphRAG** — retrieve over an entity/knowledge graph (subgraphs + community summaries); wins on
93+
global "connect-the-dots across the corpus" questions.
94+
- **Agentic RAG** — the LLM decides whether/what/when to retrieve, iterating in a loop.
95+
- **Self-RAG / Corrective RAG (CRAG)** — the model critiques its own retrieval/answer; CRAG grades
96+
retrieved docs and falls back (e.g. web search) when quality is low.
97+
98+
## Embeddings, indexing & cost (L8)
99+
- **Embedding** — a dense vector capturing meaning; near vectors ≈ similar meaning.
100+
- **Similarity metric** — cosine (most common), dot product, or Euclidean distance over embeddings.
101+
- **ANN (approximate nearest neighbor)** — trade a little recall for large speed at scale; exact
102+
k-NN is O(n) per query.
103+
- **HNSW / IVF / PQ** — vector index families: graph-based (fast, high recall, memory-heavy) /
104+
clustering (probe a few cells) / product quantization (compress vectors, lower recall). The
105+
recall ↔ latency ↔ memory trade-off.
106+
- **Metadata filtering** — pre/post-filtering candidates by attributes (date, type, tenant); also an
107+
access-control hook.
108+
- **Index freshness / invalidation** — keeping the index current (incremental updates, CDC,
109+
re-embedding on model change); a stale index *is* the "outdated context" failure mode.
110+
111+
## Caching, ordering & security (L9)
112+
- **Prompt / KV caching** — reusing the processed state of a stable prefix across calls to cut cost
113+
and latency. Put stable content (system prompt, tools) first, volatile content (query, retrieved
114+
docs) last; any change busts the cache from that point on.
115+
- **Lost in the middle** — models attend most to the start (primacy) and end (recency) of the
116+
window, weakest in the middle. Order matters: put the query last and the best doc at an edge.
117+
- **Indirect prompt injection** — a malicious instruction hidden in *retrieved* content that the
118+
model may obey. Treat all retrieved content as untrusted data, never as instructions.
119+
- **Multi-tenant access control** — enforce row/document-level permissions in the *retrieval query*
120+
(scope by tenant/ACL before anything reaches the model). Never rely on the prompt to enforce access.

context-engineering/MISSION.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Mission: Context Engineering from First Principles
2+
3+
## Why
4+
As a Senior Lead / VP Engineering I evaluate, buy, and build AI products. The single question I
5+
must be able to answer cold is: **why does one AI system appear dramatically smarter than another
6+
even when both use the same LLM?** The answer is almost never the model — it's context
7+
engineering: what gets selected, retrieved, compressed, and assembled into the window before the
8+
model ever runs. I want durable mental models for why Cursor, Claude Code, RAG systems, and modern
9+
AI products succeed or fail — not a vocabulary of buzzwords.
10+
11+
## Success looks like
12+
- I can explain, on a whiteboard, why the model is the *fixed* part and context assembly is where
13+
all the engineering value (and most of the failure) lives.
14+
- I can frame context as the new database query: retrieval quality usually dominates model quality.
15+
- For any AI product I can name its context strategy (pre-indexed embeddings vs read-on-demand vs
16+
hybrid) and the trade-off it bought.
17+
- I can diagnose a failing AI feature by failure mode: missing / wrong / outdated / conflicting /
18+
excessive context — and know the fix for each.
19+
- I can design the context system for a billing, support, engineering, or research agent and reason
20+
about its scalability, cost, reliability, and observability.
21+
22+
## Constraints
23+
- Engineering analogies first (databases, query planners, caches, indexes, RAM/disk, distributed
24+
systems). Academic framing only when unavoidable.
25+
- Visual-first: hero diagram + SVG/ASCII visuals + comparison tables + definition cards. Prose only
26+
as captions. 60–70% of each lesson is visual.
27+
- Per-concept template every time: simple explanation · deep explanation · engineering analogy ·
28+
common misconceptions · one-sentence memory rule.
29+
- Every lesson ends in retrieval practice + interview questions (click-to-reveal).
30+
- Optimize for long-term retention over completeness.
31+
32+
## Out of scope (for now)
33+
- Embedding model training, transformer internals, fine-tuning.
34+
- Vendor-specific API tutorials (LangChain/LlamaIndex call signatures).
35+
- Token-level cost optimization math beyond the budgeting mental model.
36+
37+
## Sibling track
38+
- Builds directly on `../ai-agents-mastery` (runtime, context window, memory tiers). Context
39+
Engineering is the deep-dive on the "context" layer that track introduced.

0 commit comments

Comments
 (0)