@@ -14,8 +14,8 @@ import {
14
14
} from "./evaluators.ts" ;
15
15
import { generateText } from "./generation.ts" ;
16
16
import { formatGoalsAsString , getGoals } from "./goals.ts" ;
17
- import { elizaLogger } from "./index.ts" ;
18
- import { MemoryManager } from "./memory.ts" ;
17
+ import { elizaLogger , embed , splitChunks } from "./index.ts" ;
18
+ import { embeddingZeroVector , MemoryManager } from "./memory.ts" ;
19
19
import { formatActors , formatMessages , getActorDetails } from "./messages.ts" ;
20
20
import { parseJsonArrayFromText } from "./parsing.ts" ;
21
21
import { formatPosts } from "./posts.ts" ;
@@ -301,7 +301,7 @@ export class AgentRuntime implements IAgentRuntime {
301
301
opts . character . knowledge &&
302
302
opts . character . knowledge . length > 0
303
303
) {
304
- // this.processCharacterKnowledge(opts.character.knowledge);
304
+ this . processCharacterKnowledge ( opts . character . knowledge ) ;
305
305
}
306
306
}
307
307
@@ -311,62 +311,63 @@ export class AgentRuntime implements IAgentRuntime {
311
311
* then chunks the content into fragments, embeds each fragment, and creates fragment memories.
312
312
* @param knowledge An array of knowledge items containing id, path, and content.
313
313
*/
314
- // private async processCharacterKnowledge(knowledge: string[]) {
315
- // // ensure the room exists and the agent exists in the room
316
- // this.ensureRoomExists(this.agentId);
317
- // this.ensureUserExists(
318
- // this.agentId,
319
- // this.character.name,
320
- // this.character.name
321
- // );
322
- // this.ensureParticipantExists(this.agentId, this.agentId);
323
-
324
- // for (const knowledgeItem of knowledge) {
325
- // const knowledgeId = stringToUuid(knowledgeItem);
326
- // const existingDocument =
327
- // await this.documentsManager.getMemoryById(knowledgeId);
328
- // if (!existingDocument) {
329
- // console.log(
330
- // "Processing knowledge for ",
331
- // this.character.name,
332
- // " - ",
333
- // knowledgeItem.slice(0, 100)
334
- // );
335
- // await this.documentsManager.createMemory({
336
- // embedding: embeddingZeroVector,
337
- // id: knowledgeId,
338
- // agentId: this.agentId,
339
- // roomId: this.agentId,
340
- // userId: this.agentId,
341
- // createdAt: Date.now(),
342
- // content: {
343
- // text: knowledgeItem,
344
- // },
345
- // });
346
- // const fragments = await splitChunks(
347
- // this,
348
- // knowledgeItem,
349
- // 1200,
350
- // 200,
351
- // "fast"
352
- // );
353
- // for (const fragment of fragments) {
354
- // const embedding = await embed(this, fragment);
355
- // await this.fragmentsManager.createMemory({
356
- // id: stringToUuid(fragment),
357
- // roomId: this.agentId,
358
- // userId: this.agentId,
359
- // createdAt: Date.now(),
360
- // content: {
361
- // source: knowledgeId,
362
- // text: fragment,
363
- // },
364
- // embedding,
365
- // });
366
- // }
367
- // }
368
- // }
369
- // }
314
+ private async processCharacterKnowledge ( knowledge : string [ ] ) {
315
+ // ensure the room exists and the agent exists in the room
316
+ this . ensureRoomExists ( this . agentId ) ;
317
+ this . ensureUserExists (
318
+ this . agentId ,
319
+ this . character . name ,
320
+ this . character . name
321
+ ) ;
322
+ this . ensureParticipantExists ( this . agentId , this . agentId ) ;
323
+
324
+ for ( const knowledgeItem of knowledge ) {
325
+ const knowledgeId = stringToUuid ( knowledgeItem ) ;
326
+ const existingDocument =
327
+ await this . documentsManager . getMemoryById ( knowledgeId ) ;
328
+ if ( ! existingDocument ) {
329
+ console . log (
330
+ "Processing knowledge for " ,
331
+ this . character . name ,
332
+ " - " ,
333
+ knowledgeItem . slice ( 0 , 100 )
334
+ ) ;
335
+ await this . documentsManager . createMemory ( {
336
+ embedding : embeddingZeroVector ,
337
+ id : knowledgeId ,
338
+ agentId : this . agentId ,
339
+ roomId : this . agentId ,
340
+ userId : this . agentId ,
341
+ createdAt : Date . now ( ) ,
342
+ content : {
343
+ text : knowledgeItem ,
344
+ } ,
345
+ } ) ;
346
+ const fragments = await splitChunks (
347
+ this ,
348
+ knowledgeItem ,
349
+ 1200 ,
350
+ 200 ,
351
+ "fast"
352
+ ) ;
353
+ for ( const fragment of fragments ) {
354
+ const embedding = await embed ( this , fragment ) ;
355
+ await this . fragmentsManager . createMemory ( {
356
+ id : stringToUuid ( fragment ) ,
357
+ roomId : this . agentId ,
358
+ agentId : this . agentId ,
359
+ userId : this . agentId ,
360
+ createdAt : Date . now ( ) ,
361
+ content : {
362
+ source : knowledgeId ,
363
+ text : fragment ,
364
+ } ,
365
+ embedding,
366
+ } ) ;
367
+ }
368
+ }
369
+ }
370
+ }
370
371
371
372
getSetting ( key : string ) {
372
373
// check if the key is in the character.settings.secrets object
0 commit comments