Agent systems and standards · Chapter 6 of 8
Context engineering and retrieval
Choosing what each model call reads: grep or vector search, offloading large results, a first look at subagents, and memory that lasts across threads.
Goals
- Run grep and vector search for the same words and compare.To do
- Let a large tool result be offloaded instead of filling the context.To do
- Hand a search to subagents and compare the context sizes.To do
- Pass the check.To do
Step 1 of 4: The read
What each call reads
A model call reads its context: the system prompt, the messages so far, and every tool result. Context engineering is deciding what goes in. Too little and the agent guesses; too much and it costs more, runs slower and gets distracted by text that does not matter, or that was planted.
grep or vectors
grep finds exact text, line by line: an order number, a ticket id, a date. It costs nothing and misses anything worded differently.
Vector search finds similar meaning. Each chunk of each file is turned into a vector (here, 384 numbers from the all-MiniLM-L6-v2 embedding model), and chunks are ranked by cosine similarity to the query's vector. It finds "payment taken two times" for "charged twice", but for 48213 it ranks tickets about orders 48144 and 48231 ahead of the right one. Filters such as a folder or a date keep stale or unrelated chunks out.
Offload, skills and subagents
A tool can return far more than a context can hold. Eviction saves a large result to a file and gives the model the path and a short preview; the agent then greps the file and reads only the lines it needs.
Skills follow the same idea: the agent sees each skill's name and a one-line description, and reads its full instructions (a SKILL.md file) only when a task needs them.
A subagent gets a fresh context with only its task and returns one report, so its reading stays out of the main context. Advanced agents, chapters 9 and 10, cover subagents, thresholds and compaction in depth.
Memory across threads
A thread is one conversation: its checkpointer keeps that thread's messages, and a new thread starts empty. Long-term memory is a store that every thread shares. LangGraph's InMemoryStore keeps items under a namespace, such as customers / mara-lind; one thread puts a note there, and a later thread searches for it. In production the store is a database.
In this lab
Halden's support agent works ticket T-48213. Its harness re-creates Deep Agents (a LangChain open-source harness) on LangGraph.js: filesystem tools, eviction over 20,000 tokens, and task subagents. The memory step uses LangGraph.js's own InMemoryStore.
Step 2 of 4: Try it: What the agent reads
What the agent reads
Search for the same words with grep and with vectors, let the payments export be offloaded, hand the reading to subagents, then save a note that a later thread reads back.
Mode:RealRe-createdSimulatedReal: grep, LangChain.js's text splitter and MemoryVectorStore with the shipped all-MiniLM-L6-v2 vectors, and LangGraph.js with its InMemoryStore and MemorySaver run in this page. Re-created: the deepagents 1.16 harness rebuilt on LangGraph.js 1.5.1, with its tool names, defaults and messages, because the real package does not install next to this site's LangSmith 0.11. Simulated: the model follows a script, and the documents are fictional.
Step 3 of 4: Check
Check
Next: Question 2 of 4
Step 4 of 4: What you can do now
What you can do now
- Choose between grep and vector search for a query, and say when a folder or date filter helps.
- Offload large tool results and page through them.
- Use subagents to keep a main agent's context small and clean.
- Save a note in a long-term store and read it back in a later thread.