Skip to content

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.

Before using FlotorchStrandsSession, ensure you have completed the general prerequisites outlined in the Strands Plugin Overview, including installation and environment configuration.

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)

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

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

Integrates with Strands’ session management:

  • RepositorySessionManager - Works with RepositorySessionManager for standardized session management
  • Session Identification - Uses unique session_id to prevent conflicts
  • State Management - Manages state per session automatically
from flotorch.strands.agent import FlotorchStrandsAgent
from flotorch.strands.session import FlotorchStrandsSession
from strands.session.repository_session_manager import RepositorySessionManager
# Initialize session repository
repository = FlotorchStrandsSession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
# Create session manager
session_id = "your_session_id"
session_manager = RepositorySessionManager(
session_id=session_id,
session_repository=repository
)
# Use with agent
agent_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()
from flotorch.strands.session import FlotorchStrandsSession
from strands.session.repository_session_manager import RepositorySessionManager
from strands.agent.agent import Agent
# Initialize session repository
repository = FlotorchStrandsSession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
# Create session manager
session_id = "unique_session_id"
session_manager = RepositorySessionManager(
session_id=session_id,
session_repository=repository
)
# Use with Strands Agent
agent = Agent(
model=model,
tools=tools,
session_manager=session_manager
)
# Use agent for session persistence
response = agent(user_input)
  1. Environment Variables - Use environment variables for credentials to enhance security
  2. Session Management - Implement proper session lifecycle management for long-running applications
  3. Session Identification - Use unique session_id values to prevent conflicts between different conversations
  4. Error Handling - Implement robust error handling for network and storage operations
  5. Session Cleanup - Consider implementing session cleanup strategies for production environments