Skip to main content
Kliff

Agents

How an agent is a model calling tools in a loop, and what that means for how you guide one.

Video coming soon

An agent is not a different kind of model. It is a model given tools and run in a loop, so it can take a step, see what happened, and decide the next step on its own. This lesson puts the earlier ideas together and shows what to expect when you hand a task to an agent instead of asking a chat a question.

The loop

At its core, an agent repeats four steps:

  1. The model reads the context: instructions, your request, and everything that has happened so far.
  2. It either answers or asks for a tool call.
  3. The application runs the tool and adds the result to the context.
  4. Back to step 1, until the model gives a final answer or something stops it.

In code, the shape is small:

An agent loop, simplifiedts
let context = [instructions, request];

while (true) {
  const reply = await model(context, tools);

  if (reply.kind === 'answer') {
    return reply.text;
  }

  const result = await runTool(reply.toolCall);
  context = [...context, reply, result];
}

Real agents add a lot around this: permission checks, limits on time or spending, ways to compact a context that grows too large, and ways to stop. But the loop is the engine.

What one task looks like

Say you ask an agent to fix a failing test. A run might go like this:

One task, step by steptext
Read      tests/date.test.ts          sees the failing case
Run       npm test -- date            confirms the failure
Read      src/date.ts                 finds the formatting function
Edit      src/date.ts                 changes the timezone handling
Run       npm test -- date            the test passes
Run       npm test                    the full suite passes
Answer    explains the cause and the change

Each line is one trip around the loop. The model did not plan all seven steps up front. It chose each one after seeing the last result. That is the agent's strength: it can react to what it finds, such as a test that fails for a different reason than expected.

Why the loop needs feedback

An agent is only as good as the signals it gets back. A model that edits code and never runs it is guessing that the edit works. A model that runs the tests can see that it does not, and try again.

So the best tasks for an agent have a clear way to check the result:

  • A test that fails now and should pass after.
  • A command that reproduces the bug.
  • A type check, linter, or build that must stay clean.
  • An app it can start and look at.

When there is no such check, ask the agent to create one first. "Write a failing test that shows the bug, then fix it" gives the loop something real to aim at.

Your role: set direction, check results

Agents make it easy to hand off a lot of work, and just as easy to accept work you have not checked. A few habits keep you in control:

  • Ask for a plan first on anything large or unclear. Reading a plan is much cheaper than unwinding a wrong approach.
  • Keep tasks scoped. One clear outcome per task is easier for the agent to finish and for you to review.
  • Watch for drift. If the agent starts changing things you did not ask about, stop it and restate the goal.
  • Review the change, not the summary. The agent's description of what it did is helpful, but the diff and the test results are the record.
  • Approve risky steps on purpose. When an agent asks before pushing, deleting, or calling an outside service, read the request.

Key points

  • An agent is a model calling tools in a loop: read, act, observe, repeat.
  • It chooses each step after seeing the last result, which lets it adapt to what it finds.
  • The loop works best with a clear check, such as a failing test or a reproduction.
  • Your job is to set the goal, ask for plans on bigger work, and verify the result yourself.