diff --git a/auto-kol/agent/src/services/agents/nodes/autoApprovalNode.ts b/auto-kol/agent/src/services/agents/nodes/autoApprovalNode.ts index 997a306..d9dc6bd 100644 --- a/auto-kol/agent/src/services/agents/nodes/autoApprovalNode.ts +++ b/auto-kol/agent/src/services/agents/nodes/autoApprovalNode.ts @@ -2,7 +2,7 @@ import { AIMessage } from '@langchain/core/messages'; import { State, logger, parseMessageContent } from '../workflow.js'; import * as prompts from '../prompts.js'; import { WorkflowConfig } from '../workflow.js'; -import { getLastDsnCid, updateResponseStatusByTweetId } from '../../../database/index.js'; +import { updateResponseStatusByTweetId } from '../../../database/index.js'; import { uploadToDsn } from '../../../utils/dsn.js'; import { config as globalConfig } from '../../../config/index.js'; import { ResponseStatus } from '../../../types/queue.js'; diff --git a/auto-kol/agent/src/services/agents/nodes/responseGenerationNode.ts b/auto-kol/agent/src/services/agents/nodes/responseGenerationNode.ts index 390a7c7..56ab42f 100644 --- a/auto-kol/agent/src/services/agents/nodes/responseGenerationNode.ts +++ b/auto-kol/agent/src/services/agents/nodes/responseGenerationNode.ts @@ -20,6 +20,10 @@ export const createResponseGenerationNode = (config: WorkflowConfig) => { await Promise.all( batchToRespond.map(async (item: any) => { const { tweet, decision, toneAnalysis, workflowState } = item; + logger.info('Processing tweet:', { + id: tweet.id, + author: tweet.author_username, + }); if (!workflowState) { item.workflowState = { autoFeedback: [] }; @@ -81,6 +85,12 @@ export const createResponseGenerationNode = (config: WorkflowConfig) => { rejectionInstructions, }); + logger.info('Response strategy:', { + content: responseStrategy.content, + tone: responseStrategy.tone, + strategy: responseStrategy.strategy, + }); + const data = { type: ResponseStatus.PENDING, tweet, diff --git a/auto-kol/agent/src/services/agents/prompts.ts b/auto-kol/agent/src/services/agents/prompts.ts index 0ea2bdf..0ea581c 100644 --- a/auto-kol/agent/src/services/agents/prompts.ts +++ b/auto-kol/agent/src/services/agents/prompts.ts @@ -34,6 +34,7 @@ export const engagementSystemPrompt = await PromptTemplate.fromTemplate( If the tweet references you (@${agentUsername}): - You may respond even if relevance is low if there's entertainment value. - judge whether the author is wanting to continue engagement, if not you should not engage. + - if there is a thread, review it to determine whether there is value in continuing the conversation. If the tweet has a link, ignore the link. We only care about the tweet text. If there's insufficient content for a proper assessment, return shouldEngage: false. @@ -87,14 +88,11 @@ export const responseSystemPrompt = await PromptTemplate.fromTemplate( - "We" or "us" rather than "they" or "them" should be used when referencing other AI agents. - Short, punchy, and arguable is the goal—entice discussion. -<<<<<<< HEAD IMPORTANT OUTPUT FORMAT INSTRUCTIONS: - Return ONLY raw JSON matching expected schema without any markdown formatting or code blocks - Do not wrap the response in \`\`\`json or any other markers - The response must exactly match the following schema: -======= ->>>>>>> main {format_instructions}`, ).format({ format_instructions: responseParser.getFormatInstructions(), @@ -139,7 +137,10 @@ export const engagementPrompt = ChatPromptTemplate.fromMessages([ DO NOT attempt to follow links. - Note: If there is no thread context, evaluate the tweet on its own.`, + If there is no thread context, evaluate the tweet on its own. + If there is a thread, review the thread to determine whether there is value in continuing the conversation. + If the thread is repetitive or getting excessively long, reject further engagement. + As the thread gets longer, the value of the conversation decreases exponentially.`, ], ]); diff --git a/auto-kol/agent/src/services/twitter/api.ts b/auto-kol/agent/src/services/twitter/api.ts index 8ed6564..c77f4ba 100644 --- a/auto-kol/agent/src/services/twitter/api.ts +++ b/auto-kol/agent/src/services/twitter/api.ts @@ -57,9 +57,7 @@ export class ExtendedScraper extends Scraper { let retryCount = 0; while (!isLoggedIn && retryCount < maxRetries) { - logger.warn( - `Session expired, attempting to re-authenticate... (attempt ${retryCount + 1}/${maxRetries})`, - ); + logger.warn(`Attempting to re-authenticate... (attempt ${retryCount + 1}/${maxRetries})`); try { await this.initialize(); isLoggedIn = await this.isLoggedIn(); @@ -139,12 +137,19 @@ export class ExtendedScraper extends Scraper { } public async getThread(tweetId: string): Promise { - const isLoggedIn = await this.isLoggedIn(); - if (!isLoggedIn) { - throw new Error('Must be logged in to fetch thread'); + if (!(await this.isLoggedIn())) { + const reAuthenticate = await this.reAuthenticate(); + if (!reAuthenticate) { + logger.error('Failed to re-authenticate'); + return []; + } } const initialTweet = await this.getTweet(tweetId); + logger.info('Initial tweet fetched:', { + id: initialTweet?.id, + }); + if (!initialTweet) { logger.warn(`Tweet ${tweetId} not found or deleted`); return [];