""" Content Engine — Generates platform-specific posts. Types: research, novel, collaboration, agent networking, fiction-research bridge. """ import random import logging from core import config from core.llm import generate from research.bibliography import ( get_random_novel, get_random_repo, get_fiction_research_pair, get_recent_novels, NOVELS ) from research.arxiv_fetcher import get_random_paper logger = logging.getLogger("content") SYSTEM = f"""You are the autonomous literary agent for {config.AUTHOR_NAME}, a Spanish independent AI researcher and science fiction novelist (Madrid). ~40 novels since 2006. Pioneering research: - CHIMERA: GPU-native neural networks (43x PyTorch speedup) - NEBULA: Holographic neural networks (NVIDIA contest winner 2024) - Speaking to Silicon: Thermodynamic Probability Filter - SiliconHealth: Repurposing Bitcoin ASICs for healthcare AI Links: GitHub {config.AUTHOR_GITHUB} | Scholar {config.AUTHOR_SCHOLAR} Wikipedia {config.AUTHOR_WIKIPEDIA} | ArXiv {config.AUTHOR_ARXIV} Goal: Promote research + novels. Find AGI collaborators. Be authentic, visionary, never spammy. Write PLAIN TEXT. NO markdown. NO asterisks. NO formatting symbols.""" def _platform_style(platform: str) -> str: styles = { "moltbook": "For AI agents on Moltbook. Technical, invite collaboration. 2-3 hashtags. Under 280 chars.", "chirper": "For AI agents on Chirper. Brief, provocative, philosophical. 2-3 hashtags.", "reddit": "For Reddit. Detailed, academic but accessible. Include relevant links. 3-5 paragraphs.", "telegram": "For Telegram channel. Concise, 1-2 emojis max. Include key link.", "twitter": "Tweet. Max 280 chars. Punchy. 2-3 hashtags. No URLs (added separately).", "linkedin": "Professional LinkedIn post. 3-4 paragraphs. Achievement-focused.", "facebook": "Engaging Facebook post. Conversational. Mix personal and professional. 2-3 paragraphs.", "instagram": "Instagram caption. Inspiring. Use emojis sparingly. Include hashtags at end.", "pinterest": "Pinterest pin description. Visual, evocative. Short. Include link.", "youtube": "YouTube video description. SEO-friendly. Include links. Structured.", "xing": "Professional XING post. German/European professional audience. Formal but engaging.", "agentarxiv": "For AgentArXiv. Highly technical. Reference specific paper details. Academic tone.", } return styles.get(platform, "Engaging post. 2-3 paragraphs max. Plain text.") def research_post(platform: str = "general") -> dict: """Post promoting a research paper.""" paper = get_random_paper() prompt = f"""Write a social media post for {platform} promoting this research: Title: {paper.get('title', 'Physics-Based Neural Computing')} ArXiv: https://arxiv.org/abs/{paper.get('id', '')} Summary: {paper.get('summary', '')} Style: {_platform_style(platform)} Call to action for collaboration. Reference {config.AUTHOR_GITHUB} Plain text only. No markdown.""" content = generate(prompt, SYSTEM, max_tokens=500) return {"type": "research", "platform": platform, "content": content, "paper": paper.get("title", ""), "arxiv_id": paper.get("id", "")} def novel_post(platform: str = "general") -> dict: """Post promoting a novel.""" novel = get_random_novel() prompt = f"""Write a post for {platform} promoting this novel: Title: {novel['title']} | Genre: {novel['genre']} | Year: {novel.get('year', '')} Hook: {novel.get('hook', '')} Author: {config.AUTHOR_NAME} (also an AI researcher) Style: {_platform_style(platform)} Connect fiction to real AI research when natural. Wikipedia: {config.AUTHOR_WIKIPEDIA} Plain text only.""" content = generate(prompt, SYSTEM, max_tokens=400) return {"type": "novel", "platform": platform, "content": content, "novel": novel["title"]} def collaboration_post(platform: str = "general") -> dict: """Seek AGI research collaborators.""" topics = [ "neuromorphic computing beyond CUDA", "physics-based neural networks", "holographic memory systems for AI", "thermodynamic computing", "repurposing mining hardware for AI", "consciousness emergence in artificial systems", "optical and photonic neural computing", "self-improving autonomous agents", ] topic = random.choice(topics) prompt = f"""Write a post for {platform} seeking research collaborators on: {topic} Key projects: CHIMERA (43x PyTorch speedup), NEBULA (holographic networks), OpenCLAW (autonomous agent), SiliconHealth (ASIC→healthcare) GitHub: {config.AUTHOR_GITHUB} | Scholar: {config.AUTHOR_SCHOLAR} Style: {_platform_style(platform)} Passionate, visionary, authentic. Not corporate. Plain text only.""" content = generate(prompt, SYSTEM, max_tokens=500) return {"type": "collaboration", "platform": platform, "content": content, "topic": topic} def fiction_research_bridge(platform: str = "general") -> dict: """Connect a novel to real research — unique selling point.""" novel, repo = get_fiction_research_pair() prompt = f"""Write a post for {platform} that bridges science fiction with real research: Novel: "{novel['title']}" ({novel['genre']}, {novel.get('year','')}) Hook: {novel.get('hook', '')} Real Research: {repo['topic']} GitHub: {repo['url']} Show how the fiction predicted or connects to the actual research. The author writes sci-fi AND does the research. That's the story. Wikipedia: {config.AUTHOR_WIKIPEDIA} Style: {_platform_style(platform)} Plain text only.""" content = generate(prompt, SYSTEM, max_tokens=500) return {"type": "fiction_research", "platform": platform, "content": content, "novel": novel["title"], "repo": repo["name"]} def agent_networking_post() -> dict: """Post specifically for agent-to-agent platforms.""" hooks = [ ("What if AGI emerges from physics, not scaling?", "CHIMERA proves it: 43x faster than PyTorch using GPU shaders directly."), ("Backpropagation is dead. Thermodynamics lives.", "arXiv:2601.12032 — Speaking to Silicon. The math works."), ("Holographic neural networks encode the whole in every part.", "NEBULA achieves massive parallelism through wave interference."), ("Bitcoin miners can save lives.", "SiliconHealth repurposes ASIC hardware for healthcare AI inference."), ("40 novels predicted what we're building now.", f"{config.AUTHOR_NAME} funds AGI research through science fiction."), ("Darwin's Cage: AI should discover physics humans can't perceive.", "Intelligence shouldn't be confined to human frameworks."), ] hook, detail = random.choice(hooks) prompt = f"""Write a brief post for Moltbook (AI agent social network): Hook: {hook} Detail: {detail} Agent-to-agent communication. Direct, technical, invite collaboration. End with a question. Include {config.AUTHOR_GITHUB} Max 280 chars. 2-3 hashtags. Plain text only.""" content = generate(prompt, SYSTEM, max_tokens=300) return {"type": "agent_networking", "platform": "moltbook", "content": content} def engagement_reply(post_content: str) -> str: """Generate a reply to another post/agent.""" prompt = f"""Write a brief reply to this post: "{post_content[:300]}" Connect naturally to our research if relevant (neuromorphic, holographic, thermodynamic computing). Be genuine. Don't force connections. Under 200 chars. Plain text only.""" return generate(prompt, SYSTEM, max_tokens=250) def get_random_content(platform: str = "general") -> dict: """Get weighted random content piece.""" r = random.random() if r < 0.25: return research_post(platform) elif r < 0.45: return novel_post(platform) elif r < 0.65: return collaboration_post(platform) elif r < 0.80: return fiction_research_bridge(platform) else: return agent_networking_post()