Skip to content

Commit 4c53ea2

Browse files
authored
Merge pull request elizaOS#1824 from elizaOS/tcm-max-actions
feat: Optimize Agent Action Processing by Prioritizing Timelines and Limiting Actions Per Cycle
2 parents 12ead17 + 98d2c1e commit 4c53ea2

File tree

5 files changed

+324
-228
lines changed

5 files changed

+324
-228
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

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)