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:
- 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”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”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”External memory with FloTorch
Section titled “External memory with FloTorch”External Memory:
- Provides long-term persistent storage
- Backed by FloTorch Memory providers
- Supports user and application-scoped memories
- Enables knowledge retention across interactions
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”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.memory import FlotorchMemoryStoragefrom crewai.memory.external.external_memory import ExternalMemoryfrom crewai import Crew
# 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], 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 external memory for long-term knowledge retention; use CrewAI’s built-in options for short-term context as needed
- 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
- LLM Configuration - Configure language models for your memory-enabled agents