Skip to content

LeoYeAI/agent-master-skills / skills/anima-aios

anima-aios

Verified

An AI Agent cognitive growth system built on the native OpenClaw architecture. It provides agents with persistent memory management, visual intimacy progression, a 5-dimensional cognitive profile, gamified daily quests, team leaderboards, and a 5-layer memory architecture with Knowledge Palace, Pyramid thinking, and Ebbinghaus decay function. 基于 OpenClaw 原生架构的 AI Agent 认知成长体系,为 Agent 提供五层记忆架构、知识宫殿、金字塔知识组织、记忆衰减函数、LLM 智能处理、永久化记忆管理、可视化亲密度成长、五维认知画像、游戏化每日任务和团队排行榜。

FileKindSize
CHANGELOG.mdmarkdown2.4 KB
CONTRIBUTING.mdmarkdown3.3 KB
PLAN_v6.2.3.mdmarkdown5.3 KB
README.mdmarkdown5.1 KB
README_CN.mdmarkdown7.2 KB
RELEASE_v6.2.1.mdmarkdown3.5 KB
RELEASE_v6.2.2.mdmarkdown5.0 KB
RELEASE_v6.2.3.mdmarkdown4.0 KB
SECURITY.mdmarkdown2.6 KB
SECURITY_RESPONSE.mdmarkdown5.9 KB
SKILL.mdskill md23.5 KB
__init__.pyscript71 B
_meta.jsonconfig453 B
anima_doctor.pyscript26.4 KB
anima_tools.pyscript37.2 KB
config/__init__.pyscript0 B
config/agents/template.jsonconfig683 B
config/anima_config.template.jsonconfig1.5 KB
config/config_loader.pyscript9.3 KB
config/organization_config.jsonconfig1.2 KB
config/path_config.pyscript7.2 KB
core/__init__.pyscript1.5 KB
core/agent_resolver.pyscript5.1 KB
core/cognitive_profile.pyscript13.5 KB
core/daily_quest.pyscript13.9 KB
core/decay_function.pyscript6.8 KB
core/dimension_calculator.pyscript23.0 KB
core/distill_engine.pyscript18.8 KB
core/exp_tracker.pyscript15.0 KB
core/fact_store.pyscript9.5 KB
core/level_system.pyscript9.1 KB
core/memory_sync.pyscript6.1 KB
core/memory_watcher.pyscript14.9 KB
core/native_importer.pyscript31.0 KB
core/normalization_engine.pyscript11.7 KB
core/palace_classifier.pyscript12.2 KB
core/palace_index.pyscript10.7 KB
core/profile_card.pyscript9.6 KB
core/pyramid_engine.pyscript10.3 KB
core/session_scanner.pyscript12.7 KB
core/team_scanner.pyscript9.7 KB
docs/ARCHITECTURE_PRINCIPLES.mdmarkdown2.8 KB
docs/EXAMPLES.mdmarkdown2.1 KB
docs/USAGE.mdmarkdown2.8 KB
docs/session-jsonl-schema.mdmarkdown1.8 KB
health/__init__.pyscript16.9 KB
post-install.shscript2.2 KB
scripts/refresh-quests.shscript511 B
scripts/show-progress.shscript450 B
scripts/sync-memory.shscript1.4 KB
tests/__init__.pyscript627 B
tests/test_daily_quest.pyscript9.0 KB
tests/test_exp_tracker.pyscript8.6 KB
tests/test_integration_v6.pyscript8.9 KB
tests/test_normalization.pyscript8.2 KB

core/decay_function.py

View on GitHub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2026 Anima-AIOS Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Anima AIOS v6.0 - Decay Function

基于 Ebbinghaus 遗忘曲线的记忆衰减计算器。
影响检索排序、复习推荐、归档清理。

复习 = 访问:每次 memory_search 命中,strength 重算。

Author: 清禾
Date: 2026-03-24
Version: 6.0.0
"""

import math
import json
import logging
from pathlib import Path
from datetime import datetime, timedelta
from typing import Dict, List, Optional, Tuple

logger = logging.getLogger(__name__)


def memory_strength(days_since_access: float, initial_strength: float = 1.0,
                    stability: float = 1.0, review_count: int = 0) -> float:
    """
    计算记忆强度

    Args:
        days_since_access: 距上次访问的天数
        initial_strength: 初始强度(S=1.0, A=0.8, B=0.6, C=0.4)
        stability: 稳定性因子(每次复习 +0.3,上限 3.0)
        review_count: 复习次数

    Returns:
        0.0 ~ 1.0 的记忆强度值
    """
    s_adj = min(3.0, stability + review_count * 0.3)
    strength = initial_strength * math.exp(-days_since_access / (s_adj * 7))
    return max(0.0, min(1.0, strength))


QUALITY_TO_STRENGTH = {"S": 1.0, "A": 0.8, "B": 0.6, "C": 0.4, "pending": 0.5}


class DecayManager:
    """
    记忆衰减管理器

    职责:
    - 计算每条记忆的当前强度
    - 生成复习推荐列表
    - 标记可归档的记忆
    - 维护强度缓存
    """

    # 强度区间行为
    THRESHOLDS = {
        "healthy": 0.7,       # ≥ 0.7 正常
        "weakening": 0.5,     # 0.5~0.7 优先级降低
        "review": 0.3,        # 0.3~0.5 复习推荐
        "forgetting": 0.1,    # 0.1~0.3 即将遗忘提醒
        "archive": 0.1        # < 0.1 可归档
    }

    def __init__(self, agent_name: str, facts_base: str = None):
        self.agent_name = agent_name
        self.decay_dir = Path(facts_base) / agent_name / "decay"
        self.cache_file = self.decay_dir / "strength_cache.json"
        self.decay_dir.mkdir(parents=True, exist_ok=True)
        self.cache = self._load_cache()

    def _load_cache(self) -> Dict:
        if self.cache_file.exists():
            try:
                with open(self.cache_file, 'r', encoding='utf-8') as f:
                    return json.load(f)
            except Exception:
                pass
        return {"entries": {}, "updated": datetime.now().isoformat()}

    def _save_cache(self):
        self.cache["updated"] = datetime.now().isoformat()
        with open(self.cache_file, 'w', encoding='utf-8') as f:
            json.dump(self.cache, f, ensure_ascii=False, indent=2)

    def record_access(self, fact_id: str, quality: str = "B"):
        """记录一次访问(被动复习)"""
        entry = self.cache["entries"].get(fact_id, {
            "quality": quality,
            "review_count": 0,
            "first_seen": datetime.now().isoformat()
        })
        entry["last_accessed"] = datetime.now().isoformat()
        entry["review_count"] = entry.get("review_count", 0) + 1
        entry["quality"] = quality
        self.cache["entries"][fact_id] = entry
        self._save_cache()

    def get_strength(self, fact_id: str, quality: str = "B") -> float:
        """获取某条记忆的当前强度"""
        entry = self.cache["entries"].get(fact_id)
        if not entry:
            return QUALITY_TO_STRENGTH.get(quality, 0.5)

        last_accessed = entry.get("last_accessed", entry.get("first_seen", ""))
        if not last_accessed:
            return QUALITY_TO_STRENGTH.get(quality, 0.5)

        try:
            last_dt = datetime.fromisoformat(last_accessed)
            days = (datetime.now() - last_dt).total_seconds() / 86400
        except Exception:
            days = 7

        r = QUALITY_TO_STRENGTH.get(entry.get("quality", quality), 0.5)
        review_count = entry.get("review_count", 0)
        return memory_strength(days, r, 1.0, review_count)

    def get_status(self, fact_id: str, quality: str = "B") -> str:
        """获取记忆健康状态"""
        s = self.get_strength(fact_id, quality)
        if s >= self.THRESHOLDS["healthy"]:
            return "healthy"
        elif s >= self.THRESHOLDS["weakening"]:
            return "weakening"
        elif s >= self.THRESHOLDS["review"]:
            return "needs_review"
        elif s >= self.THRESHOLDS["archive"]:
            return "forgetting"
        else:
            return "archivable"

    def scan_all(self, facts: List[Dict]) -> Dict:
        """
        扫描所有记忆的衰减状态

        Args:
            facts: [{"fact_id": ..., "quality": ..., "content": ...}, ...]

        Returns:
            按状态分组的统计
        """
        result = {
            "healthy": [], "weakening": [], "needs_review": [],
            "forgetting": [], "archivable": [], "total": len(facts)
        }

        for fact in facts:
            fid = fact.get("fact_id", "")
            quality = fact.get("quality", "B")
            status = self.get_status(fid, quality)
            strength = self.get_strength(fid, quality)
            result[status].append({
                "fact_id": fid,
                "strength": round(strength, 3),
                "quality": quality
            })

        return result

    def get_review_recommendations(self, facts: List[Dict], limit: int = 5) -> List[Dict]:
        """
        生成复习推荐列表

        返回 strength 在 0.1~0.5 区间的高质量记忆。
        """
        candidates = []
        for fact in facts:
            fid = fact.get("fact_id", "")
            quality = fact.get("quality", "B")
            if quality in ("C", "pending"):
                continue
            strength = self.get_strength(fid, quality)
            if 0.1 <= strength <= 0.5:
                candidates.append({
                    "fact_id": fid,
                    "strength": round(strength, 3),
                    "quality": quality,
                    "content_preview": fact.get("content", "")[:80]
                })

        candidates.sort(key=lambda x: x["strength"])
        return candidates[:limit]

    def get_stats(self) -> Dict:
        entries = self.cache.get("entries", {})
        return {
            "agent": self.agent_name,
            "tracked_memories": len(entries),
            "cache_updated": self.cache.get("updated", ""),
        }
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall