CrewAI Plugin: Session
The FlotorchCrewAISession provides comprehensive session management for CrewAI 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 CrewAI’s dual-memory pattern and multi-agent framework.
Session Management Features:
- Persistent Storage - Session data stored in FloTorch Gateway for conversation continuity
- Short-Term Memory Backend - Acts as storage backend for CrewAI’s
ShortTermMemory - Multi-Agent Support - Handles session state across multiple agents in a Crew
- Automatic State Management - Manages conversation state and context automatically
Prerequisites
Section titled “Prerequisites”Before using FlotorchCrewAISession, ensure you have completed the general prerequisites outlined in the CrewAI Plugin Overview, including installation and environment configuration.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”Configure your session service with the following parameters:
FlotorchCrewAISession( 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 variableFLOTORCH_API_KEY)base_url- The FloTorch Gateway endpoint URL (can be set via environment variableFLOTORCH_BASE_URL)
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 CrewAI and FloTorch formats
Short-Term Memory Integration
Section titled “Short-Term Memory Integration”Seamlessly integrates with CrewAI’s short-term memory pattern:
- ShortTermMemory Backend - Acts as the storage backend for CrewAI’s
ShortTermMemoryclass - Conversation Context - Maintains recent conversation history within a session
- Automatic Management - Handles session lifecycle and state management automatically
- Multi-Turn Support - Preserves context across multiple conversation turns
Multi-Agent Session Management
Section titled “Multi-Agent Session Management”Designed for CrewAI’s multi-agent workflows:
- Crew-Level Sessions - Manages sessions at the Crew level for multi-agent interactions
- Agent State Tracking - Tracks state across multiple agents in a Crew
- Task Context - Maintains context for task-based agent workflows
- Collaboration State - Preserves state when agents collaborate on tasks
Event Handling
Section titled “Event Handling”Automatically manages event processing and conversion:
- Event Conversion - Converts between CrewAI and FloTorch event formats
- Tool Call Management - Handles tool call execution and responses
- Function Responses - Processes function call results
- State Deltas - Applies state changes incrementally
Usage Example
Section titled “Usage Example”Basic Session Setup
Section titled “Basic Session Setup”from flotorch.crewai.sessions import FlotorchCrewAISessionfrom crewai.memory.short_term.short_term_memory import ShortTermMemoryfrom crewai import Crew
# Initialize session servicesession_service = FlotorchCrewAISession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Create short-term memory with session storageshort_term_memory = ShortTermMemory(storage=session_service)
# Use with CrewAI Crewcrew = Crew( agents=[agent], tasks=[task], short_term_memory=short_term_memory, verbose=True)
result = crew.kickoff()Session with Multi-Agent Crew
Section titled “Session with Multi-Agent Crew”from flotorch.crewai.sessions import FlotorchCrewAISessionfrom flotorch.crewai.agent import FlotorchCrewAIAgentfrom crewai.memory.short_term.short_term_memory import ShortTermMemoryfrom crewai import Crew, Task
# Initialize session servicesession_service = FlotorchCrewAISession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Create short-term memoryshort_term_memory = ShortTermMemory(storage=session_service)
# Create multiple agentsresearcher = FlotorchCrewAIAgent( agent_name="researcher", base_url="https://gateway.flotorch.cloud", api_key="your_api_key").get_agent()
writer = FlotorchCrewAIAgent( agent_name="writer", base_url="https://gateway.flotorch.cloud", api_key="your_api_key").get_agent()
# Use with Crew (session persists across all agents)crew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], short_term_memory=short_term_memory, verbose=True)
result = crew.kickoff()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
- Multi-Agent Workflows - Leverage session persistence to maintain context across agent collaborations
- Memory Combination - Combine short-term memory (sessions) with external memory for comprehensive memory management
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