diff --git a/auto-agents-framework/src/agents/tools/fetchMentionsTool.ts b/auto-agents-framework/src/agents/tools/fetchMentionsTool.ts index 40a426d1..48f6e107 100644 --- a/auto-agents-framework/src/agents/tools/fetchMentionsTool.ts +++ b/auto-agents-framework/src/agents/tools/fetchMentionsTool.ts @@ -4,6 +4,7 @@ import { createLogger } from '../../utils/logger.js'; import { TwitterApi } from '../../services/twitter/types.js'; import { ToolNode } from '@langchain/langgraph/prebuilt'; import { AIMessage } from '@langchain/core/messages'; +import { cleanTweetForCircularReferences } from './utils/twitter.js'; const logger = createLogger('fetch-mentions-tool'); @@ -15,12 +16,11 @@ export const createFetchMentionsTool = (twitterApi: TwitterApi) => func: async ({ maxMentions, sinceId }: { maxMentions: number; sinceId?: string }) => { try { const recentMentions = await twitterApi.getMyUnrepliedToMentions(maxMentions, sinceId); - return { - tweets: recentMentions, + tweets: recentMentions.map(cleanTweetForCircularReferences), }; } catch (error) { - logger.error('Error in fetchTimelineTool:', error); + logger.error('Error in fetchMentionsTool:', error); return { tweets: [], }; diff --git a/auto-agents-framework/src/agents/tools/utils/twitter.ts b/auto-agents-framework/src/agents/tools/utils/twitter.ts index 69fe16cc..a05f85c9 100644 --- a/auto-agents-framework/src/agents/tools/utils/twitter.ts +++ b/auto-agents-framework/src/agents/tools/utils/twitter.ts @@ -39,3 +39,18 @@ export const convertMessageContentToTweets = (messageContent: MessageContent): T return []; } }; + +export const cleanTweetForCircularReferences = (tweet: Tweet): Tweet => ({ + ...tweet, + thread: tweet.thread + ?.filter(t => t.id !== tweet.id) + .map(t => ({ + id: t.id, + text: t.text, + username: t.username, + timeParsed: t.timeParsed, + })) as Tweet[], + inReplyToStatus: undefined, + quotedStatus: undefined, + retweetedStatus: undefined, +});