@@ -318,42 +318,53 @@ function initializeDatabase(dataDir: string) {
318
318
}
319
319
}
320
320
321
+ // also adds plugins from character file into the runtime
321
322
export async function initializeClients (
322
323
character : Character ,
323
324
runtime : IAgentRuntime
324
325
) {
325
- const clients = [ ] ;
326
- const clientTypes =
326
+ // each client can only register once
327
+ // and if we want two we can explicitly support it
328
+ const clients :Record < string , any > = { } ;
329
+ const clientTypes :string [ ] =
327
330
character . clients ?. map ( ( str ) => str . toLowerCase ( ) ) || [ ] ;
331
+ elizaLogger . log ( 'initializeClients' , clientTypes , 'for' , character . name )
328
332
329
333
if ( clientTypes . includes ( "auto" ) ) {
330
334
const autoClient = await AutoClientInterface . start ( runtime ) ;
331
- if ( autoClient ) clients . push ( autoClient ) ;
335
+ if ( autoClient ) clients . auto = autoClient ;
332
336
}
333
337
334
338
if ( clientTypes . includes ( "discord" ) ) {
335
- clients . push ( await DiscordClientInterface . start ( runtime ) ) ;
339
+ const discordClient = await DiscordClientInterface . start ( runtime ) ;
340
+ if ( discordClient ) clients . discord = discordClient ;
336
341
}
337
342
338
343
if ( clientTypes . includes ( "telegram" ) ) {
339
344
const telegramClient = await TelegramClientInterface . start ( runtime ) ;
340
- if ( telegramClient ) clients . push ( telegramClient ) ;
345
+ if ( telegramClient ) clients . telegram = telegramClient ;
341
346
}
342
347
343
348
if ( clientTypes . includes ( "twitter" ) ) {
344
349
TwitterClientInterface . enableSearch = ! isFalsish ( getSecret ( character , "TWITTER_SEARCH_ENABLE" ) ) ;
345
- const twitterClients = await TwitterClientInterface . start ( runtime ) ;
346
- clients . push ( twitterClients ) ;
350
+ const twitterClient = await TwitterClientInterface . start ( runtime ) ;
351
+ if ( twitterClient ) clients . twitter = twitterClient ;
347
352
}
348
353
349
354
if ( clientTypes . includes ( "farcaster" ) ) {
350
- const farcasterClients = new FarcasterAgentClient ( runtime ) ;
351
- farcasterClients . start ( ) ;
352
- clients . push ( farcasterClients ) ;
355
+ // why is this one different :(
356
+ const farcasterClient = new FarcasterAgentClient ( runtime ) ;
357
+ if ( farcasterClient ) {
358
+ farcasterClient . start ( ) ;
359
+ clients . farcaster = farcasterClient ;
360
+ }
353
361
}
354
362
363
+ elizaLogger . log ( 'client keys' , Object . keys ( clients ) ) ;
364
+
355
365
if ( character . plugins ?. length > 0 ) {
356
366
for ( const plugin of character . plugins ) {
367
+ // if plugin has clients, add those..
357
368
if ( plugin . clients ) {
358
369
for ( const client of plugin . clients ) {
359
370
clients . push ( await client . start ( runtime ) ) ;
@@ -382,7 +393,7 @@ function isFalsish(input: any): boolean {
382
393
}
383
394
384
395
function getSecret ( character : Character , secret : string ) {
385
- return character . settings . secrets ?. [ secret ] || process . env [ secret ] ;
396
+ return character . settings ? .secrets ?. [ secret ] || process . env [ secret ] ;
386
397
}
387
398
388
399
let nodePlugin : any | undefined ;
@@ -392,7 +403,7 @@ export async function createAgent(
392
403
db : IDatabaseAdapter ,
393
404
cache : ICacheManager ,
394
405
token : string
395
- ) {
406
+ ) : AgentRuntime {
396
407
elizaLogger . success (
397
408
elizaLogger . successesTitle ,
398
409
"Creating runtime for character" ,
@@ -425,6 +436,7 @@ export async function createAgent(
425
436
modelProvider : character . modelProvider ,
426
437
evaluators : [ ] ,
427
438
character,
439
+ // character.plugins are handled when clients are added
428
440
plugins : [
429
441
bootstrapPlugin ,
430
442
getSecret ( character , "CONFLUX_CORE_PRIVATE_KEY" )
@@ -495,7 +507,7 @@ function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
495
507
return cache ;
496
508
}
497
509
498
- async function startAgent ( character : Character , directClient ) {
510
+ async function startAgent ( character : Character , directClient ) : AgentRuntime {
499
511
let db : IDatabaseAdapter & IDatabaseCacheAdapter ;
500
512
try {
501
513
character . id ??= stringToUuid ( character . name ) ;
@@ -514,15 +526,21 @@ async function startAgent(character: Character, directClient) {
514
526
await db . init ( ) ;
515
527
516
528
const cache = initializeDbCache ( character , db ) ;
517
- const runtime = await createAgent ( character , db , cache , token ) ;
529
+ const runtime : AgentRuntime = await createAgent ( character , db , cache , token ) ;
518
530
531
+ // start services/plugins/process knowledge
519
532
await runtime . initialize ( ) ;
520
533
521
- const clients = await initializeClients ( character , runtime ) ;
534
+ // start assigned clients
535
+ runtime . clients = await initializeClients ( character , runtime ) ;
522
536
537
+ // add to container
523
538
directClient . registerAgent ( runtime ) ;
524
539
525
- return clients ;
540
+ // report to console
541
+ elizaLogger . debug ( `Started ${ character . name } as ${ runtime . agentId } ` )
542
+
543
+ return runtime ;
526
544
} catch ( error ) {
527
545
elizaLogger . error (
528
546
`Error starting agent for character ${ character . name } :` ,
@@ -566,8 +584,8 @@ const startAgents = async () => {
566
584
} ) ;
567
585
}
568
586
569
- elizaLogger . log ( "Chat started. Type 'exit' to quit." ) ;
570
587
if ( ! args [ "non-interactive" ] ) {
588
+ elizaLogger . log ( "Chat started. Type 'exit' to quit." ) ;
571
589
chat ( ) ;
572
590
}
573
591
} ;
0 commit comments