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

Update prompt to end endless threads + cleanups #88

Merged
merged 6 commits into from
Dec 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions auto-kol/agent/src/services/agents/nodes/responseGenerationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] };
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions auto-kol/agent/src/services/agents/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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.`,
],
]);

Expand Down
17 changes: 11 additions & 6 deletions auto-kol/agent/src/services/twitter/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -139,12 +137,19 @@ export class ExtendedScraper extends Scraper {
}

public async getThread(tweetId: string): Promise<Tweet[]> {
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 [];
Expand Down
Loading