TDAIMemory
Enterprise-grade cloud-based memory storage with TDAI services integration for production applications.
Import
import { TDAIMemory } from '@ag-kit/agents/storage' ;
Constructor
constructor ( options : TDAIMemoryOptions & IBaseMemoryOptions )
Configuration
options
TDAIMemoryOptions & IBaseMemoryOptions
required
TDAI Memory configuration options extending BaseMemory options Unique session identifier for event isolation
Pre-configured TDAI client instance
TDAI client configuration (required if client not provided) TDAI API key for authentication
Custom base URL for TDAI service
Request timeout in milliseconds
Number of retry attempts for failed requests
Enable local caching for performance optimization
Whether to automatically manage context (default: true if thresholds provided)
Token calculator instance (inherited from BaseMemory)
thresholds
Partial<ContextThresholds>
Context management thresholds (inherited from BaseMemory)
Custom summarization function (inherited from BaseMemory)
Note : Either client or clientOptions must be provided.
Basic Usage
// Initialize with TDAI credentials
const memory = new TDAIMemory ({
sessionId: 'user-session-123' ,
clientOptions: {
apiKey: 'your-tdai-api-key' ,
baseURL: 'https://api.tdai.tencent.com'
},
useCache: true ,
enableContextManagement: true
});
// Add and retrieve events
await memory . add ({
message: {
id: 'msg-1' ,
role: 'user' ,
content: 'Hello, I need help with my project' ,
timestamp: new Date ()
},
state: { userId: 'user-123' }
});
const events = await memory . list ({ limit: 10 , maxTokens: 4000 });
Core Interface Methods
TDAIMemory inherits from BaseMemory and implements all standard memory interface methods (branching not supported). For complete API documentation including list(), add(), addList(), delete(), retrieve(), clear(), getCount(), isEmpty(), see the BaseMemory API Reference .
Caching
// Enable caching for better performance
const cachedMemory = new TDAIMemory ({
sessionId: 'session-123' ,
clientOptions: { apiKey: 'your-key' },
useCache: true // Enables local caching
});
// Cache is automatically managed:
// - Populated on first read
// - Invalidated on write operations
// - Reduces API calls for repeated reads
Unique Features
Cloud Persistence : Automatic synchronization to TDAI cloud services
Cross-Device Access : Share sessions across multiple instances and devices
Enterprise Security : Built-in authentication and encryption
High Availability : Redundant cloud infrastructure
Local Caching : Optional performance optimization with cache invalidation
Production Scalability : Handles enterprise-scale deployments
Branching Limitations
TDAIMemory does not support session branching operations due to cloud service limitations.
Error Handling
try {
await memory . add ( event );
} catch ( error ) {
if ( error . code === 'TDAI_AUTH_ERROR' ) {
// Handle authentication issues
console . error ( 'Invalid API key or expired token' );
} else if ( error . code === 'TDAI_QUOTA_EXCEEDED' ) {
// Handle quota limits
console . error ( 'API quota exceeded' );
} else if ( error . code === 'TDAI_NETWORK_ERROR' ) {
// Handle network issues
console . error ( 'Network connectivity problem' );
}
}
Limitations
No Session Branching : Branching operations are not supported
Network Dependency : Requires internet connectivity for all operations
API Quotas : Subject to TDAI service usage limits
Latency : Network calls introduce latency compared to local storage
Cost : Usage-based pricing for cloud storage and API calls