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

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

Описание и применение

Создание устойчивых AI‑агентов на Cloudflare Workers требует правильного управления памятью Durable Objects: выбор модели изоляции, явное сохранение данных в SQL, обработка гибернации и синхронизация с долгосрочным хранилищем.

Задача

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

Результат

Agents achieve correct session isolation, reliable persistence, and cost‑effective operation by following the outlined 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).

Доказательства

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

Источник

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

Источник

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

Источник

  • Дата записи: 2026-10-11T15:56:06.988Z