LangGraph Plugin: Session
The FlotorchLanggraphSession provides comprehensive session management for LangGraph agents, enabling persistent storage of conversation history and agent state through FloTorch Gateway. It implements LangGraph’s BaseCheckpointSaver interface and stores conversation history as FloTorch session events, enabling persistent state management across agent interactions.
Prerequisites
Section titled “Prerequisites”Before using FlotorchLanggraphSession, ensure you have completed the general prerequisites outlined in the LangGraph Plugin Overview, including installation and environment configuration.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”Configure your session service with the following parameters:
FlotorchLanggraphSession( api_key: str, # FloTorch API key for authentication (required) base_url: str, # FloTorch Gateway endpoint URL (required) app_name: str, # Application name for session identification (required) user_id: str # User identifier for session identification (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)app_name- Application name for identifying sessionsuser_id- User identifier for isolating sessions per user
Features
Section titled “Features”BaseCheckpointSaver Interface
Section titled “BaseCheckpointSaver Interface”Fully implements LangGraph’s BaseCheckpointSaver interface:
- Checkpoint Operations - Supports checkpoint save and load operations
- State Persistence - Persists agent state and conversation history
- LangGraph Compatibility - Works seamlessly with LangGraph’s checkpoint 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 LangGraph and FloTorch formats
Thread Management
Section titled “Thread Management”Manages conversation threads for LangGraph agents:
- Thread Identification - Uses
thread_idin config for thread identification - State Management - Manages state per thread automatically
- Conversation Continuity - Maintains conversation continuity across interactions
Usage Example
Section titled “Usage Example”Basic Session Setup
Section titled “Basic Session Setup”from flotorch.langgraph.agent import FlotorchLangGraphAgentfrom flotorch.langgraph.sessions import FlotorchLanggraphSession
# Initialize session servicecheckpointer = FlotorchLanggraphSession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud", app_name="your_app", user_id="user_123")
# Use with agentagent_manager = FlotorchLangGraphAgent( agent_name="customer-support", checkpointer=checkpointer, # Add checkpointer base_url="https://gateway.flotorch.cloud", api_key="your_api_key")
agent = agent_manager.get_agent()
# Use with config for session persistenceconfig = {"configurable": {"thread_id": "your_thread_id"}}response = agent.invoke({"messages": user_input}, config)Session with Thread Management
Section titled “Session with Thread Management”from flotorch.langgraph.sessions import FlotorchLanggraphSession
# Initialize session servicecheckpointer = FlotorchLanggraphSession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud", app_name="your_app", user_id="user_123")
# Use with LangGraph agentfrom langgraph.prebuilt import create_react_agent
agent = create_react_agent( model=model, tools=tools, checkpointer=checkpointer)
# Use with config for session persistenceconfig = {"configurable": {"thread_id": "unique_thread_id"}}response = agent.invoke({"messages": user_input}, config)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
- Thread Identification - Use unique
thread_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