toto-agent
Version:
Chatbot agent and reusable components for Toto platform
82 lines (81 loc) • 2.32 kB
TypeScript
import { UserAction, AgentType } from '../../shared/AgentTypes';
interface VectorEmbedding {
vector: number[];
content: string;
timestamp: Date;
metadata?: {
intent?: UserAction;
agentType?: AgentType;
confidence?: number;
};
}
interface ConversationTurn {
role: 'user' | 'assistant';
content: string;
timestamp: Date;
metadata?: {
intent?: UserAction;
agentType?: AgentType;
confidence?: number;
};
embedding?: VectorEmbedding;
}
export declare class ConversationMemoryService {
private genAI;
private memoryCache;
private readonly MAX_RECENT_TURNS;
private readonly SUMMARIZATION_THRESHOLD;
private readonly MAX_CACHE_SIZE;
private readonly EMBEDDING_MODEL;
constructor(apiKey: string);
/**
* Generate embeddings for text content
*/
private generateEmbedding;
/**
* Calculate cosine similarity between two vectors
*/
private cosineSimilarity;
/**
* Store a new conversation turn and manage memory
*/
storeTurn(conversationId: string, role: 'user' | 'assistant', content: string, metadata?: ConversationTurn['metadata'], userId?: string): Promise<void>;
/**
* Store embedding in Firestore for vector search
*/
private storeEmbeddingInFirestore;
/**
* Get enhanced context for intent analysis
*/
getEnhancedContext(conversationId: string): {
conversationHistory: ConversationTurn[];
conversationSummary?: string;
relevantPastTurns?: ConversationTurn[];
};
/**
* Rolling summarization implementation
*/
private summarizeConversation;
/**
* Search for relevant past conversations using vector embeddings
*/
searchRelevantHistory(conversationId: string, query: string, limit?: number): Promise<ConversationTurn[]>;
/**
* Detect if conversation is primarily in Spanish
*/
private detectSpanish;
/**
* Clean up old conversations from cache
*/
private cleanupCache;
/**
* Get memory statistics for monitoring
*/
getMemoryStats(): {
totalConversations: number;
averageTurnsPerConversation: number;
summarizedConversations: number;
cacheSize: number;
};
}
export {};