feat(agent): add take_snapshot() and load_snapshot() methods#1948
Merged
JackYPCOnline merged 9 commits intostrands-agents:mainfrom Apr 14, 2026
Merged
feat(agent): add take_snapshot() and load_snapshot() methods#1948JackYPCOnline merged 9 commits intostrands-agents:mainfrom
JackYPCOnline merged 9 commits intostrands-agents:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
15636c7 to
8d88027
Compare
|
Assessment: Approve ✅ Excellent updates! The PR is now in great shape for merge. Improvements in This Update
API Documentation QualityThe PR description now satisfies API bar raising requirements:
The implementation is clean, well-tested, and thoroughly documented. Ready to merge! 🚀 |
This comment was marked as resolved.
This comment was marked as resolved.
JackYPCOnline
approved these changes
Apr 14, 2026
Contributor
JackYPCOnline
left a comment
There was a problem hiding this comment.
Preset: takeSnapshotOption is now dead code, we shoud add doc string to explain how it works.
It is a non blocking comment, so merging this PR for now.
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
take_snapshot()andload_snapshot()to the PythonAgentclass, mirroring the snapshot API already present in the TypeScript SDK. Snapshots are versioned, JSON-serializable captures of agent state that can be stored and restored across agent instances.Supported fields:
messages,state,conversation_manager_state,interrupt_state,system_prompt. The"session"preset captures all fields exceptsystem_prompt.system_promptis stored as content blocks to preserve caching hints and other block-level metadata across round-trips. Restore is selective — only fields present in the snapshot are applied; absent fields leave the target agent unchanged. Anullvalue forsystem_promptin the snapshot explicitly clears the prompt on restore, distinct from the field being absent entirely.New Agent Methods
agent.take_snapshot(...) -> SnapshotCaptures the agent's current state as an in-memory
Snapshot.preset— Named field set. Currently"session"(messages, state, conversation_manager_state, interrupt_state).include— Additional fields to add on top of the preset.exclude— Fields to remove after applying preset + include.app_data— Arbitrary application-owned JSON stored verbatim in the snapshot.agent.load_snapshot(snapshot) -> NoneRestores agent state from a previously captured snapshot. Only fields present in
snapshot.dataare applied; absent fields are left unchanged.Raises
SnapshotExceptionif the snapshot has an unsupported schema version or invalid scope.Example Usage
Related Issues
#1138
Documentation PR
In Progress
strands-agents/docs#733
Type of Change
New feature
Testing
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.