1+ /**
2+ * @file AgencyMemoryManager.ts
3+ * @description Manages shared RAG memory for Agency (multi-GMI) collectives.
4+ * Enables GMIs within an agency to share context, collaborate effectively,
5+ * and maintain collective memory across conversations.
6+ *
7+ * @module AgentOS/Agency
8+ * @version 1.0.0
9+ *
10+ * @example
11+ * ```typescript
12+ * const memoryManager = new AgencyMemoryManager(vectorStoreManager, logger);
13+ *
14+ * // Initialize shared memory for an agency
15+ * await memoryManager.initializeAgencyMemory(agencySession);
16+ *
17+ * // Ingest document to shared memory
18+ * await memoryManager.ingestToSharedMemory(agencyId, {
19+ * content: 'Important context from GMI-1',
20+ * contributorGmiId: 'gmi-1',
21+ * contributorRoleId: 'researcher',
22+ * });
23+ *
24+ * // Query shared memory
25+ * const results = await memoryManager.querySharedMemory(agencyId, {
26+ * query: 'What did the researcher find?',
27+ * requestingGmiId: 'gmi-2',
28+ * requestingRoleId: 'analyst',
29+ * });
30+ * ```
31+ */
32+ import type { ILogger } from '../../logging/ILogger' ;
33+ import type { IVectorStoreManager } from '../../core/vector-store/IVectorStoreManager' ;
34+ import type { AgencySession , AgencyMemoryConfig , AgencyMemoryOperationResult , AgencyMemoryQueryOptions } from './AgencyTypes' ;
35+ /**
36+ * Input for ingesting documents to agency shared memory.
37+ */
38+ export interface AgencyMemoryIngestInput {
39+ /** Document content */
40+ content : string ;
41+ /** GMI that contributed this content */
42+ contributorGmiId : string ;
43+ /** Role of the contributing GMI */
44+ contributorRoleId : string ;
45+ /** Document category */
46+ category ?: 'communication' | 'finding' | 'decision' | 'summary' | 'context' ;
47+ /** Additional metadata */
48+ metadata ?: Record < string , unknown > ;
49+ /** Optional pre-computed embedding */
50+ embedding ?: number [ ] ;
51+ }
52+ /**
53+ * Retrieved chunk from agency shared memory.
54+ */
55+ export interface AgencyMemoryChunk {
56+ /** Chunk ID */
57+ chunkId : string ;
58+ /** Document ID */
59+ documentId : string ;
60+ /** Content text */
61+ content : string ;
62+ /** Similarity score */
63+ score : number ;
64+ /** Contributing GMI */
65+ contributorGmiId : string ;
66+ /** Contributing role */
67+ contributorRoleId : string ;
68+ /** Document category */
69+ category : string ;
70+ /** Additional metadata */
71+ metadata ?: Record < string , unknown > ;
72+ }
73+ /**
74+ * Result of querying agency shared memory.
75+ */
76+ export interface AgencyMemoryQueryResult {
77+ /** Whether query succeeded */
78+ success : boolean ;
79+ /** Retrieved chunks */
80+ chunks : AgencyMemoryChunk [ ] ;
81+ /** Total matching results */
82+ totalResults : number ;
83+ /** Query processing time in ms */
84+ processingTimeMs : number ;
85+ /** Error message if failed */
86+ error ?: string ;
87+ }
88+ /**
89+ * Statistics for agency memory.
90+ */
91+ export interface AgencyMemoryStats {
92+ /** Total documents in shared memory */
93+ totalDocuments : number ;
94+ /** Total chunks */
95+ totalChunks : number ;
96+ /** Documents by role */
97+ documentsByRole : Record < string , number > ;
98+ /** Documents by category */
99+ documentsByCategory : Record < string , number > ;
100+ /** Last ingestion timestamp */
101+ lastIngestionAt ?: string ;
102+ }
103+ /**
104+ * Manages shared RAG memory for Agency collectives.
105+ *
106+ * @remarks
107+ * This manager provides:
108+ * - Initialization of dedicated data sources for agencies
109+ * - Ingestion with role-based access control
110+ * - Cross-GMI context queries with permission checks
111+ * - Memory lifecycle management (retention, eviction)
112+ *
113+ * Architecture:
114+ * ```
115+ * AgencyMemoryManager
116+ * │
117+ * ├─► VectorStoreManager (storage backend)
118+ * │
119+ * ├─► AgencyRegistry (session state)
120+ * │
121+ * └─► Per-Agency Collections
122+ * └─► agency-{agencyId}-shared
123+ * ```
124+ */
125+ export declare class AgencyMemoryManager {
126+ private readonly vectorStoreManager ;
127+ private readonly logger ?;
128+ /** Collection name prefix for agency shared memory */
129+ private static readonly COLLECTION_PREFIX ;
130+ /** Default memory configuration */
131+ private static readonly DEFAULT_CONFIG ;
132+ /** Tracks initialized agencies */
133+ private readonly initializedAgencies ;
134+ /**
135+ * Creates a new AgencyMemoryManager instance.
136+ *
137+ * @param vectorStoreManager - Vector store manager for RAG operations
138+ * @param logger - Optional logger for diagnostics
139+ */
140+ constructor ( vectorStoreManager : IVectorStoreManager | null , logger ?: ILogger | undefined ) ;
141+ /**
142+ * Initializes shared memory for an agency.
143+ * Creates dedicated collection and applies configuration.
144+ *
145+ * @param session - Agency session to initialize memory for
146+ * @returns Operation result
147+ */
148+ initializeAgencyMemory ( session : AgencySession ) : Promise < AgencyMemoryOperationResult > ;
149+ /**
150+ * Ingests a document to agency shared memory.
151+ *
152+ * @param agencyId - Target agency
153+ * @param input - Document to ingest
154+ * @param config - Agency memory configuration
155+ * @returns Operation result
156+ */
157+ ingestToSharedMemory ( agencyId : string , input : AgencyMemoryIngestInput , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryOperationResult > ;
158+ /**
159+ * Queries agency shared memory.
160+ *
161+ * @param agencyId - Target agency
162+ * @param options - Query options
163+ * @param config - Agency memory configuration
164+ * @returns Query result with retrieved chunks
165+ */
166+ querySharedMemory ( agencyId : string , options : AgencyMemoryQueryOptions , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryQueryResult > ;
167+ /**
168+ * Gets statistics for agency shared memory.
169+ *
170+ * @param agencyId - Target agency
171+ * @returns Memory statistics
172+ */
173+ getStats ( agencyId : string ) : Promise < AgencyMemoryStats | null > ;
174+ /**
175+ * Cleans up agency memory when agency is removed.
176+ *
177+ * @param agencyId - Agency to clean up
178+ * @returns Operation result
179+ */
180+ cleanupAgencyMemory ( agencyId : string ) : Promise < AgencyMemoryOperationResult > ;
181+ /**
182+ * Gets the collection ID for an agency's shared memory.
183+ */
184+ private getCollectionId ;
185+ /**
186+ * Resolves configuration with defaults.
187+ */
188+ private resolveConfig ;
189+ /**
190+ * Checks if agency memory is initialized.
191+ */
192+ isInitialized ( agencyId : string ) : boolean ;
193+ /**
194+ * Broadcasts context from one GMI to all others in the agency.
195+ * This is useful for sharing discoveries, decisions, or important updates.
196+ *
197+ * @param agencyId - Target agency
198+ * @param input - Broadcast input
199+ * @param config - Agency memory configuration
200+ * @returns Operation result with broadcast metadata
201+ *
202+ * @example
203+ * ```typescript
204+ * await memoryManager.broadcastToAgency(agencyId, {
205+ * content: 'Found critical security vulnerability in auth module',
206+ * senderGmiId: 'security-analyst-gmi',
207+ * senderRoleId: 'security-analyst',
208+ * broadcastType: 'finding',
209+ * priority: 'high',
210+ * });
211+ * ```
212+ */
213+ broadcastToAgency ( agencyId : string , input : {
214+ content : string ;
215+ senderGmiId : string ;
216+ senderRoleId : string ;
217+ broadcastType : 'finding' | 'decision' | 'update' | 'request' | 'alert' ;
218+ priority ?: 'low' | 'normal' | 'high' | 'critical' ;
219+ targetRoles ?: string [ ] ;
220+ metadata ?: Record < string , unknown > ;
221+ } , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryOperationResult > ;
222+ /**
223+ * Gets recent context contributions from specific roles.
224+ * Enables GMIs to selectively query context from collaborators.
225+ *
226+ * @param agencyId - Target agency
227+ * @param options - Query options with role filtering
228+ * @param config - Agency memory configuration
229+ * @returns Query result filtered by contributor roles
230+ *
231+ * @example
232+ * ```typescript
233+ * // Get recent findings from the researcher role
234+ * const findings = await memoryManager.getContextFromRoles(agencyId, {
235+ * fromRoles: ['researcher', 'analyst'],
236+ * categories: ['finding', 'summary'],
237+ * requestingGmiId: 'coordinator-gmi',
238+ * requestingRoleId: 'coordinator',
239+ * limit: 10,
240+ * });
241+ * ```
242+ */
243+ getContextFromRoles ( agencyId : string , options : {
244+ fromRoles : string [ ] ;
245+ categories ?: ( 'communication' | 'finding' | 'decision' | 'summary' | 'context' ) [ ] ;
246+ requestingGmiId : string ;
247+ requestingRoleId : string ;
248+ limit ?: number ;
249+ minScore ?: number ;
250+ } , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryQueryResult > ;
251+ /**
252+ * Shares a synthesis or summary across all GMIs in the agency.
253+ * Typically used by coordinator or synthesizer roles.
254+ *
255+ * @param agencyId - Target agency
256+ * @param summary - Summary content and metadata
257+ * @param config - Agency memory configuration
258+ * @returns Operation result
259+ */
260+ shareSynthesis ( agencyId : string , summary : {
261+ content : string ;
262+ synthesizerId : string ;
263+ synthesizerRoleId : string ;
264+ sourceRoles ?: string [ ] ;
265+ summaryType : 'interim' | 'final' | 'action_items' | 'consensus' ;
266+ metadata ?: Record < string , unknown > ;
267+ } , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryOperationResult > ;
268+ /**
269+ * Records a decision made by the agency for future reference.
270+ *
271+ * @param agencyId - Target agency
272+ * @param decision - Decision details
273+ * @param config - Agency memory configuration
274+ * @returns Operation result
275+ */
276+ recordDecision ( agencyId : string , decision : {
277+ content : string ;
278+ decisionMakerId : string ;
279+ decisionMakerRoleId : string ;
280+ decisionType : 'consensus' | 'delegation' | 'escalation' | 'resolution' ;
281+ affectedRoles ?: string [ ] ;
282+ rationale ?: string ;
283+ metadata ?: Record < string , unknown > ;
284+ } , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryOperationResult > ;
285+ /**
286+ * Gets all decisions made by the agency.
287+ *
288+ * @param agencyId - Target agency
289+ * @param options - Query options
290+ * @param config - Agency memory configuration
291+ * @returns Query result with decision chunks
292+ */
293+ getDecisions ( agencyId : string , options : {
294+ requestingGmiId : string ;
295+ requestingRoleId : string ;
296+ decisionTypes ?: ( 'consensus' | 'delegation' | 'escalation' | 'resolution' ) [ ] ;
297+ limit ?: number ;
298+ } , config ?: AgencyMemoryConfig ) : Promise < AgencyMemoryQueryResult > ;
299+ }
300+ //# sourceMappingURL=AgencyMemoryManager.d.ts.map
0 commit comments