Addaly is in open beta. Things will change, and AI answers can be wrong — check anything that matters.

Plan, act, observe, repeat

Agents and Automation · lesson 3 of 8 · 7 min

The whole thing is about twelve lines

Strip away the frameworks and an agent is this:

python
messages = [{"role": "user", "content": task}]

for step in range(MAX_STEPS):
    reply = model(messages, tools=TOOLS)      # plan
    messages.append(reply)

    if not reply.tool_calls:                  # it thinks it is done
        return reply.text

    for call in reply.tool_calls:             # act
        result = execute(call)                # your code, not the model's
        messages.append(tool_result(call.id, result))   # observe

raise BudgetExceeded(step, messages)

That is it. LangGraph, CrewAI, the Agents SDK, whatever you use next year — they all wrap this. Worth writing once by hand, because everything that goes wrong later goes wrong inside these lines.

Notice what is *not* there. There is no memory. There is no plan stored anywhere. When the model writes "first I'll check the database, then I'll email the customer," that plan is not state — it is a sentence in the transcript, with no more force than any other sentence. If it is not in messages, it does not exist.

The observe step is the whole engineering problem

Plan and act are handled for you. Observe is where you make every meaningful decision, and it is the step people paste in without thinking.

Suppose a tool fetches a supplier page. The raw response is 190 KB of HTML: navigation, cookie banner, a footer in three languages, and one table with the price you wanted. Append that verbatim and you have done three bad things at once. You spent about 50,000 tokens. You buried the price under noise. And you did it again on the next call, and the one after, because the transcript keeps growing.

Good observations are:

  • Small. Extract the table. Strip the chrome.
  • Informative on failure. No price found on this page; the page returned a 404 body is worth twenty times ''.
  • Honestly truncated. If you cut, say so: [first 40 of 812 rows shown]. A silent truncation makes the model confidently reason about data it never saw.

Cost does not grow linearly

Every turn re-sends the whole transcript. A task with a 2,000-token brief and 1,500-token observations is sending about 3,500 tokens on step one and about 25,000 on step fifteen. Total spend across a run grows roughly with the square of the step count, not with the step count.

So the two levers on an agent's bill are the same two levers on its quality: fewer steps, smaller observations.

The quiet failure this causes

Here is the pattern you will meet. An agent runs beautifully for four or five steps, then starts repeating searches it already ran and contradicting facts it established earlier. The instinct is to say it "forgot." Usually nothing was dropped at all — the context window is not even full. The earlier findings are still sitting there, three thousand tokens down, under two full web pages the loop appended without trimming.

Degradation starts long before hard truncation does. What you feed back in step three determines whether step nine works.

The fix is unglamorous and it works: summarise as you go. After each tool result, write a one-line note of what was learned, and keep the notes near the end of the transcript where they stay salient. Some teams keep a running scratchpad the agent rewrites each turn. Either way, you are doing the same thing — deciding what is worth carrying forward, instead of carrying everything.

Before you move on

A research agent works well for five steps, then begins re-running searches it already ran and contradicting findings from step two. Token counts show the context window is about 40% full. What is the best explanation?

Pick the one you would defend. Nobody sees your answer.

No ads. No data sale. No public scores on people. Ever.

© 2026 Addaly