1
- import dotenv from "dotenv" ;
1
+ import * as dotenv from "dotenv" ;
2
2
const de = dotenv . config ( ) ;
3
3
console . log ( "DEBUG" , de )
4
4
@@ -49,6 +49,8 @@ import {
49
49
stringToUuid ,
50
50
getEmbeddingZeroVector ,
51
51
composeActionExamples ,
52
+ MemoryManager ,
53
+ IMemoryManager ,
52
54
// validateCharacterConfig,
53
55
} from "@elizaos/core" ;
54
56
//import { defaultCharacter } from "./defaultCharacter.ts";
@@ -129,6 +131,7 @@ Response format should be formatted in a JSON block like this:
129
131
// import { TypeScriptParser } from "../TypeScriptParser.js";
130
132
// This is the retriever we will use in RAG
131
133
import { CodeFormatter } from "./utils/CodeFormatter.js" ;
134
+ import { run } from "node:test" ;
132
135
//import { CustomErrorParams, InputTypeOfTupleWithRest, IssueData, OutputTypeOfTupleWithRest, ParseParams, ParsePathComponent, ParseStatus, RefinementCtx, RefinementEffect, SafeParseReturnType, z, ZodBranded, ZodCatch, ZodCustomIssue, ZodDefault, ZodEffects, ZodError, ZodIntersection, ZodInvalidArgumentsIssue, ZodInvalidDateIssue, ZodInvalidEnumValueIssue, ZodInvalidIntersectionTypesIssue, ZodInvalidLiteralIssue, ZodInvalidReturnTypeIssue, ZodInvalidStringIssue, ZodInvalidUnionDiscriminatorIssue, ZodInvalidUnionIssue, ZodIssueBase, ZodIssueCode, ZodNotFiniteIssue, ZodNotMultipleOfIssue, ZodOptionalDef, ZodParsedType, ZodPipeline, ZodPromise, ZodReadonly, ZodTooBigIssue, ZodTooSmallIssue, ZodTupleDef, ZodUnion, ZodUnrecognizedKeysIssue } from "zod";
133
136
//import { StructuredToolInterface, StructuredToolParams } from "@langchain/core/tools.js";
134
137
//import { ToolChoice } from "@langchain/core/language_models/chat_models.js";
@@ -175,9 +178,10 @@ export class AIService {
175
178
private chatModel : ChatWrapper ; //<ChatOpenAICallOptions>
176
179
private codeFormatter : CodeFormatter ;
177
180
private chatModelFAQ : ChatWrapper ; // <ChatOpenAICallOptions>
178
- //runtime: AgentRuntime;
181
+
179
182
private agents : Map < string , IAgentRuntime > ; // container management
180
183
runtime : AgentRuntime ;
184
+ knowledgeManager : IMemoryManager ;
181
185
182
186
/**
183
187
* Constructor for initializing the ChatOpenAI instance.
@@ -213,51 +217,36 @@ export class AIService {
213
217
// this.chatModelFAQ = new FakeListChatModel({ responses: [] });
214
218
this . codeFormatter = new CodeFormatter ( ) ;
215
219
220
+
221
+
216
222
this . agents = new Map ( ) ;
217
223
const token = "token" ;
218
224
const character = defaultCharacter ;
225
+
226
+
219
227
this . runtime = new AgentRuntime ( { token,
220
228
modelProvider : character . modelProvider ,
221
229
evaluators : [ ] ,
222
230
character,
231
+
223
232
// character.plugins are handled when clients are added
224
233
plugins : [ bootstrapPlugin ] . flat ( ) . filter ( Boolean ) ,
225
234
providers : [ ] ,
226
- managers : [ ] ,
235
+ managers : [
236
+ // memeory menages
237
+
238
+ ] ,
227
239
fetch : logFetch , } )
228
- //{
229
- // agentId: "00000000-0000-0000-0000-000000000000",
230
- // serverUrl: "http://localhost",
231
- // databaseAdapter: {} as IDatabaseAdapter,
232
- // token: "token",
233
- // function getMemoryManager(manager: string): IMemoryManager | null {
234
- // if (manager === 'someCondition') {
235
- // return {
236
- // runtime: 'someRuntime',
237
- // tableName: 'someTableName',
238
- // getMemories: async () => {
239
- // // Implementation here
240
- // return [];
241
- // },
242
- // getCachedEmbeddings: async () => {
243
- // // Implementation here
244
- // return [];
245
- // },
246
- // addEmbeddingToMemory: async (data: any) => {
247
- // // Implementation here
248
- // return {};
249
- // },
250
- // createMemory: async (memory: any) => {
251
- // // Implementation here
252
- // },
253
- // // Add other properties and methods as required
254
- // };
255
- // }
256
- // return null;
257
- // }
258
- // };
259
- // }
260
- }
240
+ this . knowledgeManager = new MemoryManager ( {
241
+ runtime : this . runtime ,
242
+ tableName : "lore" ,
243
+ } ) ;
244
+ console . log ( "KM" , this . runtime . knowledgeManager )
245
+ console . log ( "Before" , this . runtime . memoryManagers )
246
+ this . runtime . memoryManagers . set ( this . runtime . knowledgeManager . tableName , this . runtime . knowledgeManager ) ;
247
+ console . log ( "After" , this . runtime . memoryManagers )
248
+ }
249
+
261
250
262
251
/**
263
252
* Generates a comment based on the specified prompt by invoking the chat model.
@@ -278,32 +267,14 @@ export class AIService {
278
267
279
268
//characters = new Character()
280
269
281
- let runtime = this . agents . get ( agentId ) ;
270
+ //let runtime = this.agents.get(agentId);
271
+ let runtime = this . runtime ;
282
272
if ( ! runtime ) {
283
- const character = defaultCharacter ;
284
- runtime = new AgentRuntime ( {
285
- token,
286
- modelProvider : character . modelProvider ,
287
- evaluators : [ ] ,
288
- character,
289
- // character.plugins are handled when clients are added
290
- plugins : [
291
- //bootstrapPlugin
292
- ] . flat ( ) . filter ( Boolean ) ,
293
- providers : [ ] ,
294
- managers : [ ] ,
295
- // fetch: logFetch,
296
- // agentId: agentId,
297
- // serverUrl: "XXXXXXXXXXXXXXXX",
298
- // databaseAdapter: {} as IDatabaseAdapter,
299
- // token: "token",
300
- // modelProvider: "defaultModelProvider", // Add the modelProvider property
301
- } ) ;
302
273
this . agents . set ( agentId , runtime ) ;
303
274
}
304
275
if ( runtime ) {
305
276
console . log ( "Runtime found for agentId:" , agentId ) ;
306
- await processChunk ( finalPrompt , "chat " , runtime ) ;
277
+ await processChunk ( finalPrompt , "fragments " , runtime ) ;
307
278
} else {
308
279
console . warn ( "No runtime found for agentId:" , agentId ) ;
309
280
}
@@ -333,12 +304,14 @@ export class AIService {
333
304
}
334
305
}
335
306
336
- async function processChunk ( prompt : string , manager : string , runtime : IAgentRuntime ) : Promise < string > {
307
+ async function processChunk ( prompt : string , manager : string , runtime : AgentRuntime ) : Promise < string > {
337
308
console . log ( "process chunk" ) ;
338
309
try {
339
310
const mm = runtime . getMemoryManager ( manager ) ;
340
311
if ( ! mm ) {
341
- throw new Error ( "Memory manager not found" ) ;
312
+ console . log ( "manager" , manager ) ;
313
+ console . log ( "memoryManagers" , runtime . memoryManagers ) ;
314
+ throw new Error ( "Memory manager not found" , manager ) ;
342
315
}
343
316
const memory = await mm . addEmbeddingToMemory ( {
344
317
agentId : runtime . agentId ,
@@ -513,38 +486,38 @@ async function process_text(this: any, agentId: string, userName: string, name:
513
486
}
514
487
}
515
488
516
- interface IMemoryManager {
517
- runtime : string ;
518
- tableName : string ;
519
- getMemories : ( ) => Promise < any [ ] > ;
520
- getCachedEmbeddings : ( ) => Promise < any [ ] > ;
521
- addEmbeddingToMemory : ( data : any ) => Promise < { } > ;
522
- createMemory : ( memory : any ) => Promise < void > ;
523
- // Add other properties and methods as required
524
- }
525
-
526
- function getMemoryManager ( manager : string ) : IMemoryManager | null {
527
- if ( manager === 'someCondition' ) {
528
- return {
529
- runtime : 'someRuntime' ,
530
- tableName : 'someTableName' ,
531
- getMemories : async ( ) => {
532
- // Implementation here
533
- return [ ] ;
534
- } ,
535
- getCachedEmbeddings : async ( ) => {
536
- // Implementation here
537
- return [ ] ;
538
- } ,
539
- addEmbeddingToMemory : async ( data : any ) => {
540
- // Implementation here
541
- return { } ;
542
- } ,
543
- createMemory : async ( memory : any ) => {
544
- // Implementation here
545
- } ,
546
- // Add other properties and methods as required
547
- } ;
548
- }
549
- return null ;
550
- }
489
+ // interface IMemoryManager {
490
+ // runtime: string;
491
+ // tableName: string;
492
+ // getMemories: () => Promise<any[]>;
493
+ // getCachedEmbeddings: () => Promise<any[]>;
494
+ // addEmbeddingToMemory: (data: any) => Promise<{}>;
495
+ // createMemory: (memory: any) => Promise<void>;
496
+ // // Add other properties and methods as required
497
+ // }
498
+
499
+ // function getMemoryManager(manager: string): IMemoryManager | null {
500
+ // if (manager === 'someCondition') {
501
+ // return {
502
+ // runtime: 'someRuntime',
503
+ // tableName: 'someTableName',
504
+ // getMemories: async () => {
505
+ // // Implementation here
506
+ // return [];
507
+ // },
508
+ // getCachedEmbeddings: async () => {
509
+ // // Implementation here
510
+ // return [];
511
+ // },
512
+ // addEmbeddingToMemory: async (data: any) => {
513
+ // // Implementation here
514
+ // return {};
515
+ // },
516
+ // createMemory: async (memory: any) => {
517
+ // // Implementation here
518
+ // },
519
+ // // Add other properties and methods as required
520
+ // };
521
+ // }
522
+ // return null;
523
+ // }
0 commit comments