ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-05-26Advanced

Antigravity Multi-Agent State Tiers — A Three-Layer Design with Ephemeral, Journal, and Canonical

Before your Antigravity Background Agents and Sub-agents start mixing up their memory, split agent state into three lifetimes — ephemeral, journal, canonical — and map each to the right Cloudflare store. Includes the write-back boundary rules I rely on across a 12-year wallpaper-app portfolio.

antigravity429agents123architecture19state-management2cloudflare-workers8

Premium Article

One morning, an Antigravity Background Agent forgot the previous day's AdMob review and emailed me the same warning three times in a row. Following the run logs, the memory was technically present, but the restore key was off by a few characters and the agent could not read it back. I'm Masaki Hirokawa (Dolice), an indie developer building iOS and Android apps since 2014 and an artist running daily operations through editor-integrated AI agents like Antigravity. After a few rounds of "the agent forgot too much" and "the agent remembered too much," I landed on a single rule: agent state has to be split into three lifetimes, or it will eventually break.

This piece is a practical write-up of those three lifetimes — ephemeral, journal, canonical — together with how I map them onto Cloudflare Workers stores (KV, Durable Objects, R2, D1) and how I draw the write-back boundaries. The patterns come out of running a 50M-download wallpaper-app portfolio for 12 years and orchestrating a small fleet of Background, Sub, and Browser Sub-agents alongside it. If you are running more than one Antigravity agent in production, the boundaries below should give you a frame to sharpen your own design decisions.

The same Antigravity agent holds information with three very different lifespans

When you call everything "agent memory," it eventually breaks. The split I have settled on is:

TierLifetimeDamage if lostExamples
ephemeral1 runnear zero (recomputable)intermediate prompts, raw LLM output, file snapshots
journaldays to weeksmedium (slow to replay)decision logs, A/B intermediate scores, observation diffs
canonicalpermanentfatal (product-breaking)published slugs, purchase records, membership state

The deciding factor is not byte size but blast radius. A 200KB chain-of-thought can be ephemeral. A 60-byte "we already published this slug" record absolutely cannot be ephemeral.

When you internalize the split, agent code only needs to ask three questions:

  1. Can the next run recompute this? If yes — ephemeral.
  2. If not, can a human accept "we have to redo it"? If yes — journal.
  3. If losing it breaks the user-facing product — canonical.

That is the entire rubric. The tiers map to different physical stores, but agent code talks to all three through a single adapter shape.

Ephemeral — working memory that lives and dies inside one agent run

Ephemeral is everything that is born when an agent run starts and dies when it ends: scratch prompts, raw LLM responses, intermediate file listings, retrieval results, in-flight reasoning. Because the next run can rebuild it cheaply, there is almost no value in writing it to a shared store like KV.

In my Antigravity Background Agents this tier lives in plain JavaScript memory — a Map scoped to the run entry function.

// state/ephemeral.ts
export class EphemeralStore {
  private bucket = new Map<string, unknown>();
 
  get<T = unknown>(key: string): T | undefined {
    return this.bucket.get(key) as T | undefined;
  }
 
  put<T = unknown>(key: string, value: T): void {
    this.bucket.set(key, value);
  }
 
  // Always call this at the end of a run. Disposal is explicit.
  dispose(): void {
    this.bucket.clear();
  }
}

The explicit dispose() is intentional. I want ephemeral to be actively thrown away, not silently abandoned. If you let an intermediate LLM response leak into the journal or canonical tier by accident, your storage bill rises without bound. A single Background Agent in my fleet handles roughly 200–800 KB of ephemeral data per run; written naively into KV that adds up to gigabytes per month, far above the ¥800/month budget I keep per site.

One implementation gotcha worth flagging: Cloudflare Workers can reuse the same Isolate across requests, so a Map declared at the module scope will silently persist between runs. I fell into that exact trap once. The fix was to make sure EphemeralStore is always new-ed inside the run entry function. Before pushing this pattern into production, write a test that deliberately fires two runs against the same Isolate to confirm the store is fresh each time.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Split agent state into ephemeral / journal / canonical so a single Background Agent run can fail without taking your product down
Concrete Cloudflare mapping — KV / Durable Objects / R2 / D1 — with a small TypeScript adapter you can drop into a Worker today
Three operational rules I have kept across 12 years of running an indie wallpaper-app portfolio of 50M+ downloads
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-06-19
Parallel or Keep It Serial: The Break-Even Point When Orchestrating Multiple Agents
Should you run agents in parallel or keep them serial? A simple way to estimate the break-even between coordination cost and saved wall-clock time, plus how I actually split parallel vs serial across four scheduled sites.
Agents & Manager2026-06-02
Rehearsing an Agent's Actions Before They Touch Production — Designing a Zero-Side-Effect Dry-Run Layer
Some accidents survive shadow mode and canaries: the very first time an agent touches an external API. This is the design and TypeScript implementation of a zero-side-effect dry-run layer you can bolt onto Antigravity's parallel agents, with the real numbers from running six sites autonomously.
Agents & Manager2026-04-27
Giving Antigravity Agents Safe Write Access — Production Permission Boundary Design
A practical guide to designing Permission Boundaries that let AI agents safely touch production databases, deploys, and billing APIs — with dry-runs, approval queues, and audit logs.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →