Self Learning logo

Self Learning

Community
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.

Overview

Publishergotar
Repositoryopencode-config
Skill nameself-learning
Stars
26
Forks
2
Bundled files
2
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by gotar on GitHub. Read the source before you install it.

Installation

Install the Self Learning AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/gotar/opencode-config/tree/master/skills/self-learning
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

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
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Self Learning in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Self Learning on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Self Learning is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Self Learning AI skill do?

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.

Why use Self Learning on TypingMind?

Because you install it once and use it with any model. Self Learning is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Self Learning in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/gotar/opencode-config/tree/master/skills/self-learning. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Self Learning?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Self Learning?

As many as you like. As long as a model supports skills, you can use Self Learning with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Self Learning AI skill free?

It is published on GitHub by gotar. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇