CrewAI Plugin: Memory
FloTorch CrewAI Memory services enable persistent memory capabilities for your agents, allowing them to store and retrieve information across sessions. The memory system integrates seamlessly with CrewAI’s dual-memory pattern and provides both short-term and long-term memory implementations to suit different use cases.
Available Memory Types:
- ShortTermMemory - Backed by
FlotorchCrewAISessionfor conversation context - ExternalMemory - Backed by
FlotorchMemoryStoragefor long-term persistent storage
Important: Memory services require prior setup in the FloTorch Console. Memory capabilities are not built-in and must be explicitly configured.
Prerequisites
Section titled “Prerequisites”Before using FloTorch CrewAI Memory services, ensure you have completed the general prerequisites outlined in the CrewAI Plugin Overview, including installation and environment configuration.
Quick Setup
Section titled “Quick Setup”Short-Term Memory (Conversation Context)
Section titled “Short-Term Memory (Conversation Context)”from flotorch.crewai.sessions import FlotorchCrewAISessionfrom crewai.memory.short_term.short_term_memory import ShortTermMemory
# Initialize short-term memory storageshort_term_storage = FlotorchCrewAISession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")
# Create short-term memoryshort_term_memory = ShortTermMemory(storage=short_term_storage)External Memory (Long-Term Persistence)
Section titled “External Memory (Long-Term Persistence)”from flotorch.crewai.memory import FlotorchMemoryStoragefrom crewai.memory.external.external_memory import ExternalMemory
# Initialize external memory storage (requires prior registration in FloTorch Console)external_storage = FlotorchMemoryStorage( api_key="your_api_key", base_url="https://gateway.flotorch.cloud", name="your-memory-provider", # Memory provider name from FloTorch Console user_id="user_123", app_id="app_123")
# Create external memoryexternal_memory = ExternalMemory(storage=external_storage)Configuration
Section titled “Configuration”FlotorchCrewAISession Parameters
Section titled “FlotorchCrewAISession 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- FloTorch Gateway endpoint URL (can be set via environment variableFLOTORCH_BASE_URL)
FlotorchMemoryStorage Parameters
Section titled “FlotorchMemoryStorage Parameters”FlotorchMemoryStorage( api_key: str, # FloTorch API key for authentication (required) base_url: str, # FloTorch Gateway endpoint URL (required) name: str, # Memory provider name from FloTorch Console (required) user_id: str, # User identifier for memory attribution (required) app_id: str # Application identifier for memory attribution (required))Parameter Details:
api_key- Authentication key for accessing FloTorch Gateway (can be set via environment variable)base_url- FloTorch Gateway endpoint URL (can be set via environment variable)name- The name of the memory provider configured in FloTorch Consoleuser_id- User identifier for attributing memories to specific usersapp_id- Application identifier for organizing memories by application context
Features
Section titled “Features”Dual-Memory Pattern
Section titled “Dual-Memory Pattern”CrewAI’s dual-memory pattern provides two distinct memory layers:
Short-Term Memory:
- Maintains conversation context within a session
- Backed by FloTorch Sessions for persistence
- Automatically manages recent conversation history
- Ideal for maintaining context during multi-turn conversations
External Memory:
- Provides long-term persistent storage
- Backed by FloTorch Memory providers
- Supports user and application-scoped memories
- Enables knowledge retention across sessions
Automatic Content Extraction
Section titled “Automatic Content Extraction”Memory services provide automatic conversation management:
- Content Extraction - Automatically extracts content from CrewAI conversations
- Role Mapping - Converts CrewAI roles to FloTorch-compatible formats
- Metadata Storage - Stores conversations with associated metadata
- Tool Call Handling - Manages tool calls and responses within memory
- Multi-Agent Context - Preserves context across multiple agents in a Crew
- Task-Based Memory - Maintains memory context for task-based workflows
Search Capabilities
Section titled “Search Capabilities”Short-Term Memory Search:
- Session-Based Retrieval - Retrieves conversation history from current session
- Context Preservation - Maintains conversation flow and context
- Automatic Management - Handles session lifecycle automatically
External Memory Search:
- Keyword-Based Search - Performs traditional text-based searches
- User/App Filtering - Filters results by user ID and application name
- Metadata Filtering - Supports custom metadata filtering
- Date Range Queries - Allows filtering by time ranges
- Relevance Scoring - Returns results with relevance scores for ranking
- Pagination Support - Supports paginated results for large memory sets
Usage Example
Section titled “Usage Example”Basic Memory Setup
Section titled “Basic Memory Setup”from flotorch.crewai.sessions import FlotorchCrewAISessionfrom flotorch.crewai.memory import FlotorchMemoryStoragefrom crewai.memory.short_term.short_term_memory import ShortTermMemoryfrom crewai.memory.external.external_memory import ExternalMemoryfrom crewai import Crew
# Initialize short-term memoryshort_term_storage = FlotorchCrewAISession( api_key="your_api_key", base_url="https://gateway.flotorch.cloud")short_term_memory = ShortTermMemory(storage=short_term_storage)
# Initialize external memoryexternal_storage = FlotorchMemoryStorage( api_key="your_api_key", base_url="https://gateway.flotorch.cloud", name="your-memory-provider", user_id="user_123", app_id="app_123")external_memory = ExternalMemory(storage=external_storage)
# Use with CrewAI Crewcrew = Crew( agents=[agent], tasks=[task], short_term_memory=short_term_memory, external_memory=external_memory, verbose=True)
result = crew.kickoff()Memory with Agent Integration
Section titled “Memory with Agent Integration”from flotorch.crewai.agent import FlotorchCrewAIAgentfrom flotorch.crewai.memory import FlotorchMemoryStoragefrom crewai.memory.external.external_memory import ExternalMemoryfrom crewai import Crew
# Create agent with memory enabledagent_manager = FlotorchCrewAIAgent( agent_name="customer-support", enable_memory=True, # Enables memory tools (preload/search) base_url="https://gateway.flotorch.cloud", api_key="your_api_key")
agent = agent_manager.get_agent()
# Add external memory for long-term storageexternal_storage = FlotorchMemoryStorage( api_key="your_api_key", base_url="https://gateway.flotorch.cloud", name="customer-support-memory", user_id="user_123", app_id="app_123")external_memory = ExternalMemory(storage=external_storage)
# Use with Crewcrew = Crew( agents=[agent], tasks=[task], external_memory=external_memory, verbose=True)
result = crew.kickoff()Best Practices
Section titled “Best Practices”- Memory Provider Setup - Always configure memory providers in FloTorch Console before using them in code
- Memory Type Selection - Use short-term memory for conversation context and external memory for long-term knowledge retention
- User and App IDs - Always provide meaningful
user_idandapp_idvalues for proper memory attribution - Error Handling - Implement proper error handling for memory operations in production environments
- Memory Scope - Use appropriate memory scoping to avoid memory leaks and ensure proper cleanup
- Multi-Agent Memory - Consider memory sharing strategies when multiple agents need access to the same information
- Memory Performance - Monitor memory search performance and optimize queries for better response times
- Memory Cleanup - Implement proper memory cleanup strategies for long-running applications
Next Steps
Section titled “Next Steps”- Agent Configuration - Learn how to configure agents with memory capabilities
- Session Management - Implement session persistence alongside memory
- LLM Configuration - Configure language models for your memory-enabled agents