Skip to content

Session persistence #302

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Unshure
Copy link
Member

@Unshure Unshure commented Jun 27, 2025

Description

This PR introduces a SessionManagement class to the Strands SDK that is in charge of persisting an agent to some datastore, and re-initializing the agent. The SessionManagement feature set includes:

  • Introduces an agent id attribute used as a unique id for differentiating agents

  • SessionManager: Interface for SessionManagers. This interface introduces a append_message_to_agent_session method that is called in the Agent class when adding a message to the agent messages array, as well as an initialize_agent class for initializing an agent

  • AgentSessionManager: Implementation of the above interface for persisting a single agent to some datastore. This will also re-initialize the agent's messages and state.

  • Session models: Three new models to represent different data types for session persistence:

    • Session: The overarching container to represent a strands agent, and in the future, multi-agent systems. One session can have many agents
    • SessionAgent: A persisted version of an agent, storing the agents state and messages
    • SessionMessage: A persisted version of a message
  • SessionDAO: DAO Interface with CRUDL operations for each of the above new models

  • FileSessionDAO: A implementation of the SessionDAO for storing a session in the local file system. This introduces the following directory and file structure to represent a Session:

    • <storage_dir>/session_<session_id>/
      • session.json # Stores session related data
      • agents/agent_<agent_id>/
        • agent.json # Stores agent related data
        • messages/messages_<message_id>.json # Stores message content
  • S3SessionDAO: Same as the above FileSessionDAO, but stores sessions in S3

Things that still need to be addressed:

  • all unit tests are vibe-coded, need to do a more thorough review
  • Integ tests
  • Update message after guardrail triggers
  • Order event files
  • Review docstrings (some seem to be out of date)
  • Add tests for EventLoopMetric ser/de
  • Respect created_at time for DAO Update methods

Changes for a follow-up pr:

  • Support ConversationManager refreshing (SummarizationConversationManager)

#246

Documentation PR

TODO:

Type of Change

New feature

Testing

How have you tested the change?

  • Vibecoded unit tests and local testing
  • Still needs:
    • Thorough review of unit tests
    • Integration tests

• [x] I ran hatch run prepare

Checklist

• [x] I have read the CONTRIBUTING document
• [x] I have added any necessary tests that prove my fix is effective or my feature works
• [ ] I have updated the documentation accordingly
• [ ] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
• [x] My changes generate no new warnings
• [x] Any dependent changes have been merged and published

Additional Notes:
N/A

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

AGENT = "AGENT"


@dataclass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will likely convert these to TypedDict classes. The main reason I had dataclass was for the lambda default_factory, but this introduces more complexity than its worth.

@Unshure Unshure force-pushed the session-persistence branch from 74d7ed6 to 3b81f1b Compare July 1, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: We're Working On It
Development

Successfully merging this pull request may close these issues.

1 participant