Skip to content

Commit ad34b78

Browse files
committed
Load characters from arg in the new setup and rebuild docs
1 parent c96957e commit ad34b78

File tree

170 files changed

+1078
-1347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1078
-1347
lines changed

agent/src/index.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@ import {
1111
initializeClients,
1212
initializeDatabase,
1313
loadActionConfigs,
14+
loadCharacters,
1415
loadCustomActions,
1516
muteRoom,
17+
parseArguments,
1618
timeProvider,
1719
unfollowRoom,
1820
unmuteRoom,
1921
walletProvider,
2022
} from "@eliza/core";
2123
import readline from "readline";
2224

23-
const characters = [defaultCharacter];
25+
const args = parseArguments();
26+
27+
console.log("Args are: ", args);
28+
29+
let charactersArg = args.characters || args.character;
30+
31+
let characters = [defaultCharacter];
32+
33+
if (charactersArg) {
34+
characters = loadCharacters(charactersArg);
35+
}
36+
37+
console.log("Characters are: ", characters);
2438

2539
const directClient = new DirectClient();
2640

core/src/actions/continue.ts

-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
generateMessageResponse,
44
generateTrueOrFalse,
55
} from "../core/generation.ts";
6-
import { log_to_file } from "../core/logger.ts";
76
import { booleanFooter, messageCompletionFooter } from "../core/parsing.ts";
87
import {
98
Action,
@@ -137,11 +136,6 @@ export const continueAction: Action = {
137136
runtime.character.templates?.messageHandlerTemplate ||
138137
messageHandlerTemplate,
139138
});
140-
const datestr = new Date().toUTCString().replace(/:/g, "-");
141-
142-
// log context to file
143-
log_to_file(`${state.agentName}_${datestr}_continue_context`, context);
144-
145139
const { userId, roomId } = message;
146140

147141
const response = await generateMessageResponse({
@@ -152,12 +146,6 @@ export const continueAction: Action = {
152146

153147
response.inReplyTo = message.id;
154148

155-
// log response to file
156-
log_to_file(
157-
`${state.agentName}_${datestr}_continue_response`,
158-
JSON.stringify(response)
159-
);
160-
161149
runtime.databaseAdapter.log({
162150
body: { message, context, response },
163151
userId,

core/src/actions/imageGeneration.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
State,
66
Action,
77
} from "../core/types.ts";
8-
import { elizaLog } from "../index.ts";
8+
import { elizaLogger } from "../index.ts";
99
import { generateCaption, generateImage } from "./imageGenerationUtils.ts";
1010

1111
export const imageGeneration: Action = {
1212
name: "GENERATE_IMAGE",
1313
similes: ["IMAGE_GENERATION", "IMAGE_GEN", "CREATE_IMAGE", "MAKE_PICTURE"],
1414
description: "Generate an image to go along with the message.",
1515
validate: async (runtime: IAgentRuntime, message: Memory) => {
16+
// TODO: Abstract this to an image provider thing
17+
1618
const anthropicApiKeyOk = !!runtime.getSetting("ANTHROPIC_API_KEY");
1719
const togetherApiKeyOk = !!runtime.getSetting("TOGETHER_API_KEY");
1820

@@ -27,19 +29,19 @@ export const imageGeneration: Action = {
2729
options: any,
2830
callback: HandlerCallback
2931
) => {
30-
elizaLog.log("Composing state for message:", message);
32+
elizaLogger.log("Composing state for message:", message);
3133
state = (await runtime.composeState(message)) as State;
3234
const userId = runtime.agentId;
33-
elizaLog.log("User ID:", userId);
35+
elizaLogger.log("User ID:", userId);
3436

3537
const imagePrompt = message.content.text;
36-
elizaLog.log("Image prompt received:", imagePrompt);
38+
elizaLogger.log("Image prompt received:", imagePrompt);
3739

3840
// TODO: Generate a prompt for the image
3941

4042
const res: { image: string; caption: string }[] = [];
4143

42-
elizaLog.log("Generating image with prompt:", imagePrompt);
44+
elizaLogger.log("Generating image with prompt:", imagePrompt);
4345
const images = await generateImage(
4446
{
4547
prompt: imagePrompt,
@@ -51,13 +53,13 @@ export const imageGeneration: Action = {
5153
);
5254

5355
if (images.success && images.data && images.data.length > 0) {
54-
elizaLog.log(
56+
elizaLogger.log(
5557
"Image generation successful, number of images:",
5658
images.data.length
5759
);
5860
for (let i = 0; i < images.data.length; i++) {
5961
const image = images.data[i];
60-
elizaLog.log(`Processing image ${i + 1}:`, image);
62+
elizaLogger.log(`Processing image ${i + 1}:`, image);
6163

6264
const caption = await generateCaption(
6365
{
@@ -66,7 +68,7 @@ export const imageGeneration: Action = {
6668
runtime
6769
);
6870

69-
elizaLog.log(
71+
elizaLogger.log(
7072
`Generated caption for image ${i + 1}:`,
7173
caption.title
7274
);
@@ -90,7 +92,7 @@ export const imageGeneration: Action = {
9092
);
9193
}
9294
} else {
93-
elizaLog.error("Image generation failed or returned no data.");
95+
elizaLogger.error("Image generation failed or returned no data.");
9496
}
9597
},
9698
examples: [

core/src/adapters/sqlite/sqlite_vec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as sqliteVec from "sqlite-vec";
22
import { Database } from "better-sqlite3";
3-
import { elizaLog } from "../../index.ts";
3+
import { elizaLogger } from "../../index.ts";
44

55
// Loads the sqlite-vec extensions into the provided SQLite database
66
export function loadVecExtensions(db: Database): void {
77
try {
88
// Load sqlite-vec extensions
99
sqliteVec.load(db);
10-
elizaLog.log("sqlite-vec extensions loaded successfully.");
10+
elizaLogger.log("sqlite-vec extensions loaded successfully.");
1111
} catch (error) {
12-
elizaLog.error("Failed to load sqlite-vec extensions:", error);
12+
elizaLogger.error("Failed to load sqlite-vec extensions:", error);
1313
throw error;
1414
}
1515
}

core/src/cli/config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import yaml from "js-yaml";
33
import path from "path";
44
import { fileURLToPath } from "url";
55
import { Action } from "../core/types";
6-
import { elizaLog } from "../index.ts";
6+
import { elizaLogger } from "../index.ts";
77

88
const ROOT_DIR = path.resolve(fileURLToPath(import.meta.url), "../../../src");
99

@@ -30,13 +30,13 @@ export async function loadCustomActions(
3030

3131
for (const config of actionConfigs) {
3232
const resolvedPath = path.resolve(ROOT_DIR, config.path);
33-
elizaLog.log(`Importing action from: ${resolvedPath}`); // Debugging log
33+
elizaLogger.log(`Importing action from: ${resolvedPath}`); // Debugging log
3434

3535
try {
3636
const actionModule = await import(resolvedPath);
3737
actions.push(actionModule[config.name]);
3838
} catch (error) {
39-
elizaLog.error(
39+
elizaLogger.error(
4040
`Failed to import action from ${resolvedPath}:`,
4141
error
4242
);

core/src/cli/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { AgentRuntime } from "../core/runtime.ts";
1616
import { defaultActions } from "../core/actions.ts";
1717
import { Arguments } from "../types/index.ts";
1818
import { loadActionConfigs, loadCustomActions } from "./config.ts";
19-
import { elizaLog } from "../index.ts";
19+
import { elizaLogger } from "../index.ts";
2020

2121
export async function initializeClients(
2222
character: Character,
@@ -73,7 +73,10 @@ export function loadCharacters(charactersArg: string): Character[] {
7373
.map((path) => path.trim())
7474
.map((path) => {
7575
if (path.startsWith("./characters")) {
76-
return `../characters/${path}`;
76+
return `.${path}`;
77+
}
78+
if (path.startsWith("characters")) {
79+
return `../${path}`;
7780
}
7881
return path;
7982
});
@@ -213,11 +216,11 @@ export async function startTelegram(
213216
runtime: IAgentRuntime,
214217
character: Character
215218
) {
216-
elizaLog.log("🔍 Attempting to start Telegram bot...");
219+
elizaLogger.log("🔍 Attempting to start Telegram bot...");
217220
const botToken = runtime.getSetting("TELEGRAM_BOT_TOKEN");
218221

219222
if (!botToken) {
220-
elizaLog.error(
223+
elizaLogger.error(
221224
`❌ Telegram bot token is not set for character ${character.name}.`
222225
);
223226
return null;
@@ -226,12 +229,12 @@ export async function startTelegram(
226229
try {
227230
const telegramClient = new Client.TelegramClient(runtime, botToken);
228231
await telegramClient.start();
229-
elizaLog.success(
232+
elizaLogger.success(
230233
`✅ Telegram client successfully started for character ${character.name}`
231234
);
232235
return telegramClient;
233236
} catch (error) {
234-
elizaLog.error(
237+
elizaLogger.error(
235238
`❌ Error creating/starting Telegram client for ${character.name}:`,
236239
error
237240
);
@@ -240,7 +243,7 @@ export async function startTelegram(
240243
}
241244

242245
export async function startTwitter(runtime: IAgentRuntime) {
243-
elizaLog.log("Starting Twitter clients...");
246+
elizaLogger.log("Starting Twitter clients...");
244247
const twitterSearchClient = new Client.TwitterSearchClient(runtime);
245248
await wait();
246249
const twitterInteractionClient = new Client.TwitterInteractionClient(

core/src/clients/discord/actions/chat_with_attachments.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import fs from "fs";
12
import { composeContext } from "../../../core/context.ts";
23
import { generateText, trimTokens } from "../../../core/generation.ts";
3-
import { log_to_file } from "../../../core/logger.ts";
44
import models from "../../../core/models.ts";
55
import { parseJSONObjectFromText } from "../../../core/parsing.ts";
66
import {
@@ -13,7 +13,6 @@ import {
1313
ModelClass,
1414
State,
1515
} from "../../../core/types.ts";
16-
import fs from "fs";
1716
export const summarizationTemplate = `# Summarized so far (we are adding to this)
1817
{{currentSummary}}
1918
@@ -199,30 +198,14 @@ const summarizeAction = {
199198
),
200199
});
201200

202-
log_to_file(
203-
`${state.agentName}_${datestr}_chat_with_attachment_context`,
204-
context
205-
);
206-
207201
const summary = await generateText({
208202
runtime,
209203
context,
210204
modelClass: ModelClass.SMALL,
211205
});
212206

213-
log_to_file(
214-
`${state.agentName}_${datestr}_chat_with_attachment_response`,
215-
summary
216-
);
217-
218207
currentSummary = currentSummary + "\n" + summary;
219208

220-
// log summary to file
221-
log_to_file(
222-
`${state.agentName}_${datestr}_chat_with_attachment_summary`,
223-
currentSummary
224-
);
225-
226209
if (!currentSummary) {
227210
console.error("No summary found, that's not good!");
228211
return;

core/src/clients/discord/actions/joinvoice.ts

-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
GuildMember,
1111
} from "discord.js";
1212
import { composeContext } from "../../../core/context.ts";
13-
import { log_to_file } from "../../../core/logger.ts";
1413
import {
1514
Action,
1615
ActionExample,
@@ -164,24 +163,12 @@ You should only respond with the name of the voice channel or none, no commentar
164163

165164
const datestr = new Date().toUTCString().replace(/:/g, "-");
166165

167-
// log context to file
168-
log_to_file(
169-
`${state.agentName}_${datestr}_joinvoice_context`,
170-
context
171-
);
172-
173166
const responseContent = await generateText({
174167
runtime,
175168
context,
176169
modelClass: ModelClass.SMALL,
177170
});
178171

179-
// log response to file
180-
log_to_file(
181-
`${state.agentName}_${datestr}_joinvoice_response`,
182-
responseContent
183-
);
184-
185172
runtime.databaseAdapter.log({
186173
body: { message, context, response: responseContent },
187174
userId: message.userId,

core/src/clients/discord/actions/summarize_conversation.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import fs from "fs";
12
import { composeContext } from "../../../core/context.ts";
23
import {
34
generateText,
45
splitChunks,
56
trimTokens,
67
} from "../../../core/generation.ts";
7-
import { log_to_file } from "../../../core/logger.ts";
88
import { getActorDetails } from "../../../core/messages.ts";
99
import models from "../../../core/models.ts";
1010
import { parseJSONObjectFromText } from "../../../core/parsing.ts";
@@ -19,7 +19,6 @@ import {
1919
ModelClass,
2020
State,
2121
} from "../../../core/types.ts";
22-
import fs from "fs";
2322
export const summarizationTemplate = `# Summarized so far (we are adding to this)
2423
{{currentSummary}}
2524
@@ -289,34 +288,16 @@ const summarizeAction = {
289288
"gpt-4o-mini"
290289
),
291290
});
292-
293-
log_to_file(
294-
`${state.agentName}_${datestr}_summarization_context`,
295-
context
296-
);
297-
291+
298292
const summary = await generateText({
299293
runtime,
300294
context,
301295
modelClass: ModelClass.SMALL,
302296
});
303297

304-
log_to_file(
305-
`${state.agentName}_${datestr}_summarization_response_${i}`,
306-
summary
307-
);
308-
309298
currentSummary = currentSummary + "\n" + summary;
310299
}
311300

312-
// log context to file
313-
log_to_file(
314-
`${state.agentName}_${datestr}_summarization_summary`,
315-
currentSummary
316-
);
317-
318-
// call callback with it -- twitter and discord client can separately handle what to do, IMO we may way to add gists so the agent can post a gist and link to it later
319-
320301
if (!currentSummary) {
321302
console.error("No summary found, that's not good!");
322303
return;

core/src/clients/discord/actions/transcribe_media.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import fs from "fs";
12
import { composeContext } from "../../../core/context.ts";
23
import { generateText } from "../../../core/generation.ts";
3-
import { log_to_file } from "../../../core/logger.ts";
44
import { parseJSONObjectFromText } from "../../../core/parsing.ts";
55
import {
66
Action,
@@ -12,7 +12,6 @@ import {
1212
ModelClass,
1313
State,
1414
} from "../../../core/types.ts";
15-
import fs from "fs";
1615
export const transcriptionTemplate = `# Transcription of media file
1716
{{mediaTranscript}}
1817

0 commit comments

Comments
 (0)