Module 3: Context engineering

Back to the course | Previous: The loop, part 2 | Next: Harness engineering

One important thing to understand is that a model will only ever know what you send it. Every time. Nothing else. Just what you send.

It doesn't know about your project, it doesn't know about conventions, or about what happened five minutes ago, unless... You guessed it. You send it with the text. So the question "why did the agent do that?" is almost always answered by the same thing. Go and look at what it got!

That is context engineering. Deciding what goes in, what does not, and what gets thrown away. It's the only thing you can influence per call. So let's make sure you understand how it works.

Read

Factor 3, "Own your context window", in 12-Factor Agents.

Build

  1. Log every request, in full. One file, one request per line, with everything: system prompt, messages, tool definitions and results! No summary! You need to be exact here.
  2. Count tokens per turn. The API will tell you how many went in and out, and you need to keep a correct tally.
  3. Load an instructions file. If there is an AGENTS.md in the working directory, put its contents into the system prompt. This is how every commercial coding agent learns about a project. And now you do too.
  4. Read a log end to end. Really read it. This is the actual exercise.

Done when

You can open the log and point to every piece of text the model saw on a given turn.

Discuss

What surprised you when you read exactly what your agent sent to the model? Is it exciting, boring, surprising, horrifying, all of the above?

Extras

Optional reading