Skip to content
PKResources
Course outline

Agentic Engineering: the hands-on course · Module 1: Foundations

How a coding agent works: the loop, tools and the context window

Under the hood, a coding agent is a model in a loop with tools and a limited memory. Understand those three parts and most of its behavior stops being a mystery.

Lesson 2 / 24 · ⏱ 8 min

You don’t need to know how the model is trained to use an agent well. You do need a working mental model of the machine around it, because almost every surprising behavior traces back to one of three parts: the loop, the tools and the context window.

Part 1: the loop

A coding agent repeats the same cycle until it decides the task is done or it runs out of road.

  1. ReadYour request plus everything in context
  2. DecidePick the next action
  3. ActCall a tool: read, edit, run
  4. ObserveTool output goes back into context

↺ Repeat until done, stuck, or stopped

The agent loop. Each turn adds tool results to the context, which shapes the next decision.

The model itself only produces text. The “agent” is the harness that turns some of that text into actions, runs them, and feeds the result back. That’s why a failing test is gold: it’s an observation the agent can react to on the next turn.

Part 2: the tools

Most coding agents come with a similar toolbox, even if the names differ.

Tool family What it lets the agent do What it means for you
Read and search Open files, grep, list directories It explores; it doesn’t magically know your repo
Edit Write or patch files Changes land in your working tree, review them
Run Execute shell commands, tests, builds Your test suite becomes its feedback
Fetch or extra tools Docs, issue trackers, custom scripts Covered in Module 5

An agent without a way to run things is back to guessing. The single biggest upgrade you can give it is a fast, reliable command that says “this works” or “this doesn’t”.

Part 3: the context window

Everything the agent “knows” in a session lives in one finite buffer: your instructions, the files it opened, every command output. When it fills up, something has to give.

Turn 1Turn 8Turn 20full: older details get summarized or droppedyour instructionsfiles readcommand output
A session's context fills turn by turn. Big tool outputs crowd out your original instructions, which is why long sessions drift.

Different agents handle a full window differently: some summarize older turns, some drop them, some just stop. Either way, details from the start of a long session are the first to blur. We go deep on this in Module 2.

Check your mental model

🧠 Loop, tools, context

Score: 0 / 4

  1. 1. The agent fixed a bug, then 'forgot' a constraint you gave it 30 turns ago. The most likely cause?

  2. 2. Why does a failing test help an agent more than a vague 'it doesn't work'?

  3. 3. Where do the agent's code changes go?

  4. 4. What does the model itself produce?

Before you move on

✅ Key takeaways

0 / 4 completed