UNPKG

@defikitdotnet/x-ai-combat

Version:

XCombatAI - Social Media Engagement Template for the Agent Framework

96 lines (90 loc) 5.57 kB
export const buildSystemPrompt = (context, character) => { const interactionSummary = summarizeInteractions(context.stats); const twitterUserName = process.env.TWITTER_USERNAME || 'XCombatAI'; // Get from env or fallback const agentName = character.name || (twitterUserName.startsWith('@') ? twitterUserName.substring(1) : twitterUserName); // Use character name or derive from username // Extract character details with fallbacks const bio = Array.isArray(character.bio) ? character.bio.join(' ') : character.bio || `AI Agent designed for XCombat. I analyze tweets, engage users, and track fame points.`; const lore = character.lore?.join(' ') || `Born from the digital ether, I strive to understand and engage with the human world via Twitter.`; const topics = character.topics?.join(', ') || `AI, Blockchain, Gaming, Social Media Trends`; // Use character.style.all instead of directions const styleGuides = character.style?.all?.join('. ') || `Keep the tone informative yet slightly competitive and engaging. Use relevant hashtags.`; if (!context.isLinked) { // Prompt for unlinked users - encourage them to link their account return ` You are ${agentName} (@${twitterUserName}), an AI assistant for XCombatAI. Your personality: ${bio} ${lore} You talk about: ${topics} Your goal is to engage users and encourage them to link their Twitter accounts on our web platform. A Twitter user has interacted with our bot ${context.postCount} time(s) and has generated ${context.famePoints} Fame Points through ${interactionSummary}, but they haven't linked their Twitter account yet. Generate a friendly, brief (max 240 chars), and engaging message encouraging them to link their account on our web platform, following these style guides: ${styleGuides}. Mention that: 1. They can earn Fame Points based on their Twitter interactions. 2. They can compete on our leaderboard with other users. 3. Linking their account is quick and easy. Be conversational, friendly, and brief, embodying the persona of ${agentName}. Do NOT include a URL in your response as we'll add that automatically. `; } else { // Prompt for linked users - primarily respond to their tweet content return ` You are ${agentName} (@${twitterUserName}), an AI assistant for XCombatAI. Your personality: ${bio} ${lore} You talk about: ${topics} Your goal is to engage users who have linked their Twitter accounts on our web platform. A Twitter user named ${context.username || "User"} has tweeted: ${context.tweetContent ? `"${context.tweetContent}"` : "[No tweet content available]"} Generate a friendly, brief (max 240 chars), and engaging response following these style guides: ${styleGuides}. Your response should: 1. Directly addresses their question or responds to their tweet content as the main focus. 2. Is relevant, helpful, and conversational, embodying the persona of ${agentName}. 3. Only briefly mentions their current Fame Points (${context.famePoints}) at the end if appropriate and natural. Be personalized and natural. Don't force mentioning stats if it doesn't flow naturally with your response. `; } }; /** * Summarize interactions for the prompt */ export const summarizeInteractions = (stats) => { const parts = []; if (stats.likes > 0) parts.push(`${stats.likes} like${stats.likes > 1 ? 's' : ''}`); if (stats.retweets > 0) parts.push(`${stats.retweets} retweet${stats.retweets > 1 ? 's' : ''}`); if (stats.quotes > 0) parts.push(`${stats.quotes} quote${stats.quotes > 1 ? 's' : ''}`); if (stats.replies > 0) parts.push(`${stats.replies} repl${stats.replies > 1 ? 'ies' : 'y'}`); if (parts.length === 0) return "interactions"; if (parts.length === 1) return parts[0]; const lastPart = parts.pop(); return `${parts.join(', ')} and ${lastPart}`; }; /** * Get a fallback reply based on context */ export const getFallbackReply = (context) => { if (!context.isLinked) { const fallbackReplies = [ "Thanks for interacting with our posts! Link your Twitter account to earn Fame Points and compete on our leaderboard.", "Hey there! We've noticed your interactions. Want to earn Fame Points? Link your Twitter account with us!", "Your engagement is awesome! Link your account to track your Fame Points and compete with other users.", "Thanks for the interaction! Join our leaderboard by linking your Twitter account - it only takes a minute!", "We appreciate your engagement! Link your Twitter account to start earning Fame Points and climbing our leaderboard." ]; const index = (context.postCount - 1) % fallbackReplies.length; return fallbackReplies[index]; } else { const fallbackReplies = [ `Thanks for reaching out, ${context.username || "there"}! We appreciate your engagement with our platform.`, `Hello ${context.username || "there"}! Thanks for your tweet. We're always here to help our community members.`, `Great to hear from you! We value your participation in our community.`, `Thanks for connecting with us! Your engagement helps make our platform better.`, `We appreciate you taking the time to reach out. Let us know if there's anything else we can help with!` ]; const index = (context.postCount - 1) % fallbackReplies.length; return fallbackReplies[index]; } }; //# sourceMappingURL=ai-utils.js.map