Skip to content
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: Enable Multiple remote character urls #2328

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ SERVER_PORT=3000
SUPABASE_URL=
SUPABASE_ANON_KEY=

# Remote character url (optional)
REMOTE_CHARACTER_URL=
# Comma separated list of remote character urls (optional)
REMOTE_CHARACTER_URLS=

###############################
#### Client Configurations ####
Expand Down
30 changes: 18 additions & 12 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ async function loadCharacter(filePath: string): Promise<Character> {
return jsonToCharacter(filePath, character);
}

function commaSeparatedStringToArray(commaSeparated: string): string[] {
return commaSeparated?.split(",").map(value => value.trim())
}


export async function loadCharacters(
charactersArg: string
): Promise<Character[]> {
let characterPaths = charactersArg
?.split(",")
.map((filePath) => filePath.trim());
let characterPaths = commaSeparatedStringToArray(charactersArg)
const loadedCharacters: Character[] = [];

if (characterPaths?.length > 0) {
Expand Down Expand Up @@ -321,17 +324,16 @@ export async function loadCharacters(
}
}

if (loadedCharacters.length === 0) {
if (
process.env.REMOTE_CHARACTER_URL != "" &&
process.env.REMOTE_CHARACTER_URL.startsWith("http")
) {
const character = await loadCharacterFromUrl(
process.env.REMOTE_CHARACTER_URL
);
if (hasValidRemoteUrls()) {
elizaLogger.info("Loading characters from remote URLs");
let characterUrls = commaSeparatedStringToArray(process.env.REMOTE_CHARACTER_URLS)
for (const characterUrl of characterUrls) {
const character = await loadCharacterFromUrl(characterUrl);
loadedCharacters.push(character);
}
}

if (loadedCharacters.length === 0) {
elizaLogger.info("No characters found, using default character");
loadedCharacters.push(defaultCharacter);
}
Expand Down Expand Up @@ -1091,14 +1093,18 @@ const checkPortAvailable = (port: number): Promise<boolean> => {
});
};

const hasValidRemoteUrls = () =>
process.env.REMOTE_CHARACTER_URLS != "" &&
process.env.REMOTE_CHARACTER_URLS.startsWith("http")

const startAgents = async () => {
const directClient = new DirectClient();
let serverPort = parseInt(settings.SERVER_PORT || "3000");
const args = parseArguments();
let charactersArg = args.characters || args.character;
let characters = [defaultCharacter];

if (charactersArg) {
if (charactersArg || hasValidRemoteUrls()) {
characters = await loadCharacters(charactersArg);
}

Expand Down
Loading