@shinyaz

Strands Agents SDK Practical — Persist Conversations with Session Management

Table of Contents

Introduction

In Part 4 of the intro series, we learned that conversations continue when you keep talking to the same agent instance. But those conversations only exist in memory. Kill the process and they're gone.

Adding FileSessionManager is all it takes to save conversations to files and restore them after restarts.

In this article, we'll try:

  1. Save with FileSessionManager — Persist conversations to local files
  2. Restore after process restart — Restore the same session from a different process
  3. Examine stored data — Inspect the directory structure and JSON files
  4. Switch to S3SessionManager — Migration path to cloud storage

See the official documentation at Session Management.

Setup

Use the same environment from Part 1. All examples use the same model configuration and can be run as independent .py files. Write the common setup at the top, then add each example's code below it.

Python (common setup)
from strands import Agent
from strands.models import BedrockModel
from strands.session.file_session_manager import FileSessionManager
 
bedrock_model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
    region_name="us-east-1",
)

Saving Conversations with FileSessionManager

Specify a session_id and storage directory in FileSessionManager, then pass it to Agent.

01_save.py
session_manager = FileSessionManager(
    session_id="user-123",
    storage_dir="./sessions",
)
 
agent = Agent(
    model=bedrock_model,
    session_manager=session_manager,
    callback_handler=None,
)
 
result1 = agent("My name is Taro. I'm learning Strands Agents SDK.")
print(f"Agent: {result1.message['content'][0]['text'][:80]}...")
print(f"Messages: {len(agent.messages)}")
 
result2 = agent("What is my name?")
print(f"Agent: {result2.message['content'][0]['text'][:80]}...")
print(f"Messages: {len(agent.messages)}")
01_save.py full code (copy-paste)
01_save.py
from strands import Agent
from strands.models import BedrockModel
from strands.session.file_session_manager import FileSessionManager
 
bedrock_model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
    region_name="us-east-1",
)
 
session_manager = FileSessionManager(session_id="user-123", storage_dir="./sessions")
agent = Agent(model=bedrock_model, session_manager=session_manager, callback_handler=None)
 
result1 = agent("My name is Taro. I'm learning Strands Agents SDK.")
print(f"Agent: {result1.message['content'][0]['text'][:80]}...")
print(f"Messages: {len(agent.messages)}")
 
result2 = agent("What is my name?")
print(f"Agent: {result2.message['content'][0]['text'][:80]}...")
print(f"Messages: {len(agent.messages)}")
Terminal
python -u 01_save.py

Result

Output
Agent: Hello Taro! Nice to meet you. I'd be happy to help you learn about Strands Agent...
Messages: 2
Agent: Your name is Taro, as you mentioned in your first message....
Messages: 4

Same multi-turn conversation as Part 4 of the intro series, but now the conversation is automatically saved to the ./sessions directory.

Restoring After Process Restart

The real value of session management is that conversations survive process termination. Create an agent with the same session_id in a different script (= different process) to verify restoration.

02_restore.py
session_manager = FileSessionManager(
    session_id="user-123",
    storage_dir="./sessions",
)
 
agent = Agent(
    model=bedrock_model,
    session_manager=session_manager,
    callback_handler=None,
)
 
print(f"Restored messages: {len(agent.messages)}")
 
result = agent("What is my name and what am I learning?")
print(f"Agent: {result.message['content'][0]['text']}")
print(f"Messages after: {len(agent.messages)}")
02_restore.py full code (copy-paste)
02_restore.py
from strands import Agent
from strands.models import BedrockModel
from strands.session.file_session_manager import FileSessionManager
 
bedrock_model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
    region_name="us-east-1",
)
 
session_manager = FileSessionManager(session_id="user-123", storage_dir="./sessions")
agent = Agent(model=bedrock_model, session_manager=session_manager, callback_handler=None)
 
print(f"Restored messages: {len(agent.messages)}")
 
result = agent("What is my name and what am I learning?")
print(f"Agent: {result.message['content'][0]['text']}")
print(f"Messages after: {len(agent.messages)}")
Terminal
python -u 02_restore.py

Result

Output
Restored messages: 4
Agent: Your name is Taro and you're learning Strands Agents SDK.
Messages after: 6

The existing session is automatically restored when session_manager is passed to the Agent constructor. Four messages (2 turns) were restored, and the agent remembers the previous conversation.

No special restore code needed. Just specify the same session_id.

Examining Stored Data

Let's look inside the ./sessions directory.

Directory structure
sessions/
└── session_user-123/
    ├── session.json
    └── agents/
        └── agent_default/
            ├── agent.json
            └── messages/
                ├── message_0.json
                ├── message_1.json
                ├── message_2.json
                └── message_3.json
  • session.json — Session metadata (session_id, timestamps)
  • agent.json — Agent state (agent_id defaults to default)
  • messages/ — Each message saved as an individual JSON file

The contents of session.json:

session.json
{
    "session_id": "user-123",
    "session_type": "AGENT",
    "created_at": "2026-03-27T15:21:31.179132+00:00",
    "updated_at": "2026-03-27T15:21:31.179145+00:00"
}

Messages are automatically appended to files each time agent() is called. No explicit "save" call needed.

Switching to S3SessionManager

For production or multi-instance deployments, you'll want S3 instead of local files. The code change is minimal.

Python
from strands.session.s3_session_manager import S3SessionManager
 
session_manager = S3SessionManager(
    session_id="user-123",
    bucket="my-agent-sessions",
    prefix="production/",
    region_name="us-east-1",
)
 
agent = Agent(model=bedrock_model, session_manager=session_manager)

Replace FileSessionManager with S3SessionManager and swap storage_dir for bucket and prefix. The agent code doesn't change at all.

For S3, you'll need these IAM permissions:

  • s3:PutObject — Create and update session data
  • s3:GetObject — Retrieve session data
  • s3:DeleteObject — Delete session data
  • s3:ListBucket — List objects in the bucket

Summary

  • Just add FileSessionManager to persist conversations — Specify a session_id and pass it to the agent. The SDK manages save timing automatically.
  • Same session_id restores the session — Even from a different process, specifying the same session_id automatically restores past conversations. No special restore code needed.
  • Messages are saved as individual JSON files — Under session_<id>/agents/agent_default/messages/, each message is stored as an independent file.
  • Switching to S3 is just a class name change — Replace FileSessionManager with S3SessionManager. The agent code stays the same.

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.

Related Posts