Writing Engineering & games

Why agents forget, and how to make them not

Give an agent a job with five steps and pull the plug during the third. What it does when the power comes back has almost nothing to do with how capable the model is. It depends on one decision somebody made before the first step ran: where the goal was kept.

OCTAVIA, the voice assistant I have been building, went public this week. One of the things it can now do is hold a multi-step goal across sessions and restarts without being reminded. There is no trick in the model that does this. It is about 2,600 lines of bookkeeping, and the interesting part is what the bookkeeping refuses to write down.

Before the argument, the thing itself. Both sides below are handed the same goal. Let it run, or press Cut the power whenever you like.

Forgetting is a storage decision

A language model keeps nothing between calls. Everything an agent appears to know about its task, the goal, the plan, which steps are finished, what went wrong on the last try, is text in the conversation that gets sent back to the model on every turn. That text is the agent's entire working memory, and it lives in the memory of one process.

So the plainest possible agent keeps its goal in the most fragile place available. A conversation ends in at least three ways, and only one of them is a failure:

  • The process stops. A crash, a reboot, an update, a closed laptop.
  • The context fills up. Long work produces a lot of text. When the window is full something has to be dropped or summarised, and a summary of a plan is not the plan.
  • It is ended on purpose. OCTAVIA's own conversation does this by design. Its configuration has session_timeout_s: 300, commented “after this much silence, the next conversation starts with a fresh context”, and a token ceiling past which it starts afresh between turns, keeping only the thread. For a voice assistant that is the right behaviour. Nobody wants this morning's small talk dragged into tonight's question.

Put those together and a conversation is a thing built to be thrown away. Keeping an hours-long goal in it is like keeping the only copy of a document in the clipboard.

The usual objection is that the work is not lost, because the files the agent edited are still on disk. That is true and it is the cruel part. Look at the left lane after a cut: the edits are there. What is gone is everything that made them a plan. Which of them were finished. Which one was half-written when the power went. What the fourth step was going to be. Whether any of it works. A new conversation opening that folder sees some changed files and no reason for them.

Write the goal down before doing anything

OCTAVIA calls a goal it has been handed an objective, and the first thing it does with one is write it to a file. This is the record, trimmed to the fields that matter here:

@dataclass
class Step:
    id: int
    title: str
    kind: str
    instruction: str
    acceptance: str       # how to tell it worked: what the reviewer checks
    depends_on: list[int] = field(default_factory=list)
    status: str = PENDING
    attempts: int = 0
    interruptions: int = 0
    result: str = ""      # its agent's own account (attempted, not verified)
    evidence: str = ""    # what the checks found
    problem: str = ""     # why it failed or was skipped
    commit: str | None = None  # a code step's verified commit on the objective's branch
    feedback: str = ""    # what was wrong with its last attempt, for the next one (kept over a restart)

@dataclass
class Objective:
    id: int
    goal: str             # what the user asked, in their words
    status: str = PLANNING
    steps: list[Step] = field(default_factory=list)
    branch: str | None = None  # code steps' branch in the project
    base: str | None = None  # the commit the branch started from

Every objective lives in one file, data/objectives/objectives.json, and the file is rewritten at every change of state: when a plan is accepted, when an attempt starts, when a check begins, when a step is verified. The write goes to a temporary file that is then renamed over the old one, so what is on disk is always either the previous state or the next one and never half of each.

Two details in that record do more work than they look like they do. The goal is stored in the person's own words, not a paraphrase, so nothing downstream is working from an agent's summary of what it thinks was asked. And every step carries its own acceptance: a sentence, written at planning time, saying how somebody who did not do the work can tell it is done. I will come back to that one.

The conversation still needs to know the objective exists, since it is the thing I talk to. It is told the same way everything else is: one line is built from the file and placed in its system prompt, of the form Objectives: 1 under way (#1 Inventory for the game). A conversation that began five minutes ago with an empty context knows what is in flight, because it never had to remember. It reads.

Every step starts from nothing, on purpose

Persisting the goal is the obvious half. The less obvious half is that in this design no session ever holds the whole job.

A read-only planning session looks at the project and writes at most eight steps, then ends. Each step is then given to a brand-new session that has never seen the planner's conversation or any other step's. It is handed four things and nothing else: the goal in the person's words, its own instruction, its own acceptance criteria, and the verified results of the earlier steps it builds on, each cut to 4,000 characters. The planner is told this in so many words:

Each instruction must stand alone: the agent sees only it, the objective, and the results of the steps it depends on.

Watch the top right corner of the file lane in the figure. The label keeps changing: planner session, coder session, project's check, reviewer session, coder session again. A five-step objective that goes perfectly uses eleven separate sessions, and each one forgets everything when it closes.

That is the whole idea. A long-running agent sounds like one that remembers for a long time. This one forgets constantly, at every step boundary, and it does not matter, because nothing it needs was ever kept in a session. A power cut stops being a disaster to recover from. It is one more session ending, and sessions end all day.

None of this is new outside of agents. Databases have recovered by replaying a log up to the last commit for decades, and there is a 2003 paper arguing that a program should have no shutdown path at all, only crashing and recovering, because the recovery path is then the one that gets exercised. The agent version of that argument is that a conversation should be treated as a cache.

It costs something. The planner has to write instructions good enough to be followed by someone who cannot ask a question, which is harder than keeping a vague plan in your head. And every boundary is paid for in tokens: a fresh session has to read the project again before it can touch it.

What a restart actually does

When OCTAVIA starts, the runner reads the file and calls this. It is short enough to quote nearly whole:

def resume(self) -> None:
    for objective in self.store.objectives:
        if not objective.open:
            continue
        for step in objective.steps:
            if step.status not in (RUNNING, CHECKING):
                continue
            step.interruptions += 1
            step.attempts = max(0, step.attempts - 1)  # cut off, not failed
            step.activity = ""
            if step.interruptions > MAX_INTERRUPTIONS:
                step.status, step.problem = FAILED, "It was cut off by restarts too many times."
                step.finished = self._clock().isoformat()
            else:
                step.status = PENDING
        objective.waiting = ""
    self._save()
    for objective in self.store.objectives:
        if objective.open:
            self._spawn(objective, resumed=True)

Four things happen to a step that was in flight, and each is a decision.

  • It goes back to pending. Not “resume where it left off”. There is no where it left off: the session that was halfway through is gone and its half-formed reasoning went with it.
  • Its unverified work is thrown away. The objective's branch is reset to the last verified commit, so the next attempt does not inherit a file that was being edited when the lights went out. In the figure, that is the dashed stub on the branch vanishing after a cut.
  • The cut does not count against it. A step gets two attempts, and the line marked # cut off, not failed hands back the one the restart interrupted. Being interrupted is not the same as being wrong.
  • The cut is counted somewhere else. After three interruptions the fourth fails the step for good. Without that limit, a step whose own work brings the machine down would be retried at every boot, for ever.

Two smaller rules keep this cheap. A step only becomes running when its attempt really starts, so a step that is waiting its turn loses nothing to a restart and is not counted as cut off. And if an earlier attempt failed a check, what was wrong with it is stored on the step as feedback and survives the restart, so the next session starts with the reviewer's complaint in front of it.

Remembering the wrong thing is worse than forgetting

Once you decide to write progress down, you have to decide what counts as progress. The easy answer is to tick a step off when the agent says it is finished. That gives you an agent that never forgets and is sometimes confidently wrong about what it has done, permanently, across every restart.

The record above keeps five things apart on purpose: what was asked (goal), what was planned (the steps), what an agent says it did (result), what was checked (evidence), and what is unresolved (problem). Only the fourth can move a step to verified, and the agent that did the work has no say in it. For a code step the sequence is:

  1. The session finishes and reports. Its instructions tell it not to commit and not to claim the change works, since nothing has checked it yet.
  2. Code, not a model, commits the change and confirms that something actually changed. If the session said it edited the code and the diff is empty, the step fails with “It said it changed the code, but nothing changed.”
  3. Code runs the project's own check: cargo test, npm test, the project's pytest, whichever the project's files call for, or one I set in the configuration. A model never picks it.
  4. A reviewer session that did not write the change reads the diff against the step's acceptance criteria. Its instructions include “don't take the agent's word for anything.”

A step that fails gets one more attempt with the findings. If that fails too it is marked failed, the branch is rolled back to where the step began, and any step that depends on it is skipped with the reason written down. Steps that do not depend on it still run. Set the figure to step 3 failing twice: step 4 needed it and is skipped, step 5 did not and is verified.

This is why the restart rule in the last section is safe. Recovery resets to the last verified commit, so the only state that ever crosses a session boundary is state that something other than its author has checked. The two halves of the design are one rule seen twice: write the goal down, and never write down a claim.

It also changes what the person hears. OCTAVIA says one line when an objective ends, not one per step, and the line counts verified steps only. The readout under the figure shows the exact sentence for each case. An agent that reports “5 of 5 done” and one that reports “3 of 5 steps passed their checks” may have done identical work. Only one of them told you where to look.

It also has to stop

An agent that cannot lose its goal needs something else to end it, or it will work on a bad idea indefinitely. The limits are constants, not judgement calls:

  • At most three objectives open at once, eight steps each.
  • Two attempts per step and three restarts per step.
  • Fifteen minutes for planning and for a review, forty-five for a code step, twenty for a check.
  • Before each session it checks how full my usage limits are and holds the step back, still pending, if they are close.

And some things it will not plan at all: sending messages, publishing, deploying, buying, deleting data. Code it writes stays on its own branch, in its own worktree, and my checkout is never touched. Merging takes my word, and merges exactly the verified commit.

I have not measured how often objectives succeed, so this describes how one survives a restart, not how often one finishes. The agent that works is not one that remembers. It is allowed to forget everything, as often as it likes, because the goal was never its to hold. It is in a file, in my words, next to a list of what has been checked.

References

  1. OCTAVIA 0.2.7, github.com/Xitral/octavia. docs/objectives.md describes the behaviour. src/octavia/objectives/models.py holds the record and the limits, runner.py the resume, retry, rollback and reporting rules, prompts.py what each session is told, and src/octavia/core/jsonfile.py the write through a temporary file. The conversation timeouts are in config/default.yaml.
  2. G. Candea, A. Fox. “Crash-Only Software.” Proceedings of the 9th Workshop on Hot Topics in Operating Systems (HotOS IX), 2003. The argument that stopping and crashing should be the same code path.
  3. C. Mohan, D. Haderle, B. Lindsay, H. Pirahesh, P. Schwarz. “ARIES: A Transaction Recovery Method Supporting Fine-Granularity Locking and Partial Rollbacks Using Write-Ahead Logging.” ACM Transactions on Database Systems, 17(1), 1992, pp. 94–162.
  4. J. Gray, A. Reuter. Transaction Processing: Concepts and Techniques. Morgan Kaufmann, 1993. Where the vocabulary of committed and uncommitted work comes from.
All writing Get in touch