Skip to main content
Keep a project conversation across sequential runs and verify that another user with the same session ID gets separate state. This recipe uses the runtime’s default in-memory session store. Download the complete project, extract it, then run npm install and npm run check. Use npm start to execute the recipe with the requirements below.

Set up the project

Use Node.js ^22.18.0 or ^24.11.0. In an empty directory:
Running this recipe contacts OpenAI. Set OPENAI_MODEL to a compatible model your account can use; see model choices.

Run two turns

Save this as harness-sessions.ts:
harness-sessions.ts
The second answer should recall Atlas. With ordinary text responses, the stored history contains four messages and is replayable. The check for Bob’s history must pass with zero messages.

Turn this into an application

Scope sessions by (tenantId, userId, sessionId), with tenant and user derived from authentication. Reuse that tuple when the same person continues the conversation. Await the first run before starting the next; the default store permits one writer per scoped session in this process. Read a snapshot through a lease after execution settles and always release it. closeSession() releases resources, not transcript data. The runtime’s store is separate from any Agent storage you configure.

Persistence and recovery

The default store loses data on process exit. To retain conversation state, implement the session store contract with accurate durability and concurrency guarantees. Persistent history alone does not make an interrupted run resumable. For task recovery and uncertain effects, use durable execution. See events and controls for sending a follow-up to an active run; that control is different from the sequential settled runs shown here.