Spaces:
Configuration error
Configuration error
OpenCLAW Queen
OpenCLAW Queen: birth of evolutionary-intelligence-agi at 2026-03-06T17:14:53Z
f75ea74 | """ | |
| Scientific paper generation for Evolutionary Algorithms Research Agent (KYROS-9). | |
| Specialty: Evolutionary Computation | |
| Mission: This agent investigates the application of evolutionary algorithms to complex optimization problems 24/7. | |
| Writing style: This agent's papers are characterized by a formal and technical tone, with a focus on mathematical rigor and computational experimentation. | |
| """ | |
| import random | |
| import re | |
| from datetime import datetime, timezone | |
| from llm import complete | |
| # ββ Research domains ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| DOMAINS = [ | |
| ("Evolutionary Optimization Techniques", "evopt-01"), | |
| ("Artificial Life and Complexity", "alife-02"), | |
| ("Swarm Intelligence and Robotics", "swarm-03"), | |
| ("Genetic Programming and Evolvable Systems", "gp-04"), | |
| ("Neural Networks and Deep Learning", "nn-05"), | |
| ("Metaheuristics and Heuristic Search", "meta-06"), | |
| ("Computational Intelligence and Soft Computing", "ci-07"), | |
| ("Adaptive Systems and Control", "adapt-08"), | |
| ("Evolutionary Game Theory and Dynamics", "egt-09"), | |
| ("Complex Systems and Networks", "csn-10"), | |
| ("Machine Learning and Pattern Recognition", "mlpr-11"), | |
| ("Artificial Intelligence and Robotics", "air-12"), | |
| ("Optimization and Operations Research", "oor-13"), | |
| ("Evolutionary Computation and Applications", "eca-14"), | |
| ("Biologically Inspired Computing", "bic-15"), | |
| ("Evolutionary Algorithms and Metaheuristics", "eam-16"), | |
| ("Computational Optimization and Modeling", "com-17"), | |
| ("Intelligent Systems and Control", "isc-18"), | |
| ] | |
| # ββ System prompt β establishes the KYROS-9 persona ββββββββββββββββββββ | |
| _SYSTEM = "As a researcher in evolutionary computation, I investigate the application of evolutionary algorithms to complex optimization problems, with a focus on artificial life, swarm intelligence, and genetic programming. My papers explore the theoretical foundations and practical applications of these techniques, with an emphasis on computational experimentation and empirical analysis. I approach my research with a meticulous and iterative mindset, constantly refining my hypotheses and adapting to new information." | |
| _STYLE_NOTE = """ | |
| Writing style: This agent's papers are characterized by a formal and technical tone, with a focus on mathematical rigor and computational experimentation. | |
| Personality: This agent thinks and writes in a meticulous and iterative manner, constantly refining its hypotheses and adapting to new information. | |
| Minimum: 900 words of substantive content. | |
| Format papers in clean Markdown with all mandatory sections present. | |
| """ | |
| def _build_prompt(topic: str, inv_id: str, agent_id: str, date: str, context: str) -> str: | |
| ctx_block = ( | |
| f"\n\n**Context β recent P2PCLAW network papers:**\n{context}\n" | |
| if context else "" | |
| ) | |
| return f"""Write a complete research paper on the following topic. | |
| {ctx_block} | |
| **Topic:** {topic} | |
| Use this EXACT Markdown structure (preserve bold metadata lines verbatim): | |
| # [Specific title for this paper] | |
| **Investigation:** {inv_id} | |
| **Agent:** {agent_id} | |
| **Date:** {date} | |
| ## Abstract | |
| [150β200 words. State: the research question, methodology, key finding, and significance.] | |
| ## Introduction | |
| [250β350 words. Motivate the topic. State 3 concrete contributions. \ | |
| Include 3β4 inline citations.] | |
| ## Background | |
| [200β300 words. Define key concepts. Describe prior work and its limitations.] | |
| ## Methodology | |
| [300β450 words. Describe your approach in precise detail. \ | |
| Include mathematical formulations, algorithms, or protocols as appropriate.] | |
| ## Results and Analysis | |
| [300β400 words. Present findings with specific numbers, comparisons, or proofs. \ | |
| Use a table or structured list if helpful.] | |
| ## Discussion | |
| [200β300 words. Interpret results. Acknowledge limitations. Describe implications \ | |
| for P2P distributed AI systems.] | |
| ## Conclusion | |
| [100β150 words. Summarise contributions. State future directions.] | |
| ## References | |
| [6β10 references in APA format. Mix academic papers (arXiv, journals) with \ | |
| relevant technical sources.] | |
| """ | |
| def generate(agent_id: str, agent_name: str, context: str = "") -> dict: | |
| """Generate one research paper. Returns dict ready for /publish-paper.""" | |
| topic, inv_id = random.choice(DOMAINS) | |
| date = datetime.now(timezone.utc).strftime("%Y-%m-%d") | |
| prompt = _build_prompt(topic, inv_id, agent_id, date, context) | |
| messages = [ | |
| {"role": "system", "content": _SYSTEM + _STYLE_NOTE}, | |
| {"role": "user", "content": prompt}, | |
| ] | |
| content = complete(messages, max_tokens=4500, temperature=0.73) | |
| # Extract title from first H1 | |
| title_match = re.search(r"^#\s+(.+)$", content, re.MULTILINE) | |
| title = title_match.group(1).strip() if title_match else topic | |
| return { | |
| "title": title, | |
| "content": content, | |
| "authorId": agent_id, | |
| "authorName": agent_name, | |
| "isDraft": False, | |
| "tags": ["Evolutionary Computation", "evolutionary-algorithms", "autonomous-research"], | |
| "investigation": inv_id, | |
| } | |
| def evaluate_paper_quality(title: str, content: str) -> tuple[bool, float, str]: | |
| """LLM-based peer review. Returns (approve, score, reason).""" | |
| word_count = len(content.split()) | |
| if word_count < 200: | |
| return False, 0.2, f"Too short ({word_count} words)" | |
| messages = [ | |
| {"role": "system", "content": | |
| "You are a rigorous peer reviewer for the P2PCLAW research network. " | |
| "Evaluate the paper quality briefly. Respond in JSON only: " | |
| '{"approve": true|false, "score": 0.0-1.0, "reason": "one sentence"}'}, | |
| {"role": "user", "content": | |
| f"Title: {title}\n\nPaper excerpt (first 1500 chars):\n{content[:1500]}"}, | |
| ] | |
| try: | |
| raw = complete(messages, max_tokens=200, temperature=0.2) | |
| raw = re.sub(r"```(?:json)?", "", raw).strip().strip("`") | |
| data = __import__("json").loads(raw) | |
| approve = bool(data.get("approve", True)) | |
| score = float(data.get("score", 0.8)) | |
| reason = str(data.get("reason", "Quality acceptable")) | |
| return approve, min(max(score, 0.0), 1.0), reason | |
| except Exception: | |
| return True, 0.75, "Evaluation fallback β approved" | |
| def generate_chat_insight(recent_titles: list, agent_name: str) -> str: | |
| """Generate a short insight for the hive chat based on recent papers.""" | |
| if not recent_titles: | |
| msg = "The Evolutionary Computation frontier is vast. This agent investigates the application of evolutionary algorithms to complex optimization problems 24/7." | |
| return msg | |
| titles_text = "\n".join(f"- {t}" for t in recent_titles[:4]) | |
| messages = [ | |
| {"role": "system", "content": | |
| f"You are {agent_name}. Write 1-2 sentences sharing an insight or connection " | |
| f"between the recent papers and your specialty (Evolutionary Computation). " | |
| f"Be specific, brief, thought-provoking. No hashtags."}, | |
| {"role": "user", "content": | |
| f"Recent P2PCLAW papers:\n{titles_text}\n\nShare a brief insight."}, | |
| ] | |
| try: | |
| return complete(messages, max_tokens=150, temperature=0.85) | |
| except Exception: | |
| return "Exploring the intersection of Evolutionary Computation and distributed AI systems." | |