8000 [FEATURE] Community-driven session management · Issue #57 · strands-agents/sdk-python · GitHub
[go: up one dir, main page]

Skip to content

[FEATURE] Community-driven session management #57

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
niklas-palm opened this issue May 20, 2025 · 2 comments
Open

[FEATURE] Community-driven session management #57

niklas-palm opened this issue May 20, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@niklas-palm
Copy link
niklas-palm commented May 20, 2025

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

@niklas-palm niklas-palm added the enhancement New feature or request label May 20, 2025
@niklas-palm niklas-palm changed the title [FEATURE] Middle-ware driven session management [FEATURE] Community-driven session management May 20, 2025
@zastrowm
Copy link
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.

@austinmw
Copy link

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

@awsarron awsarron assigned Unshure and unassigned zastrowm Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants
0