Skip to content

[FEATURE] Community-driven session management #57

@niklas-palm

Description

@niklas-palm

Problem Statement

Currently, the Strands SDK requires developers to manually implement session persistence logic for agents. This presents several challenges:

  • Developers must write boilerplate code to save and load agent state
  • Session management logic is tightly coupled with application code
  • No standardized approach for implementing different storage backends
  • Difficult for the community to share and reuse storage implementations
  • Increased cognitive load when managing complex applications with multiple agents

Docs for current strategy for saving and loading state

Proposed Solution

Decorator-Based Session Management

I propose implementing a decorator-based session persistence layer that:

  • Automatically handles saving and loading agent states
  • Provides an extensible interface for storage providers
  • Simplifies application code by separating concerns
  • Enables community contributions of storage backends

Use Case

Developers building chat applications need to persist conversations across page refreshes, server restarts, and user sessions. With the decorator approach, they can simply:

@redis_session_manager(redis_url="redis://localhost:6379", ttl=3600)
def create_agent(system_prompt="You are a helpful assistant", messages=None):
    return Agent(system_prompt=system_prompt, messages=messages or [])

@app.post("/chat/{user_id}")
async def chat_endpoint(user_id: str, request: ChatRequest):
    # Create or restore agent using the user_id as the session ID
    agent = create_agent(
        session_id=f"user:{user_id}",
        system_prompt="You are a helpful AI assistant."
    )
    
    # Process message - state automatically saved to Redis
    response = agent(request.message)
    
    return {"response": response}

Alternatives Solutions

Instead of decorators, one possible alternative solution would be to directly enhance the Agent class with built-in session management capabilities.

from strands.storage import RedisStorage

# Create agent with Redis persistence
agent = Agent(
    system_prompt="You are a helpful assistant",
    session_id="user123",
    storage_provider=RedisStorage("redis://localhost:6379")
)

# Use normally - state automatically managed
response = agent("Hello!")

It would couple the storage logic more with the core Agent class, but also allow for the community to add storage providers by implementing this interface:

class StorageProvider(ABC):
    @abstractmethod
    def session_exists(self, session_id): pass
    
    @abstractmethod
    def load_session(self, session_id): pass
    
    @abstractmethod
    def save_session(self, session_id, state): pass

Additional Context

No response

Activity

changed the title [-][FEATURE] Middle-ware driven session management[/-] [+][FEATURE] Community-driven session management[/+] on May 20, 2025
zastrowm

zastrowm commented on May 22, 2025

@zastrowm
Member

Thanks for the request and the use case!

The Strands team is actively looking into improving session management in the SDK. We don't have any updates to share yet, but our upcoming roadmap should provide more clarity on the timeline.

self-assigned this
on May 22, 2025
austinmw

austinmw commented on May 27, 2025

@austinmw

Would also like to request boilerplate functionality to load chat history by session_id for DynamoDB

added theissue type on May 27, 2025
assigned and unassigned on Jun 3, 2025
removed their assignment
on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Development

    No branches or pull requests

      Participants

      @zastrowm@Unshure@austinmw@niklas-palm

      Issue actions

        [FEATURE] Community-driven session management · Issue #57 · strands-agents/sdk-python