Self Learning 标志

Self Learning

社区
gotar
self-learning

Self-learning capability for agents. Captures execution traces, extracts insights, and adapts agent behavior. Use after completing complex tasks, when agents encounter recurring issues, or to optimize workflows over time. Critical for multi-agent systems like orchestrator, worker, and reviewer.

概览

发布者gotar
代码仓库opencode-config
技能名称self-learning
星标数
26
复刻数
2
附带文件
2
链接
  • Markdown 格式的指令

    模型按需加载的 SKILL.md 文件,因此只有在请求确实匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个随附文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 gotar 发布于 GitHub。请在安装前查看源内容。

安装

在 TypingMind 中安装 Self Learning AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/gotar/opencode-config/tree/master/skills/self-learning
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/gotar/opencode-config.git /tmp/opencode-config
mkdir -p .claude/skills
cp -r /tmp/opencode-config/skills/self-learning .claude/skills/self-learning
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Self Learning,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Self Learning。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Self Learning 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会获取指令,因此未使用的技能不会产生额外费用。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Self Learning

Overview

Enables agents to learn from their execution history by capturing traces, extracting actionable insights, and adapting behavior. Transforms raw execution patterns into reusable knowledge structures that improve future performance.

When to Use This Skill

Trigger this skill when:

  • An agent completes a complex task and should capture learnings
  • Recurring patterns of failures or inefficiencies are detected
  • An agent discovers a better approach that should be retained
  • Multiple agents coordinate on a task and need shared learning
  • Performance metrics show degradation or opportunity for improvement

Automatic Invocation: Integrate into agents at critical points:

  • Orchestrator: After merging worker results, capture coordination patterns
  • Worker: After completing task (post-review), capture execution insights
  • Reviewer: After detecting recurring issues, capture quality patterns
  • Task Manager: After task completion, capture decomposition insights

Core Capabilities

1. Trace Collection

Captures structured execution traces containing:

markdown
# Execution Trace Structure
- Task Description
- Approach Used
- Tools Invoked (with tool calls)
- Context Loaded
- Results Achieved
- Failures/Errors Encountered
- Time Metrics (optional)
- Success/Failure Status

Collection Strategy:

  • Manual capture: Agents document their execution after completion
  • Automatic hooks: Trace capture integrated into agent workflows
  • Context: Store traces in .tmp/learning/traces/{timestamp}_{agent}_{task}.md

Example Trace:

markdown
# Trace: worker_implementation_20250108_1120
Agent: worker
Task: Implement user authentication feature
Status: Success

## Approach
1. Analyzed existing auth patterns in codebase
2. Implemented JWT token validation
3. Added tests for edge cases

## Tools Invoked
- Read: agent/openagent.md, code/auth.ts
- Write: code/auth.ts, tests/auth.test.ts
- lsp_diagnostics: code/auth.ts

## Results
- Auth implemented successfully
- All tests passing
- Zero diagnostics errors

## Failures Encountered
- Initial JWT secret configuration missing
- Fixed by reading config patterns from code/config.ts

2. Insight Extraction

Transforms traces into structured insights using pattern recognition:

Insight Categories:

CategoryDescriptionExample
Success PatternsApproaches that consistently work"Loading context.md before task start reduces errors by 40%"
Failure PatternsRecurring causes of failures" Skipping lsp_diagnostics leads to type errors in production"
Efficiency PatternsWays to complete tasks faster"Reading multiple files in parallel reduces context load time"
Coordination PatternsBest practices for multi-agent work"Orchestrator spawning 2 workers instead of 3 reduces merge conflicts"
Knowledge GapsInformation that should have been available"Project lacks centralized error handling documentation"

Extraction Process:

  1. Analyze traces for recurring patterns
  2. Identify successful vs unsuccessful approaches
  3. Extract high-impact insights (prioritize by frequency and impact)
  4. Structure insights as actionable recommendations
  5. Store in .tmp/learning/insights/{category}.md

Example Insights:

markdown
# Insights: Success Patterns

## Context Loading
**Finding**: Loading context.md before task start significantly reduces errors
**Evidence**: 10/10 successful tasks loaded context.md first
**Action**: Mandate context loading in all agent workflows
**Impact**: High (prevents 60% of failures)

## Parallel Execution
**Finding**: Spawning 2 workers in parallel reduces total time by 35%
**Evidence**: Compared to 3 workers (merge conflicts) and 1 worker (sequential)
**Action**: Default to 2 workers in orchestrator for most tasks
**Impact**: Medium (performance optimization)

# Insights: Failure Patterns

## Skipping Validation
**Finding**: 8/10 failures skipped lsp_diagnostics before completion
**Evidence**: Type errors detected post-merge
**Action**: Require lsp_diagnostics before task completion
**Impact**: High (prevents integration failures)

3. Adaptation

Applies insights to improve agent behavior:

Adaptation Levels:

  1. Immediate (Session-Local): Apply insights within current session

    • Example: "Switching to 2 workers based on merge conflict pattern"
    • Storage: .tmp/learning/adaptations/session_{id}.md
  2. Persistent (Agent-Specific): Update agent instructions for future sessions

    • Example: "Added mandatory lsp_diagnostics check to worker.md"
    • Storage: Update agent .md files directly
  3. System-Wide (All Agents): Modify agent orchestration patterns

    • Example: "Updated orchestrator.md to default to 2 workers"
    • Storage: Update core agent files

Adaptation Rules:

  • Start with session-local adaptations (low risk)
  • Promote to persistent only after 3+ confirming instances
  • Require manual approval for system-wide changes
  • Always preserve original behavior in comments

Example Adaptation:

markdown
# Adaptation: Worker Validation Rule
Applied: Session
Date: 2025-01-08
Insight: "Skipping lsp_diagnostics leads to type errors in production"
Based on: 8/10 failures analyzed

Change:
- Added mandatory lsp_diagnostics check before swarm_worker_complete
- Updated worker.md to require validation in workflow

Result:
- Zero type errors in subsequent 5 tasks
- Minimal overhead (2-3 sec per task)

4. Knowledge Base

Builds a persistent knowledge base from insights:

Structure:

learning/
├── traces/           # Raw execution traces
├── insights/         # Extracted insights by category
├── adaptations/      # Applied adaptations by level
├── knowledge-base.md # Consolidated actionable knowledge
└── metrics/          # Performance metrics over time

Knowledge Base Format:

markdown
# Self-Improving Agent Knowledge Base

Last Updated: 2025-01-08

## Agent Behavior Guidelines

### Context Management
- ALWAYS load context.md before starting tasks
- Read multiple files in parallel when possible
- Prune context aggressively (>50% reduction ideal)

### Validation
- Run lsp_diagnostics before completing any task
- Request review on all complex changes (>3 files)
- Verify with build/test commands when available

### Coordination
- Default to 2 parallel workers (3 causes merge conflicts)
- Wait for worker confirmation before spawning new workers
- Merge results sequentially, not all at once

### Common Pitfalls
Don't:
- Skip type checks to "save time"
- Assume patterns work without validation
- Batch-complete todos (mark individually)

Do:
- Extract key findings before pruning context
- Verify work after delegation
- Learn from failures, not just successes

Workflow Decision Tree

Start Learning Process
├─ Is this task complete?
│  ├─ Yes → Capture trace
│  │      ├─ Manual documentation
│  │      └─ Automatic hooks (if integrated)
│  │
│  └─ No → Continue task
│
├─ Should we extract insights?
│  ├─ Yes (5+ traces available or pattern detected)
│  │      └─ Analyze traces
│  │             ├─ Identify patterns
│  │             ├─ Extract insights
│  │             └─ Prioritize by impact
│  │
│  └─ No (insufficient data) → Continue
│
└─ Should we adapt behavior?
   ├─ Yes (high-confidence insight available)
   │      └─ Determine adaptation level
   │             ├─ Session-local → Apply immediately
   │             ├─ Agent-specific → Update agent file
   │             └─ System-wide → Document and seek approval
   │
   └─ No (low confidence or risky) → Document and wait

Integration Examples

Integrating into Orchestrator

Add to orchestrator.md:

markdown
## Post-Merge Learning

After merging worker results, capture coordination patterns:

1. Document:
   - Number of workers spawned
   - Merge conflicts encountered
   - Total execution time
   - Worker success/failure rates

2. If pattern detected (e.g., recurring conflicts):
   - Extract insight
   - Apply session-local adaptation
   - Example: "Reducing to 2 workers next phase"

3. After swarm completion:
   - Consolidate all traces
   - Extract insights for future swarms
   - Update orchestrator.md if pattern persists (>3 instances)

Integrating into Worker

Add to worker.md:

markdown
## Pre-Completion Learning

Before calling swarm_worker_complete:

1. REQUIRED: Run lsp_diagnostics
2. Capture execution trace:
   - Approach used
   - Tools invoked
   - Failures encountered
   - Success criteria met
3. Store trace: `.tmp/learning/traces/worker_{timestamp}.md`

## Post-Review Learning

After reviewer approval:

1. If reviewer identified issues:
   - Document failure pattern
   - Extract insight (e.g., "Always validate with reviewer before complex refactors")
   - Update worker.md if pattern recurs

Integrating into Reviewer

Add to reviewer.md:

markdown
## Pattern Detection

During review, watch for recurring issues:

1. Track issues by category:
   - Type safety violations
   - Missing validation
   - Inconsistent patterns
   - Performance issues

2. If same issue appears 3+ times:
   - Extract insight
   - Suggest agent adaptation
   - Update knowledge-base.md

3. Provide pattern-aware feedback:
   "Note: This is the 4th occurrence of X. Recommend adding Y to worker.md"

Scripts

The following scripts support automated learning:

analyze_traces.py

python
"""
Analyze collected traces to extract patterns and insights.

Usage: python scripts/analyze_traces.py --traces .tmp/learning/traces/

Output: .tmp/learning/insights/
"""

import argparse
import json
from pathlib import Path
from collections import Counter
import re

def load_trace(trace_path):
    """Load and parse a trace file."""
    with open(trace_path) as f:
        content = f.read()
    # Extract structured data from trace
    return {
        'agent': extract_field(content, 'Agent'),
        'status': extract_field(content, 'Status'),
        'tools': extract_tools(content),
        'failures': extract_failures(content),
    }

def extract_field(content, field):
    """Extract a field from trace content."""
    pattern = f"{field}:\\s*(.+?)(?:\\n|$)"
    match = re.search(pattern, content)
    return match.group(1).strip() if match else None

def extract_tools(content):
    """Extract tools used from trace."""
    tools = re.findall(r'- ([\w_]+):', content)
    return Counter(tools)

def extract_failures(content):
    """Extract failure patterns from trace."""
    failures = re.findall(r'(?:Error|Failure):\\s*(.+)', content)
    return failures

def identify_patterns(traces):
    """Identify patterns across traces."""
    # Success patterns
    success_traces = [t for t in traces if t['status'] == 'Success']
    success_tools = Counter()
    for t in success_traces:
        success_tools.update(t['tools'])

    # Failure patterns
    failure_traces = [t for t in traces if t['status'] == 'Failure']
    failure_patterns = Counter()
    for t in failure_traces:
        failure_patterns.update(t['failures'])

    return {
        'success_tools': success_tools,
        'failure_patterns': failure_patterns,
        'success_rate': len(success_traces) / len(traces) if traces else 0,
    }

def generate_insights(patterns):
    """Generate actionable insights from patterns."""
    insights = []

    # Success pattern: Tools consistently used in successful traces
    for tool, count in patterns['success_tools'].most_common(5):
        insight = {
            'category': 'Success Patterns',
            'finding': f"Tool '{tool}' appears in {count} successful traces",
            'action': f"Consider making '{tool}' mandatory for relevant tasks",
            'impact': 'High' if count > 5 else 'Medium',
        }
        insights.append(insight)

    # Failure pattern: Recurring issues
    for pattern, count in patterns['failure_patterns'].most_common(5):
        insight = {
            'category': 'Failure Patterns',
            'finding': f"Failure pattern '{pattern}' occurs {count} times",
            'action': f"Add validation to prevent: {pattern}",
            'impact': 'High' if count > 3 else 'Medium',
        }
        insights.append(insight)

    return insights

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--traces', required=True, help='Path to traces directory')
    parser.add_argument('--output', default='.tmp/learning/insights', help='Output directory')
    args = parser.parse_args()

    # Load all traces
    trace_dir = Path(args.traces)
    traces = [load_trace(f) for f in trace_dir.glob('*.md')]

    # Identify patterns
    patterns = identify_patterns(traces)

    # Generate insights
    insights = generate_insights(patterns)

    # Save insights
    output_dir = Path(args.output)
    output_dir.mkdir(parents=True, exist_ok=True)

    for insight in insights:
        category = insight['category'].replace(' ', '_').lower()
        output_file = output_dir / f"{category}.md"

        with open(output_file, 'a') as f:
            f.write(f"## Insight: {insight['finding']}\n")
            f.write(f"**Category**: {insight['category']}\n")
            f.write(f"**Action**: {insight['action']}\n")
            f.write(f"**Impact**: {insight['impact']}\n\n")

    print(f"Generated {len(insights)} insights in {output_dir}")

if __name__ == '__main__':
    main()

apply_adaptation.py

python
"""
Apply an adaptation to agent behavior.

Usage: python scripts/apply_adaptation.py --agent worker --adaptation "Always run lsp_diagnostics"

Supports levels: session, agent, system
"""

import argparse
from pathlib import Path
from datetime import datetime

def apply_session_adaptation(agent, adaptation):
    """Apply session-local adaptation."""
    session_id = datetime.now().strftime("%Y%m%d_%H%M%S")
    adaptation_file = Path(f".tmp/learning/adaptations/session_{session_id}.md")

    with open(adaptation_file, 'w') as f:
        f.write(f"# Session Adaptation: {agent}\n")
        f.write(f"Applied: {datetime.now()}\n\n")
        f.write(f"**Adaptation**: {adaptation}\n")
        f.write(f"**Level**: Session-local\n")
        f.write(f"**Impact**: Applied to current session only\n")

    print(f"Session adaptation saved to {adaptation_file}")

def apply_agent_adaptation(agent, adaptation, agent_file):
    """Apply agent-specific adaptation."""
    agent_path = Path(agent_file)

    with open(agent_path, 'r') as f:
        content = f.read()

    # Find "## Workflow" or similar section
    if "## Workflow" in content:
        insertion_point = content.find("## Workflow")
        adapted_content = (
            content[:insertion_point] +
            f"## Learning Rule (Self-Improving)\n{adaptation}\n\n" +
            content[insertion_point:]
        )
    else:
        adapted_content = content + f"\n\n## Learning Rule (Self-Improving)\n{adaptation}\n"

    with open(agent_path, 'w') as f:
        f.write(adapted_content)

    print(f"Agent adaptation applied to {agent_path}")

def apply_system_adaptation(adaptation):
    """Apply system-wide adaptation (requires approval)."""
    print(f"SYSTEM-WIDE ADAPTATION REQUESTED:")
    print(f"  Adaptation: {adaptation}")
    print(f"\nThis requires manual approval.")
    print("Document in .tmp/learning/adaptations/system_pending.md")
    print("Then update relevant agent files after review.")

    pending_file = Path(".tmp/learning/adaptations/system_pending.md")
    pending_file.parent.mkdir(parents=True, exist_ok=True)

    with open(pending_file, 'a') as f:
        f.write(f"# System-Wide Adaptation (Pending Approval)\n")
        f.write(f"Requested: {datetime.now()}\n")
        f.write(f"**Adaptation**: {adaptation}\n")
        f.write(f"**Status**: Pending manual review\n\n")

    print(f"Adaptation documented in {pending_file}")

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--agent', required=True, help='Agent name (e.g., worker, orchestrator)')
    parser.add_argument('--adaptation', required=True, help='Adaptation description')
    parser.add_argument('--level', default='session', choices=['session', 'agent', 'system'], help='Adaptation level')
    parser.add_argument('--agent-file', help='Path to agent .md file (required for agent level)')
    args = parser.parse_args()

    if args.level == 'session':
        apply_session_adaptation(args.agent, args.adaptation)
    elif args.level == 'agent':
        if not args.agent_file:
            raise ValueError("--agent-file required for agent-level adaptations")
        apply_agent_adaptation(args.agent, args.adaptation, args.agent_file)
    elif args.level == 'system':
        apply_system_adaptation(args.adaptation)

if __name__ == '__main__':
    main()

Safety Guidelines

Critical Constraints:

  1. Never adapt without evidence

    • Require minimum 3-5 traces before extracting patterns
    • Validate insights across multiple sessions
    • Seek confirmation before major changes
  2. Start local, scale slowly

    • Always apply session-local adaptations first
    • Promote to agent-specific only after validation
    • System-wide changes require manual approval
  3. Preserve original behavior

    • Document what changed and why
    • Keep comments showing original patterns
    • Enable rollback if adaptation causes issues
  4. Don't override user intent

    • Learning should optimize, not override
    • Adaptations must respect explicit instructions
    • Conflicts: user instructions > learned patterns
  5. Monitor for negative feedback

    • Track adaptation effectiveness
    • Revert if success rate decreases
    • Learn from adaptation failures too

Usage Example

Scenario: Orchestrator agent completes a complex swarm task with merge conflicts

Execution:

  1. Capture trace:
markdown
# Trace: orchestrator_swarm_20250108_1120
Agent: orchestrator
Task: Multi-feature implementation
Workers: 3
Merge Conflicts: 5 (high)
Total Time: 45min
Status: Success (with issues)
  1. Extract insight:
markdown
## Insight: Worker Count Optimization
**Finding**: 3 workers cause 5 merge conflicts
**Evidence**: Compared to previous 2-worker tasks (0-1 conflicts)
**Action**: Reduce to 2 workers for similar tasks
**Impact**: High (prevents merge conflicts, faster completion)
  1. Apply adaptation (session-local):
bash
python scripts/apply_adaptation.py \
  --agent orchestrator \
  --adaptation "Default to 2 workers instead of 3 for tasks with <5 subtasks" \
  --level session
  1. Result:

    • Next swarm phase uses 2 workers
    • Merge conflicts reduced to 1
    • Total time reduced to 32min
    • Pattern validated
  2. Promote to persistent (after 3+ successful validations):

bash
python scripts/apply_adaptation.py \
  --agent orchestrator \
  --adaptation "Default to 2 workers instead of 3 for tasks with <5 subtasks" \
  --level agent \
  --agent-file /path/to/orchestrator.md

Outcome: Orchestrator permanently optimized based on learned experience.

Metrics Tracking

Track learning effectiveness over time:

markdown
# Learning Metrics

## Adaptation Success Rate
- Total adaptations applied: 15
- Successful improvements: 12 (80%)
- Neutral/no effect: 2 (13%)
- Negative (reverted): 1 (7%)

## Agent Performance (Before/After)
- Orchestrator: 45min → 32min (29% improvement)
- Worker: 3.2 failures/10 tasks → 1.1 failures/10 tasks (66% reduction)
- Reviewer: 2.1 issues/review → 1.4 issues/review (33% reduction)

## Knowledge Base Growth
- Traces collected: 127
- Insights extracted: 34
- Patterns validated: 12

Key Principle: This skill transforms execution history into actionable knowledge, enabling agents to systematically improve without human intervention. Start small, validate thoroughly, scale cautiously.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Self Learning AI 技能有什么作用?

Self-learning capability for agents. Captures execution traces, extracts insights, and adapts agent behavior. Use after completing complex tasks, when agents encounter recurring issues, or to optimize workflows over time. Critical for multi-agent systems like orchestrator, worker, and reviewer.

为什么在 TypingMind 中使用 Self Learning?

因为您只需安装一次,就能搭配任何模型使用。Self Learning 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型,甚至可以在聊天中途切换模型,而不会影响技能正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Self Learning?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/gotar/opencode-config/tree/master/skills/self-learning。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Self Learning?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Self Learning 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以搭配 Self Learning 使用,包括 GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等,都可在 TypingMind 中使用您自己的 API 密钥接入。

Self Learning AI 技能免费吗?

该技能源自 gotar 在 GitHub 上发布的项目。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇