AutoGen Plugin: Session
The FlotorchAutogenSession provides comprehensive session management for AutoGen agents, enabling persistent storage of conversation history and session data through FloTorch Gateway. It seamlessly handles state management, event conversion, and persistent storage while maintaining compatibility with Microsoft AutoGen’s agent framework. It serves as short-term model context for conversational context.
Prerequisites
Section titled “Prerequisites”Before using FlotorchAutogenSession, ensure you have completed the general prerequisites outlined in the AutoGen Plugin Overview, including installation and environment configuration.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”Configure your session service with the following parameters:
FlotorchAutogenSession( 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”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 AutoGen and FloTorch formats
Short-Term Model Context
Section titled “Short-Term Model Context”Serves as AutoGen’s model context for short-term conversational context:
- Conversation History - Maintains conversation history for the current session
- Context Management - Provides context for model interactions
- Automatic Updates - Automatically updates context as conversations progress
Event Handling
Section titled “Event Handling”Automatically manages event processing and conversion:
- Event Conversion - Converts between AutoGen and FloTorch event formats
- Message Handling - Handles text messages and tool responses
- State Management - Manages session state throughout the conversation
- Persistence - Ensures events are persisted to FloTorch Gateway
Usage Example
Section titled “Usage Example”Basic Session Setup
Section titled “Basic Session Setup”from flotorch.autogen.agent import FlotorchAutogenAgentfrom flotorch.autogen.sessions import FlotorchAutogenSession
# Initialize session servicesession_memory = FlotorchAutogenSession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Use with agent as model contextagent_manager = FlotorchAutogenAgent( agent_name="customer-support", model_context=session_memory, # Short-term context base_url="https://gateway.flotorch.cloud", api_key="your_api_key")
agent = agent_manager.get_agent()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
- 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