# How Memory Works in HyperAgents

Part of: [AI Agent Memory](https://ninadpathak.com/articles/agent-memory/)

HyperAgents memory was written by the agent itself: a key-value JSON store printed in the paper. This page runs it and shows what it keeps and omits.

Canonical: https://ninadpathak.com/articles/hyperagents-memory/

By Ninad Pathak (https://ninadpathak.com/about/). Published 2026-04-19, updated 2026-11-18.

Nobody on the research team designed the memory system in HyperAgents. The [paper](https://arxiv.org/abs/2603.19461), first posted on March 19 and revised on November 1, reports that the agent wrote one for itself: "Without explicit instruction to do so, the agent creates mechanisms for storing and retrieving insights across sessions."

Jürgen Schmidhuber proposed the [Gödel machine](https://en.wikipedia.org/wiki/G%C3%B6del_machine) in 2003, which Wikipedia describes as a program that "rewrites its own code when it can prove the new code provides a better strategy". The system in this paper descends from it by way of the Darwin Gödel Machine.

So what does a self-rewriting agent build when it wants to remember something? The paper prints one answer in [its appendix](https://arxiv.org/html/2603.19461v1), a short Python class that keeps notes in a JSON file.

I'll run that class and look at what the agent built as its own [AI agent memory](https://ninadpathak.com/articles/agent-memory/) and what it left out. The appendix link goes to the March version, the only one arXiv renders as a web page, and the section reads the same in the November PDF.

## What is a hyperagent?

A hyperagent is a program made of two agents that can both be edited. The abstract defines the pair as "a task agent (which solves the target task) and a meta agent (which modifies itself and the task agent)".

The meta agent's own procedure is open to change as well, so the system can improve how it improves. The authors, with Jenny Zhang as first author and the work done at Meta, build it on the Darwin Gödel Machine and call the result DGM-H.

Memory comes into the paper as one of the things the meta agent gave itself. The abstract lists "persistent memory, performance tracking" among the improvements the system made to its own process.

## What memory did the agent build?

The agent built a key-value store with a timestamp on each entry. The class below is the one printed in Appendix E.3.7, with a loader added, since the paper doesn't print that method.

```python
"""The MemoryTool printed in Appendix E.3.7 of the Hyperagents paper, run on a temp file.

The class body is the paper's. _load_memory is not printed there, so the
version below is mine, as are the three calls at the bottom.
"""
import json
import os
import tempfile
from datetime import datetime
from typing import List, Optional


class MemoryTool:
    """Tool for persistent memory storage across agent interactions."""

    def __init__(self, memory_file: str = './memory.json'):
        self.memory_file = memory_file
        self.memory = self._load_memory()

    def _load_memory(self) -> dict:  # not shown in the paper
        if os.path.exists(self.memory_file):
            with open(self.memory_file) as f:
                return json.load(f)
        return {}

    def store(self, key: str, value: any) -> None:
        """Store information with timestamp for temporal tracking."""
        self.memory[key] = {
            "value": value,
            "timestamp": datetime.now().isoformat()
        }
        self._save()

    def retrieve(self, key: str) -> Optional[any]:
        """Retrieve stored information by key."""
        return self.memory.get(key, {}).get("value")

    def list_keys(self) -> List[str]:
        """List all stored memory keys."""
        return list(self.memory.keys())

    def _save(self):
        """Persist memory to disk."""
        with open(self.memory_file, 'w') as f:
            json.dump(self.memory, f, indent=2)


path = os.path.join(tempfile.mkdtemp(), "memory.json")

first = MemoryTool(path)
first.store("best_generation", "Gen55: 63% accuracy, too harsh")
first.store("best_generation", "Gen64: 61% accuracy, best balance")
first.store("gen66_results", "52% accuracy, worse than gen64")

second = MemoryTool(path)  # a new process would start here
print("keys after reload:   ", second.list_keys())
print("best_generation:     ", second.retrieve("best_generation"))
print("unknown key:         ", second.retrieve("gen55_results"))
print("entries on disk:     ", len(json.load(open(path))))
```

The three `store` calls and the reload at the bottom are mine, and so is the choice to reuse a key. `python3 hyper_memory.py` gives this.

```text
keys after reload:    ['best_generation', 'gen66_results']
best_generation:      Gen64: 61% accuracy, best balance
unknown key:          None
entries on disk:      2
```

<figure class="np-figure">
  <a class="np-figure-zoom" href="https://ninadpathak.com/static/images/diagrams/hyperagents-memory/memory-layers.svg"><picture><source media="(max-width: 712px)" srcset="https://ninadpathak.com/static/images/diagrams/hyperagents-memory/memory-layers.narrow.svg" width="288" height="720"><img class="np-has-narrow" src="https://ninadpathak.com/static/images/diagrams/hyperagents-memory/memory-layers.svg" width="720" height="256" alt="A meta agent calls a MemoryTool that it wrote for itself. The tool saves each insight under a key in a memory.json file, and the next generation of the agent consults that file when it modifies itself." loading="lazy" decoding="async"></picture></a>
  <figcaption>The hyperagent's memory is one JSON file, written through a tool the agent added to its own code.</figcaption>
</figure>

The reload works, which is all persistence means here: a second instance reads the file and finds the notes. The paper's description of the real file is "structured storage of performance insights", and the entries it prints are paragraphs of analysis filed under keys such as `best_performers_analysis`.

## What does the agent write down?

The agent writes conclusions and leaves the raw numbers to the logs. The authors make the distinction themselves: "Instead of merely logging numerical scores, the hyperagent stores synthesized insights, causal hypotheses, and forward-looking plans".

The entry under `gen66_results` records 52% accuracy against generation 64's 61% and names the cause, in the agent's words: "gen65 changes over-corrected." Another entry sets the plan for the next attempt, to "combine gen55's critical reasoning with gen64's balance".

Why does that matter? Because raw scores can be read again from the logs, and a conclusion exists only if somebody writes it down.

Compaction can lose a conclusion the same way. If the summary of a long session leaves the conclusion out, it's gone, which [short-term agent memory](https://ninadpathak.com/articles/short-term-agent-memory/) works through.

## What did the agent leave out?

The agent left out history, search and forgetting, which memory systems add later. My run stores two notes under `best_generation`, and the second replaces the first with no trace that Gen55 was once the answer.

The agent's own file avoids that overwrite through its key names. Each event in the printed entries gets a key of its own, such as `gen66_results`, so no result replaces an earlier one, even though the class would let it.

But a convention can be broken by one careless call, and an overwrite with no history is the design that [memory versioning](https://ninadpathak.com/articles/memory-versioning/) argues against, since nobody can ask later what the agent believed at an earlier point. The timestamp records when the surviving value was written and nothing about the one it replaced.

The class also has no way to search. `retrieve` needs the exact key, and `list_keys` returns every key, so recall depends on the agent choosing names it will recognise later.

The class never deletes a note either, and the whole file is rewritten on every `store`. Neither matters at the scale of the runs the paper reports, and both would in a system that ran for months.

## Does the memory make the agent better?

The paper credits memory with part of the gain and doesn't isolate its effect. Its transfer experiment moves a trained hyperagent to a new domain, and the authors write that "the transfer hyperagents have features such as performance tracking and persistent memory", which they call a qualitative attribution.

The measured result is about the meta agent as a whole.

Moving only the meta agent to the new domain scored 0.620 on imp@50, the paper's measure of improvement after 50 iterations, against 0.630 for moving both agents. Moving only the task agent scored 0.100, with a confidence interval the paper gives as 0.0 to 0.560.

So the evidence says the self-improvement machinery transfers, and that memory is one visible part of that machinery. A claim that the memory file alone caused the gain would go past what the paper shows.

## What should a builder take from it?

Start with less than a memory framework offers. An agent that could have written anything wrote a class of 22 lines and a JSON file, and that was enough for its notes to shape the next generation.

History, search and forgetting are what to add when the simple version stops being enough. Those layers are laid out in [AI memory management](https://ninadpathak.com/articles/ai-memory-management/), and [Claude Code's memory](https://ninadpathak.com/articles/claude-code-memory/) is a shipped product that also keeps its notes in plain files.

## FAQ

**Does HyperAgents ship with a memory system?**

No. The public repository holds the starting agents with two tools, for shell commands and file edits, and the memory tool exists only in the paper's appendix and its experiment logs.

**Where does a hyperagent store its memory?**

The printed example stores it in a `memory.json` file in the working directory. Each key holds a value and the time it was written.

**Is HyperAgents the same as the Darwin Gödel Machine?**

No. The paper's system, DGM-H, extends the Darwin Gödel Machine with a meta agent whose own improvement procedure can be edited.

---

Work with me: email hello@ninadpathak.com, or book a 30-minute call at https://zcal.co/ninadpathak/meet

Services: https://ninadpathak.com/services/
