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

fix: Limit the number of timelines fetched #1931

Merged
merged 3 commits into from
Jan 7, 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
12 changes: 8 additions & 4 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ export class ClientBase extends EventEmitter {
return processedTimeline;
}

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

const agentUsername = this.twitterConfig.TWITTER_USERNAME;

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

return homeTimeline
.map((tweet) => ({
Expand Down Expand Up @@ -357,7 +357,11 @@ export class ClientBase extends EventEmitter {
(media) => media.type === "video"
) || [],
}))
.filter((tweet) => tweet.username !== agentUsername); // do not perform action on self-tweets
.filter((tweet) => tweet.username !== agentUsername) // do not perform action on self-tweets
.slice(0, count);
// TODO: Once the 'count' parameter is fixed in the 'fetchTimeline' method of the 'agent-twitter-client',
// this workaround can be removed.
// Related issue: https://github.com/elizaOS/agent-twitter-client/issues/43
}

async fetchSearchTweets(
Expand Down
9 changes: 5 additions & 4 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { DEFAULT_MAX_TWEET_LENGTH } from "./environment.ts";
import { State } from "@elizaos/core";
import { ActionResponse } from "@elizaos/core";

const MAX_TIMELINES_TO_FETCH = 15;

const twitterPostTemplate = `
# Areas of Expertise
{{knowledge}}
Expand Down Expand Up @@ -627,10 +629,9 @@ export class TwitterPostClient {
"twitter"
);

// TODO: Once the 'count' parameter is fixed in the 'fetchTimeline' method of the 'agent-twitter-client',
// we should enable the ability to control the number of items fetched here.
// Related issue: https://github.com/elizaOS/agent-twitter-client/issues/43
const homeTimeline = await this.client.fetchTimelineForActions();
const homeTimeline = await this.client.fetchTimelineForActions(
MAX_TIMELINES_TO_FETCH
);
const maxActionsProcessing =
this.client.twitterConfig.MAX_ACTIONS_PROCESSING;
const processedTimelines = [];
Expand Down
Loading