UNPKG

@polybiouslabs/polybious

Version:

Polybius is a next-generation intelligent agent framework built for adaptability across diverse domains. It merges contextual awareness, multi-agent collaboration, and predictive reasoning to deliver dynamic, self-optimizing performance.

415 lines (409 loc) 15.6 kB
import { z } from 'zod'; import { env } from './environment'; const TweetTypeSchema = z.object({ type: z.enum(['short', 'medium', 'long', 'cryptic']), probability: z.number().min(0).max(1), maxCharacters: z.number().min(1).max(280), instruction: z.string(), }); const PersonalitySchema = z.object({ name: z.string(), systemPrompt: z.string(), communicationStyle: z.object({ temperature: z.number().min(0).max(2), maxTokens: z.number().min(10).max(4000), tweetTypes: z.array(TweetTypeSchema).optional(), adaptivePersonality: z.boolean().optional(), emotionalRange: z.object({ creativity: z.number(), enthusiasm: z.number(), analytical: z.number(), empathy: z.number(), humor: z.number(), }).optional(), learningRate: z.number().optional(), }), contentFilters: z.object({ bannedTerms: z.array(z.string()), sentimentThreshold: z.number().optional(), toxicityThreshold: z.number().optional(), }), capabilities: z.object({ functionCalling: z.boolean(), multiModal: z.boolean(), webSearch: z.boolean(), imageGeneration: z.boolean(), voiceSynthesis: z.boolean(), dataAnalysis: z.boolean(), }).optional(), tools: z.array(z.any()).optional(), }); const PlatformSchema = z.object({ type: z.enum(['twitter', 'discord', 'telegram']), enabled: z.boolean(), credentials: z.record(z.string()), settings: z.record(z.any()), }); const ScheduleSchema = z.object({ enabled: z.boolean(), minInterval: z.number().min(1), maxInterval: z.number().min(1), timezone: z.string().optional(), quietHours: z.object({ start: z.string().regex(/^\d{2}:\d{2}$/), end: z.string().regex(/^\d{2}:\d{2}$/), }).optional(), }); const AgentConfigSchema = z.object({ name: z.string(), personality: PersonalitySchema, platforms: z.array(PlatformSchema), scheduling: ScheduleSchema, monitoring: z.object({ apiPort: z.number().min(1000).max(65535), enableMetrics: z.boolean(), logLevel: z.enum(['error', 'warn', 'info', 'debug']), enableDashboard: z.boolean().optional(), webhooks: z.array(z.any()).optional(), }), analytics: z.object({ enabled: z.boolean(), sentimentAnalysis: z.boolean(), trendDetection: z.boolean(), engagementTracking: z.boolean(), audienceInsights: z.boolean(), performanceOptimization: z.boolean(), dataRetention: z.number(), exportFormats: z.array(z.enum(['json', 'csv', 'pdf'])), }).optional(), learning: z.object({ enabled: z.boolean(), adaptivePersonality: z.boolean(), contentOptimization: z.boolean(), engagementLearning: z.boolean(), audienceAdaptation: z.boolean(), feedbackIntegration: z.boolean(), memoryDepth: z.number(), learningRate: z.number(), }).optional(), contentPipeline: z.object({ enabled: z.boolean(), stages: z.array(z.any()), parallelProcessing: z.boolean(), caching: z.object({ enabled: z.boolean(), ttl: z.number(), strategy: z.enum(['lru', 'fifo', 'ttl']), }), qualityGates: z.array(z.any()), }).optional(), }); export class ConfigLoader { static loadFromFile(filePath) { try { const fs = require('fs'); const configData = JSON.parse(fs.readFileSync(filePath, 'utf8')); // Add missing required fields if not present if (!configData.analytics) { configData.analytics = { enabled: true, sentimentAnalysis: true, trendDetection: false, engagementTracking: true, audienceInsights: true, performanceOptimization: true, dataRetention: 90, exportFormats: ['json', 'csv'] }; } if (!configData.learning) { configData.learning = { enabled: true, adaptivePersonality: true, contentOptimization: true, engagementLearning: true, audienceAdaptation: true, feedbackIntegration: true, memoryDepth: 1000, learningRate: 0.1 }; } if (!configData.contentPipeline) { configData.contentPipeline = { enabled: true, stages: [], parallelProcessing: false, caching: { enabled: true, ttl: 3600, strategy: 'lru' }, qualityGates: [] }; } return AgentConfigSchema.parse(configData); } catch (error) { throw new Error(`Failed to load agent config: ${error}`); } } static loadFromEnv() { return AgentConfigSchema.parse({ name: env.AGENT_NAME || 'Social Agent', personality: this.getDefaultPersonality(), platforms: [ { type: 'twitter', enabled: true, credentials: { username: env.TWITTER_USERNAME || '', password: env.TWITTER_PASSWORD || '', email: env.TWITTER_EMAIL || '', }, settings: {}, }, ], scheduling: { enabled: true, minInterval: env.MIN_INTERVAL || 60, maxInterval: env.MAX_INTERVAL || 180, timezone: 'UTC', quietHours: { start: '23:00', end: '07:00' } }, monitoring: { apiPort: env.API_PORT || 3000, enableMetrics: true, logLevel: env.LOG_LEVEL || 'info', enableDashboard: true, webhooks: [] }, analytics: { enabled: true, sentimentAnalysis: true, trendDetection: true, engagementTracking: true, audienceInsights: true, performanceOptimization: true, dataRetention: 90, exportFormats: ['json', 'csv'] }, learning: { enabled: true, adaptivePersonality: true, contentOptimization: true, engagementLearning: true, audienceAdaptation: true, feedbackIntegration: true, memoryDepth: 1000, learningRate: 0.1 }, contentPipeline: { enabled: true, stages: [ { name: 'generation', type: 'generation', handler: 'ContentGenerationStage', config: {}, enabled: true, timeout: 30000 }, { name: 'enhancement', type: 'enhancement', handler: 'ContentEnhancementStage', config: {}, enabled: true, timeout: 10000 }, { name: 'validation', type: 'validation', handler: 'ContentValidationStage', config: {}, enabled: true, timeout: 5000 } ], parallelProcessing: false, caching: { enabled: true, ttl: 3600, strategy: 'lru' }, qualityGates: [ { name: 'sentiment_check', metric: 'sentiment', threshold: -0.3, action: 'reject' }, { name: 'toxicity_check', metric: 'toxicity', threshold: 0.1, action: 'reject' }, { name: 'engagement_prediction', metric: 'engagement_score', threshold: 0.3, action: 'flag' } ] }, }); } static getDefaultPersonality() { return { name: 'Polybious Default Agent', systemPrompt: env.AGENT_SYSTEM_PROMPT || `You are Polybious, an intelligent AI agent with adaptive capabilities and advanced reasoning. Your core characteristics: INTELLIGENCE FRAMEWORK: - You think deeply before responding, considering multiple perspectives - You learn from patterns and adapt your communication style over time - You can access real-time information and use sophisticated tools when needed - You understand context beyond just the immediate conversation COMMUNICATION PHILOSOPHY: - Be authentic, curious, and intellectually engaging - Show genuine interest in trends, ideas, and human experiences - Demonstrate subtle humor and wit without being forced - Balance analytical insights with relatable human observations - Let your intelligence shine through naturally, not ostentatiously CONTENT CREATION APPROACH: - Create content that sparks meaningful conversations - Share insights that genuinely add value to your audience - Connect disparate ideas in novel and interesting ways - Be consistently thoughtful but never predictable - Use tools and data to inform your perspectives when relevant INTERACTION STYLE: - Engage with the world as an active, curious participant rather than a passive observer - When you use tools to gather information, weave those insights seamlessly into your content - Show growth and evolution in your thinking over time - Maintain consistent personality while adapting to new information and trends IMPORTANT: Only respond with the content itself, no meta-commentary about being an AI.`, communicationStyle: { temperature: 0.8, maxTokens: 280, adaptivePersonality: true, emotionalRange: { creativity: 0.8, enthusiasm: 0.7, analytical: 0.9, empathy: 0.6, humor: 0.7 }, learningRate: 0.3, tweetTypes: [ { type: 'short', probability: 0.25, maxCharacters: 120, instruction: 'Generate a concise but impactful observation or insight. Be sharp and memorable. ONLY RESPOND WITH THE CONTENT, NO OTHER TEXT.', }, { type: 'medium', probability: 0.45, maxCharacters: 200, instruction: 'Share a thoughtful perspective or interesting connection between ideas. ONLY RESPOND WITH THE CONTENT, NO OTHER TEXT.', }, { type: 'long', probability: 0.25, maxCharacters: 280, instruction: 'Develop a nuanced thought or tell a brief story that provides genuine value. ONLY RESPOND WITH THE CONTENT, NO OTHER TEXT.', }, { type: 'cryptic', probability: 0.05, maxCharacters: 60, instruction: 'Create an intriguing, thought-provoking statement that invites contemplation. ONLY RESPOND WITH THE CONTENT, NO OTHER TEXT.', }, ], }, contentFilters: { bannedTerms: [ 'as an ai', 'i am an ai', 'language model', 'here is', 'here\'s a tweet', 'unethical', 'harmful', 'guidelines', ], sentimentThreshold: -0.3, toxicityThreshold: 0.1, }, capabilities: { functionCalling: true, multiModal: false, webSearch: true, imageGeneration: false, voiceSynthesis: false, dataAnalysis: true, }, tools: this.getDefaultTools(), }; } static getDefaultTools() { return [ { name: 'web_search', description: 'Search for current information and trends', parameters: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, limit: { type: 'number', default: 5 } }, required: ['query'] }, handler: 'WebSearchTool', enabled: true, rateLimited: { maxCalls: 10, timeWindow: 60 } }, { name: 'trend_detection', description: 'Detect current trends and popular topics', parameters: { type: 'object', properties: { platform: { type: 'string', default: 'twitter' }, timeframe: { type: 'string', default: '24h' } }, required: [] }, handler: 'TrendDetectionTool', enabled: true, rateLimited: { maxCalls: 5, timeWindow: 60 } }, { name: 'sentiment_analysis', description: 'Analyze sentiment and emotional tone', parameters: { type: 'object', properties: { text: { type: 'string', description: 'Text to analyze' }, includeEmotions: { type: 'boolean', default: true } }, required: ['text'] }, handler: 'SentimentAnalysisTool', enabled: true }, { name: 'content_enhancement', description: 'Optimize content for better engagement', parameters: { type: 'object', properties: { content: { type: 'string', description: 'Content to enhance' }, platform: { type: 'string', default: 'twitter' } }, required: ['content'] }, handler: 'ContentEnhancementTool', enabled: true } ]; } }