Strands Plugin: Session
The FlotorchStrandsSession provides comprehensive session management for Strands agents, enabling persistent storage of conversation history and agent state through FloTorch Gateway. It implements Strands’ session repository interface and stores conversation history as FloTorch session events, enabling persistent state management across agent interactions.
Prerequisites
Section titled “Prerequisites”Before using FlotorchStrandsSession, ensure you have completed the general prerequisites outlined in the Strands Plugin Overview, including installation and environment configuration.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”Configure your session service with the following parameters:
FlotorchStrandsSession( api_key: str, # FloTorch API key for authentication (required) base_url: str # FloTorch Gateway endpoint URL (required))Parameter Details:
api_key- Authentication key for accessing FloTorch Gateway (can be set via environment variable)base_url- The FloTorch Gateway endpoint URL (can be set via environment variable)
Features
Section titled “Features”Session Repository Interface
Section titled “Session Repository Interface”Fully implements Strands’ session repository interface:
- Repository Operations - Supports session save and load operations
- State Persistence - Persists agent state and conversation history
- Strands Compatibility - Works seamlessly with Strands’ session framework
Persistent Session Storage
Section titled “Persistent Session Storage”Provides comprehensive session persistence capabilities:
- Gateway Storage - Stores session data persistently in FloTorch Gateway
- Event History - Preserves complete event history across service restarts
- State Synchronization - Automatically synchronizes state management
- Format Conversion - Seamlessly converts events between Strands and FloTorch formats
Session Manager Integration
Section titled “Session Manager Integration”Integrates with Strands’ session management:
- RepositorySessionManager - Works with
RepositorySessionManagerfor standardized session management - Session Identification - Uses unique
session_idto prevent conflicts - State Management - Manages state per session automatically
Usage Example
Section titled “Usage Example”Basic Session Setup
Section titled “Basic Session Setup”from flotorch.strands.agent import FlotorchStrandsAgentfrom flotorch.strands.session import FlotorchStrandsSessionfrom strands.session.repository_session_manager import RepositorySessionManager
# Initialize session repositoryrepository = FlotorchStrandsSession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Create session managersession_id = "your_session_id"session_manager = RepositorySessionManager( session_id=session_id, session_repository=repository)
# Use with agentagent_manager = FlotorchStrandsAgent( agent_name="customer-support", session_manager=session_manager, # Add session manager base_url="https://gateway.flotorch.cloud", api_key="your_api_key")
agent = agent_manager.get_agent()Session with Agent
Section titled “Session with Agent”from flotorch.strands.session import FlotorchStrandsSessionfrom strands.session.repository_session_manager import RepositorySessionManagerfrom strands.agent.agent import Agent
# Initialize session repositoryrepository = FlotorchStrandsSession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Create session managersession_id = "unique_session_id"session_manager = RepositorySessionManager( session_id=session_id, session_repository=repository)
# Use with Strands Agentagent = Agent( model=model, tools=tools, session_manager=session_manager)
# Use agent for session persistenceresponse = agent(user_input)Best Practices
Section titled “Best Practices”- Environment Variables - Use environment variables for credentials to enhance security
- Session Management - Implement proper session lifecycle management for long-running applications
- Session Identification - Use unique
session_idvalues to prevent conflicts between different conversations - Error Handling - Implement robust error handling for network and storage operations
- Session Cleanup - Consider implementing session cleanup strategies for production environments
Next Steps
Section titled “Next Steps”- Agent Configuration - Learn how to configure agents with session management
- Memory Integration - Add memory capabilities alongside sessions
- LLM Configuration - Configure language models for your session-enabled agents