Overview
Understanding Compozy's memory system architecture, concepts, and design principles
What is Memory in Compozy?
Compozy's memory system provides persistent context storage for AI agents and workflows, enabling stateful conversations, data caching, and intelligent decision-making. The system supports multiple memory types and automatic lifecycle management to optimize both performance and cost.
Memory integrates seamlessly with agents to maintain conversation history, stores context between workflow executions, and supports dynamic memory allocation through YAML templates.
Core Features
Multiple Memory Types
Dynamic Key Templates
Automatic Lifecycle Management
Privacy & Security
Memory System Architecture
Memory System Components
Memory Manager
The central orchestrator that creates and retrieves memory instances based on resource configurations. Evaluates template expressions and manages the complete lifecycle of memory instances.
Template Engine
Enables dynamic memory keys through Go template syntax, supporting variables like {{.workflow.input.user_id}}
for user-specific and context-aware memory allocation.
Memory Instances
Individual memory containers that store conversation messages and context data. Each instance implements specific memory types with automatic cleanup and thread-safe operations.
Redis Storage
High-performance persistent storage layer providing fast key-value operations, atomic updates, TTL-based cleanup, and scalable multi-instance support.
Memory Types
Choose the right memory strategy based on your application needs and cost optimization requirements:
Optimized for LLM integration and cost management
resource: memory
id: conversation_memory
type: token_based
max_tokens: 4000
max_context_ratio: 0.8
- 1Smart Token Tracking
Automatically counts tokens in stored messages using the same tokenization as your LLM provider
- 2Context Window Optimization
Removes oldest messages when approaching model context limits, ensuring optimal performance
- 3Cost Management
Helps control API costs by maintaining token budgets and preventing expensive large context calls
- 4Configurable Strategies
Supports different flush strategies for memory management based on usage patterns
Ideal for: Chat applications, LLM integration, conversation history management, token budget optimization
Dynamic Key Templates
Create flexible memory organization using template expressions that adapt to workflow context and user data.
# User-specific memory for multi-tenant applications
key: "user:{{.workflow.input.user_id}}"
# Session-based memory for temporary contexts
key: "session:{{.session_id}}:conversation"
# Multi-level hierarchy for complex applications
key: "project:{{.project_id}}:agent:{{.agent_id}}"
# Context-aware memory with multiple dimensions
key: "tenant:{{.tenant_id}}:user:{{.user_id}}:chat:{{.chat_id}}"
- 1User Isolation
Separate memory instances per user for multi-tenant applications and data privacy
- 2Session Management
Temporary memory contexts that expire with user sessions
- 3Hierarchical Organization
Multi-level memory organization for complex application structures
- 4Context Awareness
Memory keys that adapt based on workflow context and runtime data
Lifecycle Management
Automatic memory management ensures optimal resource usage and data retention policies without manual intervention.
Privacy & Security
Built-in privacy controls and security measures protect sensitive data in memory instances.
Privacy Controls
Automatic PII redaction and privacy protection:
privacy:
enabled: true
redaction_patterns:
- name: "email"
pattern: "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b"
replacement: "[REDACTED:EMAIL]"
- name: "phone"
pattern: "\\b\\d{3}-\\d{3}-\\d{4}\\b"
replacement: "[REDACTED:PHONE]"
- 1Regex-based Redaction
Configurable patterns that automatically identify and redact sensitive information
- 2Custom Redaction Rules
Define application-specific patterns for industry-specific data protection needs
- 3Automatic PII Removal
Built-in patterns for common personally identifiable information types
- 4Secure Storage
Redacted data is stored securely with no way to reverse the redaction process
Security Best Practices
Essential security considerations for production deployments:
- 1Key Security
Avoid including sensitive information in memory keys - they may appear in logs and monitoring systems
- 2Appropriate TTL Settings
Set TTL values based on data sensitivity and compliance requirements for your industry
- 3Privacy Controls
Always enable privacy controls in production environments to prevent accidental PII exposure
- 4Access Controls
Implement proper access controls and authentication for memory instance access
- 5Monitoring & Auditing
Monitor memory access patterns and maintain audit logs for compliance requirements
Review the complete security guide for comprehensive protection strategies.
Agent Integration
Memory seamlessly integrates with agents to provide persistent context and conversation history.
agents:
- id: customer_support
memory:
- id: conversation_history
key: "support:{{.workflow.input.conversation_id}}"
- id: customer_profile
key: "customer:{{.workflow.input.customer_id}}"
- 1Context Persistence
Agents automatically access memory for conversation history and context continuity
- 2Multi-Memory Support
Agents can use multiple memory instances for different data types and contexts
- 3Dynamic Keys
Memory keys adapt to workflow context, enabling user-specific and session-based isolation
- 4Seamless Operations
Memory operations (read, append, clear, flush) are handled automatically by agents
Learn more about agent memory integration in the agent memory documentation.
Common Use Cases
Best Practices
- 1Hierarchical Naming
Use consistent patterns like
domain:entity:context
for clear organization and easy debugging - 2Unique Identifiers
Include necessary identifiers to ensure uniqueness across users, sessions, and contexts
- 3Avoid Sensitive Data
Never include sensitive information in keys - they may appear in logs and monitoring systems
- 4Keep Keys Short
Use reasonably short keys for better performance and reduced storage overhead
Related Documentation
Next Steps
TypeScript Development
Build sophisticated tools using TypeScript that extend your agents' capabilities. This guide covers development setup, best practices, and patterns for creating reliable, performant, and secure tools.
Memory Configuration
Complete guide to configuring memory resources for persistent agent context management, conversation continuity, and intelligent data retention