-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: loading characters from db at load and runtime (conflicts resolved) #1210
Conversation
… Ungate-Ai-ungate/dev
I like this a lot. In the current design, are characters able to be published to the DB through an API call? I can imagine an interesting way to leverage this is to have a published docker image and pair it with a docker compose file to load the character file into the DB on startup and then initialize the agent without needing to build a new image. If I am going to test this and want to load a character file, can I make a call to an S3 API storing a character file and have that be fetched and loaded in the DB? Then have my command to be something like |
not yet but I like that direction. The issue with the current REST loading is that a crash will lose all your current agents and you have to know which ones to reload, so I like this DB direction. This PR is a bit over engineered, thinking about merging and then cleaning up. |
I would really LOVE to get this merged in post hopefully the final round of merge conflicts :) |
Originally #551, this is a resubmission
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