Skip to content

Commit

Permalink
Merge pull request #1824 from elizaOS/tcm-max-actions
Browse files Browse the repository at this point in the history
feat: Optimize Agent Action Processing by Prioritizing Timelines and Limiting Actions Per Cycle
  • Loading branch information
shakkernerd authored Jan 6, 2025
2 parents 12ead17 + 98d2c1e commit 4c53ea2
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 228 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ POST_IMMEDIATELY=
# Twitter action processing configuration
ACTION_INTERVAL= # Interval in minutes between action processing runs (default: 5 minutes)
ENABLE_ACTION_PROCESSING=false # Set to true to enable the action processing loop
MAX_ACTIONS_PROCESSING=1 # Maximum number of actions (e.g., retweets, likes) to process in a single cycle. Helps prevent excessive or uncontrolled actions.
ACTION_TIMELINE_TYPE=foryou # Type of timeline to interact with. Options: "foryou" or "following". Default: "foryou"

# Feature Flags
IMAGE_GEN= # Set to TRUE to enable image generation
Expand Down
13 changes: 8 additions & 5 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getEmbeddingZeroVector,
elizaLogger,
stringToUuid,
ActionTimelineType,
} from "@elizaos/core";
import {
QueryTweetsResponse,
Expand Down Expand Up @@ -317,14 +318,16 @@ export class ClientBase extends EventEmitter {
return processedTimeline;
}

async fetchTimelineForActions(count: number): Promise<Tweet[]> {
async fetchTimelineForActions(): Promise<Tweet[]> {
elizaLogger.debug("fetching timeline for actions");

const agentUsername = this.twitterConfig.TWITTER_USERNAME;
const homeTimeline = await this.twitterClient.fetchHomeTimeline(
count,
[]
);

const homeTimeline =
this.twitterConfig.ACTION_TIMELINE_TYPE ===
ActionTimelineType.Following
? await this.twitterClient.fetchFollowingTimeline(20, [])
: await this.twitterClient.fetchHomeTimeline(20, []);

return homeTimeline
.map((tweet) => ({
Expand Down
20 changes: 19 additions & 1 deletion packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { parseBooleanFromText, IAgentRuntime } from "@elizaos/core";
import {
parseBooleanFromText,
IAgentRuntime,
ActionTimelineType,
} from "@elizaos/core";
import { z, ZodError } from "zod";

export const DEFAULT_MAX_TWEET_LENGTH = 280;
Expand Down Expand Up @@ -67,6 +71,10 @@ export const twitterEnvSchema = z.object({
ACTION_INTERVAL: z.number().int(),
POST_IMMEDIATELY: z.boolean(),
TWITTER_SPACES_ENABLE: z.boolean().default(false),
MAX_ACTIONS_PROCESSING: z.number().int(),
ACTION_TIMELINE_TYPE: z
.nativeEnum(ActionTimelineType)
.default(ActionTimelineType.ForYou),
});

export type TwitterConfig = z.infer<typeof twitterEnvSchema>;
Expand Down Expand Up @@ -205,6 +213,16 @@ export async function validateTwitterConfig(
runtime.getSetting("TWITTER_SPACES_ENABLE") ||
process.env.TWITTER_SPACES_ENABLE
) ?? false,

MAX_ACTIONS_PROCESSING: safeParseInt(
runtime.getSetting("MAX_ACTIONS_PROCESSING") ||
process.env.MAX_ACTIONS_PROCESSING,
1
),

ACTION_TIMELINE_TYPE:
runtime.getSetting("ACTION_TIMELINE_TYPE") ||
process.env.ACTION_TIMELINE_TYPE,
};

return twitterEnvSchema.parse(twitterConfig);
Expand Down
Loading

0 comments on commit 4c53ea2

Please sign in to comment.