You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)defcreate_agent(system_prompt="You are a helpful assistant", messages=None):
returnAgent(system_prompt=system_prompt, messages=messagesor [])
@app.post("/chat/{user_id}")asyncdefchat_endpoint(user_id: str, request: ChatRequest):
# Create or restore agent using the user_id as the session IDagent=create_agent(
session_id=f"user:{user_id}",
system_prompt="You are a helpful AI assistant."
)
# Process message - state automatically saved to Redisresponse=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.
fromstrands.storageimportRedisStorage# Create agent with Redis persistenceagent=Agent(
system_prompt="You are a helpful assistant",
session_id="user123",
storage_provider=RedisStorage("redis://localhost:6379")
)
# Use normally - state automatically managedresponse=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:
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.
Uh oh!
There was an error while loading. Please reload this page.
Problem Statement
Currently, the Strands SDK requires developers to manually implement session persistence logic for agents. This presents several challenges:
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:
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:
Alternatives Solutions
Instead of decorators, one possible alternative solution would be to directly enhance the Agent class with built-in session management capabilities.
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:
Additional Context
No response
The text was updated successfully, but these errors were encountered: