11import { Agent , SessionManager , FileStorage } from '@strands-agents/sdk'
22import { S3Storage } from '@strands-agents/sdk/session/s3-storage'
3- import type { SnapshotStorage , SnapshotLocation , Snapshot , SnapshotManifest } from '@strands-agents/sdk'
3+ import type {
4+ SnapshotStorage ,
5+ SnapshotLocation ,
6+ Snapshot ,
7+ SnapshotManifest ,
8+ } from '@strands-agents/sdk'
49import { S3Client } from '@aws-sdk/client-s3'
510
611// =====================
@@ -61,8 +66,9 @@ async function s3StorageExample() {
6166 storage : {
6267 snapshot : new S3Storage ( {
6368 bucket : 'my-agent-sessions' ,
64- prefix : 'production' , // Optional key prefix
65- s3Client : new S3Client ( { // Optional pre-configured client
69+ prefix : 'production' , // Optional key prefix
70+ s3Client : new S3Client ( {
71+ // Optional pre-configured client
6672 region : 'us-west-2' ,
6773 } ) ,
6874 // Alternatively, use region directly (cannot be combined with s3Client):
@@ -104,8 +110,8 @@ async function snapshotTriggerExample() {
104110 } )
105111
106112 const agent = new Agent ( { sessionManager : session } )
107- await agent . invoke ( 'First message' ) // 2 messages — no snapshot
108- await agent . invoke ( 'Second message' ) // 4 messages — immutable snapshot created
113+ await agent . invoke ( 'First message' ) // 2 messages — no snapshot
114+ await agent . invoke ( 'Second message' ) // 4 messages — immutable snapshot created
109115 // --8<-- [end:snapshot_trigger]
110116}
111117
@@ -116,7 +122,11 @@ async function snapshotTriggerExample() {
116122async function listAndRestoreExample ( ) {
117123 // --8<-- [start:list_and_restore]
118124 const storage = new FileStorage ( './sessions' )
119- const location = { sessionId : 'my-session' , scope : 'agent' as const , scopeId : 'default' }
125+ const location = {
126+ sessionId : 'my-session' ,
127+ scope : 'agent' as const ,
128+ scopeId : 'default' ,
129+ }
120130
121131 // List all immutable snapshot IDs (chronological order)
122132 const snapshotIds = await storage . listSnapshotIds ( { location } )
@@ -129,7 +139,10 @@ async function listAndRestoreExample() {
129139 } )
130140
131141 // Restore agent to a specific checkpoint
132- const session = new SessionManager ( { sessionId : 'my-session' , storage : { snapshot : storage } } )
142+ const session = new SessionManager ( {
143+ sessionId : 'my-session' ,
144+ storage : { snapshot : storage } ,
145+ } )
133146 const agent = new Agent ( { sessionManager : session } )
134147 await agent . initialize ( )
135148 await session . restoreSnapshot ( { target : agent , snapshotId : snapshotIds [ 0 ] ! } )
@@ -144,21 +157,36 @@ async function customStorageExample() {
144157 // --8<-- [start:custom_storage]
145158 // Implement SnapshotStorage to plug in any backend (database, Redis, etc.)
146159 class MyStorage implements SnapshotStorage {
147- async saveSnapshot ( { location, snapshotId, snapshot } : {
148- location : SnapshotLocation ; snapshotId : string ; isLatest : boolean ; snapshot : Snapshot
160+ async saveSnapshot ( {
161+ location,
162+ snapshotId,
163+ snapshot,
164+ } : {
165+ location : SnapshotLocation
166+ snapshotId : string
167+ isLatest : boolean
168+ snapshot : Snapshot
149169 } ) {
150170 // Store the snapshot JSON keyed by location + snapshotId
151171 }
152172
153- async loadSnapshot ( { location, snapshotId } : {
154- location : SnapshotLocation ; snapshotId ?: string
173+ async loadSnapshot ( {
174+ location,
175+ snapshotId,
176+ } : {
177+ location : SnapshotLocation
178+ snapshotId ?: string
155179 } ) {
156180 // Return the snapshot for the given location, or null if not found
157181 return null
158182 }
159183
160- async listSnapshotIds ( { location } : {
161- location : SnapshotLocation ; limit ?: number ; startAfter ?: string
184+ async listSnapshotIds ( {
185+ location,
186+ } : {
187+ location : SnapshotLocation
188+ limit ?: number
189+ startAfter ?: string
162190 } ) {
163191 // Return immutable snapshot IDs sorted chronologically
164192 return [ ]
@@ -168,13 +196,21 @@ async function customStorageExample() {
168196 // Remove all stored data for this session
169197 }
170198
171- async loadManifest ( { location } : { location : SnapshotLocation } ) : Promise < SnapshotManifest > {
199+ async loadManifest ( {
200+ location,
201+ } : {
202+ location : SnapshotLocation
203+ } ) : Promise < SnapshotManifest > {
172204 // Return the manifest for the given location
173205 return { schemaVersion : '1' , updatedAt : new Date ( ) . toISOString ( ) }
174206 }
175207
176- async saveManifest ( { location, manifest } : {
177- location : SnapshotLocation ; manifest : SnapshotManifest
208+ async saveManifest ( {
209+ location,
210+ manifest,
211+ } : {
212+ location : SnapshotLocation
213+ manifest : SnapshotManifest
178214 } ) {
179215 // Persist the manifest
180216 }
0 commit comments