Skip to content

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 FlotorchCrewAISession for conversation context
  • ExternalMemory - Backed by FlotorchMemoryStorage for 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.

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

from flotorch.crewai.sessions import FlotorchCrewAISession
from crewai.memory.short_term.short_term_memory import ShortTermMemory
# Initialize short-term memory storage
short_term_storage = FlotorchCrewAISession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
# Create short-term memory
short_term_memory = ShortTermMemory(storage=short_term_storage)
from flotorch.crewai.memory import FlotorchMemoryStorage
from 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 memory
external_memory = ExternalMemory(storage=external_storage)
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 - FloTorch Gateway endpoint URL (can be set via environment variable FLOTORCH_BASE_URL)
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 Console
  • user_id - User identifier for attributing memories to specific users
  • app_id - Application identifier for organizing memories by application context

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

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

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
from flotorch.crewai.sessions import FlotorchCrewAISession
from flotorch.crewai.memory import FlotorchMemoryStorage
from crewai.memory.short_term.short_term_memory import ShortTermMemory
from crewai.memory.external.external_memory import ExternalMemory
from crewai import Crew
# Initialize short-term memory
short_term_storage = FlotorchCrewAISession(
api_key="your_api_key",
base_url="https://gateway.flotorch.cloud"
)
short_term_memory = ShortTermMemory(storage=short_term_storage)
# Initialize external memory
external_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 Crew
crew = Crew(
agents=[agent],
tasks=[task],
short_term_memory=short_term_memory,
external_memory=external_memory,
verbose=True
)
result = crew.kickoff()
from flotorch.crewai.agent import FlotorchCrewAIAgent
from flotorch.crewai.memory import FlotorchMemoryStorage
from crewai.memory.external.external_memory import ExternalMemory
from crewai import Crew
# Create agent with memory enabled
agent_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 storage
external_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 Crew
crew = Crew(
agents=[agent],
tasks=[task],
external_memory=external_memory,
verbose=True
)
result = crew.kickoff()
  1. Memory Provider Setup - Always configure memory providers in FloTorch Console before using them in code
  2. Memory Type Selection - Use short-term memory for conversation context and external memory for long-term knowledge retention
  3. User and App IDs - Always provide meaningful user_id and app_id values for proper memory attribution
  4. Error Handling - Implement proper error handling for memory operations in production environments
  5. Memory Scope - Use appropriate memory scoping to avoid memory leaks and ensure proper cleanup
  6. Multi-Agent Memory - Consider memory sharing strategies when multiple agents need access to the same information
  7. Memory Performance - Monitor memory search performance and optimize queries for better response times
  8. Memory Cleanup - Implement proper memory cleanup strategies for long-running applications