Skip to content

Commit 1ae56a3

Browse files
authored
Merge branch 'develop' into feature/add-binance-plugin
2 parents 713a688 + 4c53ea2 commit 1ae56a3

File tree

11 files changed

+413
-294
lines changed

11 files changed

+413
-294
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ POST_IMMEDIATELY=
9797
# Twitter action processing configuration
9898
ACTION_INTERVAL= # Interval in minutes between action processing runs (default: 5 minutes)
9999
ENABLE_ACTION_PROCESSING=false # Set to true to enable the action processing loop
100+
MAX_ACTIONS_PROCESSING=1 # Maximum number of actions (e.g., retweets, likes) to process in a single cycle. Helps prevent excessive or uncontrolled actions.
101+
ACTION_TIMELINE_TYPE=foryou # Type of timeline to interact with. Options: "foryou" or "following". Default: "foryou"
100102

101103
# Feature Flags
102104
IMAGE_GEN= # Set to TRUE to enable image generation

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
## 🚩 Overview
1818

1919
<div align="center">
20-
<img src="./docs/static/img/eliza_diagram.jpg" alt="Eliza Diagram" width="100%" />
20+
<img src="./docs/static/img/eliza_diagram.png" alt="Eliza Diagram" width="100%" />
2121
</div>
2222

2323
## ✨ Features

agent/src/index.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ export async function loadCharacters(
134134
let characterPaths = charactersArg
135135
?.split(",")
136136
.map((filePath) => filePath.trim());
137-
const loadedCharacters = [];
137+
const loadedCharacters: Character[] = [];
138138

139139
if (characterPaths?.length > 0) {
140140
for (const characterPath of characterPaths) {
141-
let content = null;
141+
let content: string | null = null;
142142
let resolvedPath = "";
143143

144144
// Try different path resolutions in order
@@ -248,7 +248,7 @@ export async function loadCharacters(
248248
export function getTokenForProvider(
249249
provider: ModelProviderName,
250250
character: Character
251-
): string {
251+
): string | undefined {
252252
switch (provider) {
253253
// no key needed for llama_local or gaianet
254254
case ModelProviderName.LLAMALOCAL:
@@ -661,13 +661,23 @@ export async function createAgent(
661661
}
662662

663663
function initializeFsCache(baseDir: string, character: Character) {
664+
if (!character?.id) {
665+
throw new Error(
666+
"initializeFsCache requires id to be set in character definition"
667+
);
668+
}
664669
const cacheDir = path.resolve(baseDir, character.id, "cache");
665670

666671
const cache = new CacheManager(new FsCacheAdapter(cacheDir));
667672
return cache;
668673
}
669674

670675
function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
676+
if (!character?.id) {
677+
throw new Error(
678+
"initializeFsCache requires id to be set in character definition"
679+
);
680+
}
671681
const cache = new CacheManager(new DbCacheAdapter(db, character.id));
672682
return cache;
673683
}
@@ -683,6 +693,11 @@ function initializeCache(
683693
if (process.env.REDIS_URL) {
684694
elizaLogger.info("Connecting to Redis...");
685695
const redisClient = new RedisClient(process.env.REDIS_URL);
696+
if (!character?.id) {
697+
throw new Error(
698+
"CacheStore.REDIS requires id to be set in character definition"
699+
);
700+
}
686701
return new CacheManager(
687702
new DbCacheAdapter(redisClient, character.id) // Using DbCacheAdapter since RedisClient also implements IDatabaseCacheAdapter
688703
);
@@ -702,6 +717,11 @@ function initializeCache(
702717

703718
case CacheStore.FILESYSTEM:
704719
elizaLogger.info("Using File System Cache...");
720+
if (!baseDir) {
721+
throw new Error(
722+
"baseDir must be provided for CacheStore.FILESYSTEM."
723+
);
724+
}
705725
return initializeFsCache(baseDir, character);
706726

707727
default:

docs/static/img/eliza_diagram.png

2.3 MB
Loading

packages/client-discord/src/actions/summarize_conversation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ ${currentSummary.trim()}
381381
{
382382
user: "{{user2}}",
383383
content: {
384-
text: "no probblem, give me a few minutes to read through everything",
384+
text: "no problem, give me a few minutes to read through everything",
385385
action: "SUMMARIZE",
386386
},
387387
},

packages/client-telegram/src/messageManager.ts

+48-50
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,53 @@ export class MessageManager {
10511051
// Decide whether to respond
10521052
const shouldRespond = await this._shouldRespond(message, state);
10531053

1054+
// Send response in chunks
1055+
const callback: HandlerCallback = async (content: Content) => {
1056+
const sentMessages = await this.sendMessageInChunks(
1057+
ctx,
1058+
content,
1059+
message.message_id
1060+
);
1061+
if (sentMessages) {
1062+
const memories: Memory[] = [];
1063+
1064+
// Create memories for each sent message
1065+
for (let i = 0; i < sentMessages.length; i++) {
1066+
const sentMessage = sentMessages[i];
1067+
const isLastMessage = i === sentMessages.length - 1;
1068+
1069+
const memory: Memory = {
1070+
id: stringToUuid(
1071+
sentMessage.message_id.toString() +
1072+
"-" +
1073+
this.runtime.agentId
1074+
),
1075+
agentId,
1076+
userId: agentId,
1077+
roomId,
1078+
content: {
1079+
...content,
1080+
text: sentMessage.text,
1081+
inReplyTo: messageId,
1082+
},
1083+
createdAt: sentMessage.date * 1000,
1084+
embedding: getEmbeddingZeroVector(),
1085+
};
1086+
1087+
// Set action to CONTINUE for all messages except the last one
1088+
// For the last message, use the original action from the response content
1089+
memory.content.action = !isLastMessage
1090+
? "CONTINUE"
1091+
: content.action;
1092+
1093+
await this.runtime.messageManager.createMemory(memory);
1094+
memories.push(memory);
1095+
}
1096+
1097+
return memories;
1098+
}
1099+
};
1100+
10541101
if (shouldRespond) {
10551102
// Generate response
10561103
const context = composeContext({
@@ -1071,55 +1118,6 @@ export class MessageManager {
10711118

10721119
if (!responseContent || !responseContent.text) return;
10731120

1074-
// Send response in chunks
1075-
const callback: HandlerCallback = async (content: Content) => {
1076-
const sentMessages = await this.sendMessageInChunks(
1077-
ctx,
1078-
content,
1079-
message.message_id
1080-
);
1081-
if (sentMessages) {
1082-
const memories: Memory[] = [];
1083-
1084-
// Create memories for each sent message
1085-
for (let i = 0; i < sentMessages.length; i++) {
1086-
const sentMessage = sentMessages[i];
1087-
const isLastMessage = i === sentMessages.length - 1;
1088-
1089-
const memory: Memory = {
1090-
id: stringToUuid(
1091-
sentMessage.message_id.toString() +
1092-
"-" +
1093-
this.runtime.agentId
1094-
),
1095-
agentId,
1096-
userId: agentId,
1097-
roomId,
1098-
content: {
1099-
...content,
1100-
text: sentMessage.text,
1101-
inReplyTo: messageId,
1102-
},
1103-
createdAt: sentMessage.date * 1000,
1104-
embedding: getEmbeddingZeroVector(),
1105-
};
1106-
1107-
// Set action to CONTINUE for all messages except the last one
1108-
// For the last message, use the original action from the response content
1109-
memory.content.action = !isLastMessage
1110-
? "CONTINUE"
1111-
: content.action;
1112-
1113-
await this.runtime.messageManager.createMemory(
1114-
memory
1115-
);
1116-
memories.push(memory);
1117-
}
1118-
1119-
return memories;
1120-
}
1121-
};
1122-
11231121
// Execute callback to send messages and log memories
11241122
const responseMessages = await callback(responseContent);
11251123

@@ -1135,7 +1133,7 @@ export class MessageManager {
11351133
);
11361134
}
11371135

1138-
await this.runtime.evaluate(memory, state, shouldRespond);
1136+
await this.runtime.evaluate(memory, state, shouldRespond, callback);
11391137
} catch (error) {
11401138
elizaLogger.error("❌ Error handling message:", error);
11411139
elizaLogger.error("Error sending message:", error);

packages/client-twitter/src/base.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getEmbeddingZeroVector,
99
elizaLogger,
1010
stringToUuid,
11+
ActionTimelineType,
1112
} from "@elizaos/core";
1213
import {
1314
QueryTweetsResponse,
@@ -317,14 +318,16 @@ export class ClientBase extends EventEmitter {
317318
return processedTimeline;
318319
}
319320

320-
async fetchTimelineForActions(count: number): Promise<Tweet[]> {
321+
async fetchTimelineForActions(): Promise<Tweet[]> {
321322
elizaLogger.debug("fetching timeline for actions");
322323

323324
const agentUsername = this.twitterConfig.TWITTER_USERNAME;
324-
const homeTimeline = await this.twitterClient.fetchHomeTimeline(
325-
count,
326-
[]
327-
);
325+
326+
const homeTimeline =
327+
this.twitterConfig.ACTION_TIMELINE_TYPE ===
328+
ActionTimelineType.Following
329+
? await this.twitterClient.fetchFollowingTimeline(20, [])
330+
: await this.twitterClient.fetchHomeTimeline(20, []);
328331

329332
return homeTimeline
330333
.map((tweet) => ({

packages/client-twitter/src/environment.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { parseBooleanFromText, IAgentRuntime } from "@elizaos/core";
1+
import {
2+
parseBooleanFromText,
3+
IAgentRuntime,
4+
ActionTimelineType,
5+
} from "@elizaos/core";
26
import { z, ZodError } from "zod";
37

48
export const DEFAULT_MAX_TWEET_LENGTH = 280;
@@ -67,6 +71,10 @@ export const twitterEnvSchema = z.object({
6771
ACTION_INTERVAL: z.number().int(),
6872
POST_IMMEDIATELY: z.boolean(),
6973
TWITTER_SPACES_ENABLE: z.boolean().default(false),
74+
MAX_ACTIONS_PROCESSING: z.number().int(),
75+
ACTION_TIMELINE_TYPE: z
76+
.nativeEnum(ActionTimelineType)
77+
.default(ActionTimelineType.ForYou),
7078
});
7179

7280
export type TwitterConfig = z.infer<typeof twitterEnvSchema>;
@@ -205,6 +213,16 @@ export async function validateTwitterConfig(
205213
runtime.getSetting("TWITTER_SPACES_ENABLE") ||
206214
process.env.TWITTER_SPACES_ENABLE
207215
) ?? false,
216+
217+
MAX_ACTIONS_PROCESSING: safeParseInt(
218+
runtime.getSetting("MAX_ACTIONS_PROCESSING") ||
219+
process.env.MAX_ACTIONS_PROCESSING,
220+
1
221+
),
222+
223+
ACTION_TIMELINE_TYPE:
224+
runtime.getSetting("ACTION_TIMELINE_TYPE") ||
225+
process.env.ACTION_TIMELINE_TYPE,
208226
};
209227

210228
return twitterEnvSchema.parse(twitterConfig);

0 commit comments

Comments
 (0)