feat: add session manager implementation and related tests#569
Open
JackYPCOnline wants to merge 20 commits intostrands-agents:mainfrom
Open
feat: add session manager implementation and related tests#569JackYPCOnline wants to merge 20 commits intostrands-agents:mainfrom
JackYPCOnline wants to merge 20 commits intostrands-agents:mainfrom
Conversation
# Conflicts: # package-lock.json # src/__fixtures__/mock-storage-provider.ts # src/session/index.ts # src/session/storage.ts # src/session/types.ts
92e12cc to
f474eb7
Compare
pgrayy
reviewed
Feb 25, 2026
pgrayy
reviewed
Feb 25, 2026
pgrayy
reviewed
Feb 25, 2026
pgrayy
reviewed
Feb 25, 2026
pgrayy
reviewed
Feb 25, 2026
JackYPCOnline
commented
Feb 26, 2026
| * Manifest tracks snapshot metadata. | ||
| * Stored alongside snapshots to support versioning and future multi-agent patterns. | ||
| */ | ||
| export interface SnapshotManifest { |
Contributor
Author
There was a problem hiding this comment.
SnapshotManifest is now unused, we don't create manifest while we create immutable_history, but it will be used in future, so keep it to follow initial design.
JackYPCOnline
commented
Feb 27, 2026
| private _getHistorySnapshotKey(location: SnapshotLocation, snapshotId: string): string { | ||
| return this._getKey(location, `${IMMUTABLE_HISTORY}snapshot_${String(snapshotId).padStart(5, '0')}.json`) | ||
| validateIdentifier(snapshotId) | ||
| return this._getKey(location, `${IMMUTABLE_HISTORY}snapshot_${snapshotId}.json`) |
Contributor
Author
There was a problem hiding this comment.
This resolves an internal ticket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
SessionManagerto the Strands Agents TypeScript SDK, enabling agents to persist and restore conversation state across invocations using pluggable storage backends (filesystem or S3).Related issue
#80
Type of Change
New feature
New APIs Introduced
SessionManagersessionIdstring'default-session'agentIdstring'default'storage.snapshotSnapshotStorageFileStoragein OS temp dirsaveLatestOn'message' | 'invocation' | 'never''message'snapshotTriggerSnapshotTriggerCallbackloadSnapshotIdstringMethods:
saveSnapshot({ target: Agent, isLatest: boolean }): Promise<void>— manually persist agent staterestoreSnapshot({ target: Agent, snapshotId?: string }): Promise<boolean>— restore agent state; returnsfalseif no snapshot existsImplements
HookProvider— integrates with the agent lifecycle viaInitializedEvent,MessageAddedEvent, andAfterInvocationEvent.FileStorageFile-based
SnapshotStoragebackend. Default location:os.tmpdir()/strands-sessions.Storage layout:
S3StorageS3-based
SnapshotStoragebackend. Auto-creates the bucket if it doesn't exist.bucketstringprefixstringregionstringus-east-1)s3ClientS3Clientregion)SnapshotStorageInterfaceImplement to provide a custom backend:
SnapshotTriggerCallbackControls when immutable snapshots are created, called after each agent invocation:
Usage Example
Files Changed
src/session/session-manager.tsSessionManagerclasssrc/session/file-storage.tsFileStorageimplementationsrc/session/s3-storage.tsS3Storageimplementationsrc/session/storage.tsSnapshotStorageinterface and typessrc/session/types.tsSnapshot,SnapshotManifest,SnapshotTriggerCallbacktypessrc/session/validation.tsvalidateIdentifierutilitysrc/session/__tests__/test/integ/session-manager.test.node.tsFollow up
Testing
SessionManager,FileStorage,S3Storage, andvalidateIdentifiertest/integ/session-manager.test.node.tsnpm run checkChecklist