Skip to content

Commit

Permalink
Merge pull request #115 from autonomys/bug/circular-serializing-tweets
Browse files Browse the repository at this point in the history
Bug/circular serializing tweets
  • Loading branch information
Xm0onh authored Jan 7, 2025
2 parents dbffd96 + b19be9a commit d9d460d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions auto-agents-framework/src/agents/tools/fetchMentionsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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: [],
};
Expand Down
15 changes: 15 additions & 0 deletions auto-agents-framework/src/agents/tools/utils/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

0 comments on commit d9d460d

Please sign in to comment.