UNPKG

@codai/memorai-mcp

Version:

MemorAI CBD-based MCP Server - High-Performance Vector Memory System

286 lines 9.19 kB
/** * Phase 4.2: Cross-Agent Memory Federation Engine * * Revolutionary federated memory sharing and collective intelligence: * - Cross-agent memory sharing with permission controls * - Collective intelligence through shared insights * - Distributed memory optimization across agents * - Real-time collaboration and knowledge synchronization * - Federated learning and pattern sharing */ import OpenAI from 'openai'; import { AdvancedMemory } from './server.js'; export interface FederationResult { success: boolean; federationId: string; sharedMemoryIds: string[]; collaborationMetrics: CollaborationMetrics; synchronizationStatus: SynchronizationStatus; timestamp: string; } export interface SharingPermissions { accessLevel: 'read' | 'read-write' | 'admin'; expirationTime?: string; allowModification: boolean; allowDeletion: boolean; allowSharing: boolean; contextRestrictions?: string[]; projectRestrictions?: string[]; } export interface CollaborationMetrics { participantCount: number; memoryExchangeCount: number; insightGenerationRate: number; conflictResolutionRate: number; knowledgeSynthesisScore: number; collaborationEffectiveness: number; } export interface SynchronizationStatus { status: 'synced' | 'syncing' | 'conflict' | 'offline' | 'error'; lastSyncTime: string; pendingChanges: number; conflictCount: number; participantStatuses: Map<string, AgentSyncStatus>; } export interface AgentSyncStatus { agentId: string; status: 'online' | 'offline' | 'syncing' | 'error'; lastActivity: string; memoryCount: number; contributionScore: number; } export interface FederatedMemory extends AdvancedMemory { federationInfo: { isShared: boolean; originAgentId: string; sharedWith: string[]; permissions: Map<string, SharingPermissions>; shareHistory: ShareEvent[]; collectiveInsights?: CollectiveInsight[]; }; } export interface ShareEvent { timestamp: string; eventType: 'shared' | 'accessed' | 'modified' | 'revoked'; sourceAgentId: string; targetAgentId: string; details: string; } export interface CollectiveInsight { insightId: string; type: 'pattern_recognition' | 'knowledge_gap' | 'optimization_opportunity' | 'contradiction_detected'; description: string; contributingAgents: string[]; confidence: number; evidence: string[]; actionable: boolean; timestamp: string; } export interface CrossAgentKnowledge { knowledgeId: string; topic: string; contributingMemories: MemoryContribution[]; synthesizedInsight: string; confidence: number; applicableContexts: string[]; lastUpdated: string; } export interface MemoryContribution { memoryId: string; agentId: string; contributionType: 'primary' | 'supporting' | 'contradictory' | 'confirming'; relevanceScore: number; extractedContent: string; } export interface FederationPolicy { policyId: string; name: string; description: string; rules: PolicyRule[]; applicableAgents: string[]; priority: number; active: boolean; } export interface PolicyRule { ruleType: 'allow' | 'deny' | 'require_approval' | 'log_only'; condition: PolicyCondition; action: PolicyAction; exceptions?: string[]; } export interface PolicyCondition { memoryType?: string[]; agentRelationship?: 'same_project' | 'same_organization' | 'trusted' | 'any'; contentSensitivity?: 'public' | 'internal' | 'confidential' | 'restricted'; timeWindow?: { start: string; end: string; }; } export interface PolicyAction { actionType: string; parameters: Record<string, any>; notificationRequired: boolean; approvalRequired: boolean; } export interface CollectiveLearning { learningSessionId: string; participatingAgents: string[]; learningObjective: string; sharedPatterns: SharedPattern[]; collectiveInsights: CollectiveInsight[]; performanceMetrics: CollectivePerformanceMetrics; nextSessionSchedule?: string; } export interface SharedPattern { patternId: string; patternType: 'usage' | 'temporal' | 'contextual' | 'behavioral'; description: string; contributingAgents: string[]; strength: number; universality: number; applications: string[]; } export interface CollectivePerformanceMetrics { sessionDuration: number; patternsIdentified: number; insightsGenerated: number; crossAgentAgreement: number; knowledgeTransferRate: number; participantSatisfaction: number; } export interface FederatedQuery { queryId: string; requestingAgentId: string; query: string; targetAgents: string[]; queryType: 'search' | 'recommendation' | 'insight' | 'verification'; priority: 'low' | 'medium' | 'high' | 'urgent'; responseTimeout: number; aggregationMethod: 'union' | 'intersection' | 'weighted' | 'consensus'; } export interface FederatedQueryResult { queryId: string; results: AgentQueryResult[]; aggregatedResult: any; consensus: ConsensusMetrics; responseTime: number; participationRate: number; } export interface AgentQueryResult { agentId: string; result: any; confidence: number; responseTime: number; metadata: Record<string, any>; } export interface ConsensusMetrics { agreement: number; disagreement: number; uncertainty: number; reliabilityScore: number; } export interface KnowledgeGraph { graphId: string; nodes: KnowledgeNode[]; edges: KnowledgeEdge[]; clusters: KnowledgeCluster[]; globalMetrics: GraphMetrics; lastUpdated: string; } export interface KnowledgeNode { nodeId: string; nodeType: 'memory' | 'concept' | 'agent' | 'insight' | 'pattern'; content: any; agentId?: string; importance: number; connections: number; lastAccessed: string; } export interface KnowledgeEdge { edgeId: string; sourceNodeId: string; targetNodeId: string; relationshipType: string; strength: number; bidirectional: boolean; metadata: Record<string, any>; } export interface KnowledgeCluster { clusterId: string; theme: string; nodeIds: string[]; centralNodeId: string; cohesion: number; significance: number; } export interface GraphMetrics { totalNodes: number; totalEdges: number; density: number; centralityScores: Map<string, number>; clusterCount: number; averagePathLength: number; } export declare class MemoryFederationEngine { private openaiClient?; private memories; private learningEngine; private federationPolicies; private activeCollaborations; private knowledgeGraph; private agentConnections; constructor(openaiClient?: OpenAI, memories?: Map<string, AdvancedMemory>); /** * Share memory with another agent with specific permissions * Core federation capability for cross-agent collaboration */ shareMemoryWithAgent(sourceAgentId: string, targetAgentId: string, memoryId: string, permissions: SharingPermissions): Promise<FederationResult>; /** * Perform federated query across multiple agents * Distributed search and intelligence gathering */ performFederatedQuery(queryRequest: FederatedQuery): Promise<FederatedQueryResult>; /** * Generate collective insights from multiple agents * AI-powered knowledge synthesis across the federation */ generateCollectiveInsights(participatingAgents: string[], topic: string): Promise<CrossAgentKnowledge>; /** * Enable real-time collaborative learning across agents * Continuous knowledge sharing and improvement */ enableCollaborativeLearning(participatingAgents: string[], learningObjective: string): Promise<CollectiveLearning>; /** * Synchronize memories across federated agents * Ensures consistency and conflict resolution */ synchronizeFederatedMemories(participatingAgents: string[]): Promise<SynchronizationStatus>; private validateSharingRequest; private updateAgentConnections; private updateKnowledgeGraph; private calculateCollaborationMetrics; private createSynchronizationStatus; private initializeDefaultPolicies; private evaluatePolicyCondition; private executeAgentQuery; private aggregateQueryResults; private calculateConsensus; private gatherRelevantMemories; private analyzeMemoryPatterns; private generateInsightsFromPatterns; private determineContributionType; private calculateRelevanceScore; private extractRelevantContent; private calculateInsightConfidence; private identifyApplicableContexts; private getAgentUsagePatterns; private identifySharedPatterns; private generateCollectiveInsightsFromPatterns; private applyCollectiveLearning; private calculateCrossAgentAgreement; private calculateKnowledgeTransferRate; private scheduleNextLearningSession; private checkAgentSyncStatus; private resolveMemoryConflicts; } //# sourceMappingURL=federation-engine.d.ts.map