Skip to content

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

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

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 variable FLOTORCH_API_KEY)
  • base_url - The FloTorch Gateway endpoint URL (can be set via environment variable FLOTORCH_BASE_URL)

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

Seamlessly integrates with CrewAI’s short-term memory pattern:

  • ShortTermMemory Backend - Acts as the storage backend for CrewAI’s ShortTermMemory class
  • 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

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

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
from flotorch.crewai.sessions import FlotorchCrewAISession
from crewai.memory.short_term.short_term_memory import ShortTermMemory
from crewai import Crew
# Initialize session service
session_service = FlotorchCrewAISession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
# Create short-term memory with session storage
short_term_memory = ShortTermMemory(storage=session_service)
# Use with CrewAI Crew
crew = Crew(
agents=[agent],
tasks=[task],
short_term_memory=short_term_memory,
verbose=True
)
result = crew.kickoff()
from flotorch.crewai.sessions import FlotorchCrewAISession
from flotorch.crewai.agent import FlotorchCrewAIAgent
from crewai.memory.short_term.short_term_memory import ShortTermMemory
from crewai import Crew, Task
# Initialize session service
session_service = FlotorchCrewAISession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
# Create short-term memory
short_term_memory = ShortTermMemory(storage=session_service)
# Create multiple agents
researcher = 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()
  1. Environment Variables - Use environment variables for credentials to enhance security
  2. Session Management - Implement proper session lifecycle management for long-running applications
  3. Error Handling - Implement robust error handling for network and storage operations
  4. Multi-Agent Workflows - Leverage session persistence to maintain context across agent collaborations
  5. Memory Combination - Combine short-term memory (sessions) with external memory for comprehensive memory management