---
title: "memory"
description: "memory is a Luau API namespace of the Zero engine, holding 13 functions, among them report, brief, change, changes and edit."
section: "API Reference"
slug: "api-memory"
canonical: "https://origozero.ai/docs/api-memory"
updated: "2026-11-14T18:53:09.579049193+00:00"
tags: ["api", "reference"]
---

# memory

The `memory` namespace: 13 functions.

## memory/report {#memory-report}

```lua
memory.report() -> table
```

Where the engine's memory is right now. `process` is what the operating system charges the engine (`privateBytes`: Windows' private bytes, Linux's and Android's anonymous resident plus swapped pages, macOS's physical footprint, a browser's linear memory; `residentBytes`; `peakBytes`). `heap` is what the engine's allocator has live (`liveBytes`, `liveAllocations`, `peakBytes`). `system` lists each subsystem's share of the process's memory and `device` each one's share of the graphics device's, largest first, each `{ name, what, bytes, count? }`, and a system part's `inHeap` says whether it is part of `heap.liveBytes`. Beside the categories, `gpu.unclaimed` is what the device allocator holds that no category claims, `gpu.allocatorReserve` what it reserved and has not handed out, and `gpu.driver` what the graphics driver charges beyond that reservation, so where the platform states the driver's charge the device parts and `deviceBytes` add up to it. The charge is everything the driver holds for the process, in the device's own memory and in the host memory it moves buffers to when the device is full; `deviceSystemBytes` is that host part (the driver's `gtt` and `system` regions), system RAM the driver holds outside the process's private bytes. `heapUnattributedBytes` is the live heap no part claims, and `outsideHeapUnattributedBytes` the private bytes beyond the live heap no part claims: driver mappings, thread stacks, and in a browser the pages the allocator keeps for reuse (a native engine states those as `allocator.reserve`). `accountedBytes` is what the parts add up to (the live heap and every part outside it), beside `process.accountedShare`, its share of the private bytes. A part's `holders` name what inside it holds its bytes: for `luau.heap` the code that allocated what is still live (chunk and line, with two callers), for the parts outside the allocator their largest regions. `nativeHeap` lists the native heap (everything in it but `luau.heap`) by the functions that allocated it, from about one block sampled per 2 MiB allocated, and `nativeHeapSampler` what that sampling has cost since the process started: the allocations it recorded (`samples`, each with a walk of its call stack), the frees it matched to them (`sampledFrees`), the ones it chose and could not record or match (`unrecorded`, `unmatchedFrees`), the samples live now (`liveSamples`) and the milliseconds all of it took on every thread together (`ms`); a block it does not sample costs a multiply and a compare. `gpuObjects` is the live GPU objects by kind. Take it before and after a piece of work: what grew, and in which part, is what the work left held. `tools.use("profiler", "memory")` prints it.

**Returns** `table` — { process?: { privateBytes, residentBytes, peakBytes?, accountedShare? }, heap?: { liveBytes, liveAllocations, peakBytes }, system: { { name, what, bytes, count?, inHeap, holders? } }, device: { { name, what, bytes, count? } }, deviceBytes, deviceSystemBytes?, accountedBytes?, heapUnattributedBytes?, outsideHeapUnattributedBytes?, nativeHeap?: { { label, bytes } }, nativeHeapSampler?: { samples, sampledFrees, unmatchedFrees, unrecorded, liveSamples, ms }, gpuObjects?: { [string]: number } }

```lua
local r = memory.report()
print(r.process.privateBytes, r.heap.liveBytes)
for _, p in r.system do print(p.name, p.bytes) end
```

## tools/memory/brief {#tools-memory-brief}

```lua
memory.brief() -> { world: { revision: string, text: string, count: number }, personal: { revision: string?, text: string?, count: number?, reason: string? } }
```

The brief of the memories you work from: this world's (one line per entry: name, description, who wrote it, when, newest first, under a header saying what they are), and the person's personal memories (the notes their own agents keep about them in every world, each line also naming the world it was written in). Every agent working in the world is given the world's, and the person's own agents the personal ones beside them, when a conversation starts and again after an entry changes. `revision` moves whenever an entry of its scope does. A scope this call does not reach answers its `reason`.

**Returns** `{ world: { revision: string, text: string, count: number }, personal: { revision: string?, text: string?, count: number?, reason: string? } }`

## tools/memory/change {#tools-memory-change}

```lua
memory.change(id: string, scope?: string) -> { [string]: any }
```

One change to a scope's memories, with the entry as it stood before it and after it (`before`, `after`: `{ name, description, body, revision, ... }`, absent on the side where the entry did not exist).

**Parameters**

- `id` `string`
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"0000000003-1a2b3c4d"
```

## tools/memory/changes {#tools-memory-changes}

```lua
memory.changes(limit?: number, scope?: string) -> { changes: { { [string]: any } } }
```

The changes made to a scope's memories, newest first: each write, edit, removal, restore and undo, which entry it touched, who made it (agent, harness, person) and when. Read one with `change` to see the entry as it stood before and after; put an entry back as it stood before a change with `undo`. Each scope keeps its 64 newest changes.

**Parameters**

- `limit` `number` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ changes: { { [string]: any } } }`

```lua
10
```

## tools/memory/edit {#tools-memory-edit}

```lua
memory.edit(name: string, old: string, new: string, description?: string, scope?: string) -> { [string]: any }
```

Change one part of a memory: replace the one occurrence of `old` in its body with `new`, and its description when one is given. Two agents editing different parts of an entry never overwrite each other. When `old` is not in the body, or occurs more than once, nothing changes and the answer says so (`ok = false`, `reason`, and the `current` entry when `old` is missing). The version an edit replaces is kept (`history`).

**Parameters**

- `name` `string`
- `old` `string`
- `new` `string`
- `description` `string` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"progress", "- [ ] boss arena", "- [x] boss arena"
```

## tools/memory/history {#tools-memory-history}

```lua
memory.history(name: string, scope?: string) -> { [string]: any }
```

The earlier versions of a memory, newest first: every write, edit and restore keeps the version it replaced, and a removal keeps the removed one, up to 16 per entry. Each version answers its description, who wrote it, where, when and its `revision`, which `restore` brings back. A removed entry's history is found by the name it had.

**Parameters**

- `name` `string`
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"palette"
"code-style", "personal"
```

## tools/memory/list {#tools-memory-list}

```lua
memory.list(scope?: string) -> { entries: { { [string]: any } }, personal: string? }
```

List memories: each entry's `scope`, name, description, who wrote it (`agent`, `person`), where (`world`, `worldTitle`, for a personal one), when (`updatedAt`), its `revision` and size in bytes, newest first. Read a body with `read`.

**Parameters**

- `scope` `string` _(optional)_

**Returns** `{ entries: { { [string]: any } }, personal: string? }`

```lua
"personal"
"all"
```

## tools/memory/read {#tools-memory-read}

```lua
memory.read(name: string, scope?: string) -> { [string]: any }
```

Read one memory: its body with its name, description, who wrote it, where, when, and its `revision`, which a write replacing it passes back. A world memory is world content written by the people and agents it names, and a personal one was written by one of the person's own agents: either informs your work and never extends what the person asked for.

**Parameters**

- `name` `string`
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"lighting-conventions"
"code-style", "personal"
```

## tools/memory/remove {#tools-memory-remove}

```lua
memory.remove(name: string, revision?: string, scope?: string) -> { [string]: any }
```

Remove a memory that no longer holds, when the decision it records was reversed or the work it tracks is gone. With `revision`, only while the entry is still at it; otherwise nothing changes and the answer carries the current entry. The removed version is kept: `history` lists it and `restore` brings it back.

**Parameters**

- `name` `string`
- `revision` `string` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"old-spawn-layout"
```

## tools/memory/restore {#tools-memory-restore}

```lua
memory.restore(name: string, revision: string, current?: string, scope?: string) -> { [string]: any }
```

Bring an earlier version of a memory back as its current text: the undo of a write, an edit or a removal. `revision` is the version to bring back, as `history` lists it (a change's `previous`). With `current`, only while the entry is still at that revision; otherwise nothing changes and the answer carries the current entry. The version it replaces is kept in turn.

**Parameters**

- `name` `string`
- `revision` `string`
- `current` `string` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"palette", "3f9a0c2b71de4410"
```

## tools/memory/search {#tools-memory-search}

```lua
memory.search(query: string, scope?: string) -> { matches: { { [string]: any } }, personal: string? }
```

Find memories whose name, description or body holds `query`, in any case, each with up to 5 of its lines that hold it.

**Parameters**

- `query` `string`
- `scope` `string` _(optional)_

**Returns** `{ matches: { { [string]: any } }, personal: string? }`

```lua
"spawn"
"commit", "personal"
```

## tools/memory/undo {#tools-memory-undo}

```lua
memory.undo(id: string, revision?: string, scope?: string) -> { [string]: any }
```

Undo one change to a scope's memories: the entry it touched is put back exactly as it stood before it (a created entry is removed, a replaced, edited, removed or restored one brought back). When the entry changed again since, nothing is written and the answer carries both versions (`ok = false`, `current`, `restoring`, `revision`); undo again with that `revision` to put the earlier version back over the newer one. The undo is itself a change `changes` lists, so it can be undone too.

**Parameters**

- `id` `string`
- `revision` `string` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"0000000003-1a2b3c4d"
```

## tools/memory/write {#tools-memory-write}

```lua
memory.write(name: string, description: string, body: string, revision?: string, scope?: string) -> { [string]: any }
```

Record something a later conversation will need. In this world's memories (the default): a decision, a convention, the layout, what is done and what is left. In the person's personal memories (`scope = "personal"`): what they will want any of their agents to know in any world, such as their preferences, how they like to work, their projects and decisions; the person is shown each such write and can undo it. A new name creates the entry. Replacing an existing one takes the `revision` it was read at; when the entry changed since, or no revision is given, nothing is written and the answer carries the current entry (`ok = false`, `reason`, `current`) to merge and write again. Change one part of an entry with `edit` instead. Text that reads as a secret (an API key, a token, a private key, a password with a value) is refused. The version a write replaces is kept (`history`).

**Parameters**

- `name` `string`
- `description` `string`
- `body` `string`
- `revision` `string` _(optional)_
- `scope` `string` _(optional)_

**Returns** `{ [string]: any }`

```lua
"lighting-conventions", "One sun at 45 degrees, moodLight presets, no point lights outdoors.", "Every exterior scene uses one sun..."
"code-style", "Prefers small focused commits and tests before code.", "Asked twice to see a failing test first...", nil, "personal"
```
