@@ -24,7 +24,9 @@ import {
24
24
settings ,
25
25
stringToUuid ,
26
26
validateCharacterConfig ,
27
+ CacheStore ,
27
28
} from "@ai16z/eliza" ;
29
+ import { RedisClient } from "@ai16z/adapter-redis" ;
28
30
import { zgPlugin } from "@ai16z/plugin-0g" ;
29
31
import { bootstrapPlugin } from "@ai16z/plugin-bootstrap" ;
30
32
import createGoatPlugin from "@ai16z/plugin-goat" ;
@@ -210,11 +212,11 @@ export async function loadCharacters(
210
212
export function getTokenForProvider (
211
213
provider : ModelProviderName ,
212
214
character : Character
213
- ) :string {
215
+ ) : string {
214
216
switch ( provider ) {
215
217
// no key needed for llama_local
216
218
case ModelProviderName . LLAMALOCAL :
217
- return ''
219
+ return "" ;
218
220
case ModelProviderName . OPENAI :
219
221
return (
220
222
character . settings ?. secrets ?. OPENAI_API_KEY ||
@@ -310,9 +312,9 @@ export function getTokenForProvider(
310
312
settings . AKASH_CHAT_API_KEY
311
313
) ;
312
314
default :
313
- const errorMessage = `Failed to get token - unsupported model provider: ${ provider } `
314
- elizaLogger . error ( errorMessage )
315
- throw new Error ( errorMessage )
315
+ const errorMessage = `Failed to get token - unsupported model provider: ${ provider } ` ;
316
+ elizaLogger . error ( errorMessage ) ;
317
+ throw new Error ( errorMessage ) ;
316
318
}
317
319
}
318
320
@@ -402,7 +404,6 @@ export async function initializeClients(
402
404
// TODO: Add Slack client to the list
403
405
// Initialize clients as an object
404
406
405
-
406
407
if ( clientTypes . includes ( "slack" ) ) {
407
408
const slackClient = await SlackClientInterface . start ( runtime ) ;
408
409
if ( slackClient ) clients . slack = slackClient ; // Use object property instead of push
@@ -583,6 +584,45 @@ function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
583
584
return cache ;
584
585
}
585
586
587
+ function initializeCache (
588
+ cacheStore : string ,
589
+ character : Character ,
590
+ baseDir ?: string ,
591
+ db ?: IDatabaseCacheAdapter
592
+ ) {
593
+ switch ( cacheStore ) {
594
+ case CacheStore . REDIS :
595
+ if ( process . env . REDIS_URL ) {
596
+ elizaLogger . info ( "Connecting to Redis..." ) ;
597
+ const redisClient = new RedisClient ( process . env . REDIS_URL ) ;
598
+ return new CacheManager (
599
+ new DbCacheAdapter ( redisClient , character . id ) // Using DbCacheAdapter since RedisClient also implements IDatabaseCacheAdapter
600
+ ) ;
601
+ } else {
602
+ throw new Error ( "REDIS_URL environment variable is not set." ) ;
603
+ }
604
+
605
+ case CacheStore . DATABASE :
606
+ if ( db ) {
607
+ elizaLogger . info ( "Using Database Cache..." ) ;
608
+ return initializeDbCache ( character , db ) ;
609
+ } else {
610
+ throw new Error (
611
+ "Database adapter is not provided for CacheStore.Database."
612
+ ) ;
613
+ }
614
+
615
+ case CacheStore . FILESYSTEM :
616
+ elizaLogger . info ( "Using File System Cache..." ) ;
617
+ return initializeFsCache ( baseDir , character ) ;
618
+
619
+ default :
620
+ throw new Error (
621
+ `Invalid cache store: ${ cacheStore } or required configuration missing.`
622
+ ) ;
623
+ }
624
+ }
625
+
586
626
async function startAgent (
587
627
character : Character ,
588
628
directClient : DirectClient
@@ -604,7 +644,12 @@ async function startAgent(
604
644
605
645
await db . init ( ) ;
606
646
607
- const cache = initializeDbCache ( character , db ) ;
647
+ const cache = initializeCache (
648
+ process . env . CACHE_STORE ,
649
+ character ,
650
+ "" ,
651
+ db
652
+ ) ; // "" should be replaced with dir for file system caching. THOUGHTS: might probably make this into an env
608
653
const runtime : AgentRuntime = await createAgent (
609
654
character ,
610
655
db ,
0 commit comments