feat: loading characters from db at load and runtime #551
+1,255
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to:
Loading Characters from db(sqlite/postgres) during runtime (via a REST API call) and
during start/load time.
Risks
Medium
None of these changes will affect existing workflow as its handled by env variables
FETCH_FROM_DB (bool) - default: null/false - For loading characters from DB
AGENT_RUNTIME_MANAGEMENT (bool) - default: null/false - For loading characters from Db at runtime
From security standpoint, all character specific secrets (EG: TWITTER_PASSWORD or OPENAI_API_KEY) is AES-256 encrypted and stored in DB
Background
For a production ready - multi-character Eliza setup, we want to load new characters in runtime via API calls.
We do not want to restart the Eliza server for each new character.
ASSUMPTION:
An api or script exists to store the characters in DB.
The api uses the same stringToUUID method to create consistent UUIDs for a character and store in DB.
What does this PR do?
What kind of change is this?
This is a new Feature
Why?
Currently
Why are we doing this?
To take a step towards multi-character production setup
Code Changes made and why?
export type CharacterTable = { id: UUID; // created from stringToUUID - unique and consistent for name name: string; characterState: Character; // A JSONB or TEXT - that maps the character secretsIV?: Secrets; // Initialisation Vector for each secrets };
Also added the above in packages/core/src/types.ts
characterNames?: string
): Promise<Character[]>
Requires env variable
POSTGRES_URL= # if postgres ENCRYPTION_KEY="" INPUT_PATH=characters # the folder path to load the characters from SQLITE_DB_PATH= #if you want to change db path Default: agent/data/db.sqlite
Documentation changes needed?
Not needed necessarily.
New ENV variables and explanations are added in .env.example
Testing
I have tested the scenarios in detailed testing steps in both sqlite and postgres.
Where should a reviewer start?
packages/client-direct/src/index.js
Detailed testing steps
INIT STEP:
scripts/importCharactersInDB/[postgres/sqlite]/insertInDb.js
-I have tested the following scenarios
pnpm start
pnpm start
curl --location --request POST 'http://localhost:3000/load/trump'
- replace port and character name if using different characters