Repository navigation
feat(session): deprecate repository-based managers and add migration guide #4797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolas-m-romero
wants to merge
51
commits into
main
Choose a base branch
from
agent-tasks/3663-session-migration-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+423
−179
Open
Changes from 29 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
40932f6
docs(session): add migration guide from message-log managers to Snaps…
765b2d3
docs(session): emphasize why to migrate and what to watch when portin…
8bc5666
docs(session): drop the Looking ahead note from the migration guide
e828392
docs(session): reframe the constructor swap as a valid choice, not a …
4f0dbd6
docs(session): make the before/after swap snippet parallel
b2d513c
docs(session): tighten the migration guide to reference-doc register
b5c83ba
docs(session): fold verify/cut-over into the running-the-migration list
92955a4
docs(session): add the why-migrate rationale and clarify the snapshot…
02f8286
docs: reframe session manager guidance to recommend SnapshotSessionMa…
8af9e08
docs: flag the migration reference script as a minimal, extend-for-co…
a4cf4ef
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 6b66a79
docs: clarify multi-agent migration limitations
63724bd
Apply suggestion from @strandly-the-agent
nicolas-m-romero 8513a67
docs: clarify legacy migration source mutations
62e8856
docs: separate prompt and model migration guidance
0f1df60
docs: document Bidi restart snapshots
09a9059
Update site/src/content/docs/user-guide/sdk/agents/session-management…
nicolas-m-romero cfb79d9
docs: define migration prompt placeholder
54a4911
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 69472f9
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 7630259
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 72d16cc
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero ba12ce3
docs: remove em dashes from session migration guide
44fcbe4
docs: align migration section on repository-based terminology
84d7d0d
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 8b352b7
docs(session): separate repository migration guide
a6a3473
feat(session): deprecate repository-based managers
46d6bf5
docs(session): retain deprecated manager guidance
908293a
Merge remote-tracking branch 'origin/main' into agent-tasks/3663-sess…
9bed83f
fix(session): avoid deprecation warning on subclassing
b83cb01
feat(session): deprecate session repository interface
c14ac88
docs(session): use sdk deprecation docstring style
c94325f
docs(session): link migration guide from api docs
b38544d
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero ccf0cea
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero d4d5ea3
Merge remote-tracking branch 'origin/main' into agent-tasks/3663-sess…
901bd78
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero e3ae8b6
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero ee7c40b
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 27afc23
docs(session): accept stateful-model sessions in migration guard
08a641e
docs: steer remaining examples to SnapshotSessionManager
a8a2785
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero fcd85ab
docs(session): check migrated data through take_snapshot in guard
b4b5e69
test(site): expect migration guide in Sessions sidebar group
d8787c1
docs(session): scope the migration script to one session at a time
a9e7178
test(session): ignore deprecation warning in storage nudge test
a15da16
docs(session): clarify what the already-migrated error means
71d5edf
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 2b5fe1e
docs(session): keep agents stopped until cutover and clarify step 2
7811ffd
Merge branch 'main' into agent-tasks/3663-session-migration-guide
nicolas-m-romero 7b9ced7
docs: fix LangGraph highlights, course notice, and SessionManager note
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
160 changes: 160 additions & 0 deletions
160
site/src/content/docs/user-guide/sdk/agents/migrate-repository-sessions.mdx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| --- | ||
| title: Migrate repository-based sessions | ||
| description: "Migrate Python sessions from RepositorySessionManager, | ||
| FileSessionManager, or S3SessionManager to SnapshotSessionManager before v2.0.0." | ||
| languages: [python] | ||
| tags: [session-management, snapshots, state] | ||
| sourceLinks: | ||
| - path: strands-py/src/strands/session/repository_session_manager.py | ||
| - path: strands-py/src/strands/session/file_session_manager.py | ||
| - path: strands-py/src/strands/session/s3_session_manager.py | ||
| - path: strands-py/src/strands/session/snapshot_session_manager.py | ||
| - path: strands-py/src/strands/types/session.py | ||
| --- | ||
|
|
||
| The repository-based session managers are deprecated and will be removed in v2.0.0. | ||
| Use this guide to preserve existing session data when moving `RepositorySessionManager`, | ||
| `FileSessionManager`, or `S3SessionManager` sessions to `SnapshotSessionManager`. | ||
|
|
||
| For an overview of session persistence and snapshot behavior, see | ||
| [Session management](./session-management.mdx). | ||
|
|
||
| ## Decide whether to migrate | ||
|
|
||
| `SnapshotSessionManager` cannot read repository-format records. Reusing the same session | ||
| and agent IDs starts an empty snapshot session and leaves the source records unchanged. | ||
|
|
||
| If you do not need the existing data, start a new snapshot-backed session. To preserve the | ||
| data, restore each repository-format session through a live agent, then save the restored | ||
| state with `SnapshotSessionManager`. | ||
|
|
||
| ## Customize the procedure | ||
|
|
||
| Match the migrating agent to the production agent before restoring its state: | ||
|
|
||
| - **Storage**: Configure the repository-based source and snapshot target. The example | ||
| reads local records with `FileSessionManager` and writes to `LocalFileStorage`. For an | ||
| S3 source, use `S3SessionManager` and `S3Storage`. For a custom source, construct the | ||
| same `SessionRepository` implementation used by the application. | ||
| - **Identifiers**: Use the same `session_id` and `agent_id` for the source and target. | ||
| Migrate each agent ID in a session separately. | ||
| - **Conversation manager**: Use the same type and settings so the restored message offset | ||
| and compaction behavior match the production agent. | ||
| - **System prompt**: Pass the production system prompt. Repository-based managers do not | ||
| restore it, but the new snapshot records it. | ||
| - **Model and tools**: Recreate the production model, tools, and custom components that | ||
| affect agent initialization or restored behavior. | ||
|
|
||
| ## Review what restoration preserves | ||
|
|
||
| Attaching the repository-based manager to the temporary agent restores the persisted data | ||
| before the snapshot is created. This includes application state, conversation-manager | ||
| state, interrupt state, model state, and message history. | ||
|
|
||
| The restore also applies saved redactions and repairs incomplete tool-use pairs in the | ||
| history. A trailing orphan is repaired when the agent receives its next prompt. For a | ||
| stateful model, the manager restores model state instead of local messages because the | ||
| model provider manages conversation history server-side. | ||
|
|
||
| ## Protect existing data | ||
|
|
||
| Complete these checks before constructing a repository-based manager or writing a | ||
| snapshot: | ||
|
|
||
| - Validate every source `session_id` and `agent_id`. Repository-based managers create | ||
| empty records for unknown identifiers, so a typo changes the source store. | ||
| - Run the migration offline against a copy of the session store first. Do not race a live | ||
| agent that uses the same session. | ||
| - Stop if the target snapshot already exists. Keep the source records until you verify | ||
| that the snapshot restores correctly. | ||
|
|
||
| ## Migrate one local session | ||
|
|
||
| Attach the repository-based manager to a temporary agent, then capture the restored agent | ||
| with the snapshot manager. | ||
|
|
||
| :::caution | ||
| The script can complete even when its configuration does not match the production agent. | ||
| Complete the customization and data-protection checks above before running it. | ||
| ::: | ||
|
|
||
| ```python | ||
| import asyncio | ||
|
|
||
| from strands import Agent | ||
| from strands.session import FileSessionManager, SnapshotSessionManager | ||
| from strands.storage import LocalFileStorage | ||
|
|
||
| SYSTEM_PROMPT = "<your production system prompt>" | ||
|
|
||
|
|
||
| async def migrate_session(session_id: str, *, agent_id: str = "default") -> None: | ||
| """Migrate one repository-format session without overwriting the target.""" | ||
| snapshot = SnapshotSessionManager( | ||
| session_id=session_id, | ||
| storage=LocalFileStorage("./snapshot-sessions"), | ||
| ) | ||
|
|
||
| # Stop rather than overwrite an existing target snapshot. | ||
| if await snapshot.restore_snapshot(Agent(agent_id=agent_id)): | ||
| raise RuntimeError( | ||
| f"session={session_id!r} agent={agent_id!r} already migrated" | ||
| ) | ||
|
nicolas-m-romero marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Restore conversation-manager state, redactions, and message-history repairs. | ||
| source = FileSessionManager( | ||
| session_id=session_id, | ||
| storage_dir="./repository-sessions", | ||
| ) | ||
| agent = Agent( | ||
| agent_id=agent_id, | ||
| system_prompt=SYSTEM_PROMPT, | ||
| session_manager=source, | ||
| ) | ||
|
|
||
| if not agent.messages and not agent.state.get(): | ||
|
nicolas-m-romero marked this conversation as resolved.
Resolved
|
||
| raise ValueError( | ||
| f"no source data found for session={session_id!r} agent={agent_id!r}" | ||
| ) | ||
|
|
||
| # Write the snapshot restored during agent initialization. | ||
| await snapshot.save_snapshot(agent, is_latest=True) | ||
|
|
||
|
|
||
| asyncio.run(migrate_session("user-123")) | ||
| ``` | ||
|
|
||
| Save the script as `migrate_repository_session.py`, update its configuration, then run: | ||
|
|
||
| ```bash | ||
| python migrate_repository_session.py | ||
| ``` | ||
|
|
||
| ## Migrate and verify each session | ||
|
|
||
| - **Get the source session ID** from the existing agent or session manager. See | ||
| [Reading the session ID](./session-management.mdx#reading-the-session-id). | ||
| - **Migrate many sessions** by calling `migrate_session` per session and per `agent_id`. | ||
| Keep each call independent and idempotent so an interrupted run can resume. | ||
| - **Verify, then cut over:** | ||
| 1. Dry-run against a copy of the session store. | ||
| 2. Attach `SnapshotSessionManager` to a fresh agent with the same `session_id` and | ||
| `agent_id`. Compare `agent.messages`, `agent.state.get()`, `agent.system_prompt`, and | ||
| the conversation-manager state. | ||
| 3. Cut application code over to `SnapshotSessionManager`. | ||
| 4. Delete the source records only after verifying that the snapshot restores correctly. | ||
|
|
||
| ## Adapt unsupported session types | ||
|
|
||
| The single-agent `migrate_session()` example does not work for Graph or Swarm sessions. | ||
| It passes an `Agent` to `save_snapshot()`, while Graph and Swarm persistence captures the | ||
| orchestrator through its lifecycle hooks. There is no public one-shot conversion API. | ||
| Start a new snapshot-backed multi-agent session before v2.0.0. If you must preserve an | ||
| in-progress orchestrator state, remain on v1 and its repository-based manager until a | ||
| dedicated migration path is available. | ||
|
|
||
| `BidiAgent` requires a separate adaptation. Construct the equivalent stopped `BidiAgent` | ||
| and preserve its streaming configuration before calling `save_snapshot()`. After cutover, | ||
| `SnapshotSessionManager` saves Bidi state after each message by default, when the agent | ||
| stops, and before a connection restart. Configure this behavior with | ||
| `bidi_agent_save_latest_on`. | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.