Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Durable Objects Are Your Agent's Memory — If You Design Them Like a Database

Description and use

Building stateful AI agents on Cloudflare Workers demands proper Durable Object memory management: choose an isolation model, explicitly persist data via SQL transactions, handle hibernation, and sync with long‑term storage.

Problem

Designing stateful AI agents on Cloudflare Workers requires correct Durable Object (DO) memory management to avoid privacy violations or loss of context.

Outcome

Agents achieve correct session isolation, reliable persistence, and cost‑effective operation by following the outlined workflow.

Workflow

  • 1. Decide isolation model (per‑session, per‑user, per‑tenant).
  • 2. Derive DO ID from user/tenant ID and enforce access control.
  • 3. Initialize SQL schema in DO constructor or initialize().
  • 4. Wrap all state‑changing operations in explicit transactions and await commit/rollback.
  • 5. Persist data to durable storage before returning from async functions.
  • 6. Rebuild any in‑memory caches in initialize() after hibernation.
  • 7. Use TTL policies to expire outdated session data.
  • 8. Optionally sync important insights from DO to long‑term storage (e.g., Qdrant).

Evidence

Explicitly committed transactions (await sql.execute('COMMIT'))

Source

In-memory JavaScript variables: Anything stored in this or local variables disappears when the DO hibernates

Source

When a DO hasn't received a request for a few seconds, it suspends execution

Source

  • Record date: 2026-10-11T15:56:06.988Z